Site icon Tutorial

Session Commands

Go back to tutorial

Session Commands

In this section we will be giving an overview about the various session command including creating new session commands, end session commands, and many other capability related commands.

How to create a new session?

We have illustrated an example showcasing the process to create a new session command – Using Java

DesiredCapabilities desiredCapabilities = new DesiredCapabilities();

desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “10.3”);

desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “iPhone Simulator”);

desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, “XCUITest”);

desiredCapabilities.setCapability(MobileCapabilityType.APP, “/path/to/ios/app.zip”);

 

URL url = new URL(“http://127.0.0.1:4723/wd/hub”);

 

IOSDriver driver = new IOSDriver(url, desiredCapabilities);

String sessionId = driver.getSessionId().toString();

 

Further, the server must attempt to create a session that most closely matches the desired and required capabilities.

How to end a session?

We will now illustrate how to end a running session – Using in Java

driver.quit();

Where, HTTP API Specifications

Endpoint –

DELETE /session/:session_id

URL Parameters –

name description
session_id ID of the session to delete

JSON Parameters – None

Response – null

How to get Session Capabilities?

We will illustrate the process to retrieve the capabilities of the specified session – Using Java

Map<String, Object> caps = driver.getSessionDetails();

HTTP API Specifications

Endpoint – GET /session/:session_id

URL Parameters –

name description
session_id ID of the session to route the command to

JSON Parameters – None

Response – An object describing the session’s capabilities (object)

What is session command to navigate?

We will illustrate the process to navigate backwards in the browser history, if possible (Web context only) – Using Java

driver.back();

HTTP API Specifications

Endpoint – POST /wd/hub/session/:session_id/back

URL Parameters –

name description
session_id ID of the session to route the command to

JSON Parameters – None

Response – null

What are the orientation commands?

Example Usage in Java

ScreenOrientation orientation = driver.getOrientation();

Example Usage in Java

driver.rotate(ScreenOrientation.LANDSCAPE);

 

Learn more about device setting and updates!

Boost your chances for better job opportunities. Practice and Prepare for Mobile Testing (Appium) Exam Now!

Go back to tutorial

Exit mobile version