buttons

 

Appium Concepts: How to Fetch/Use ‘SessionID’ with ‘Appium Inspector’

Please go through the below video for complete details:

Usage: Will return Current SessionId, generated by appium server

SessionId sessionid_value=driver.getSessionId();

return type — SessionId

package demo;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;

import org.openqa.selenium.remote.SessionId;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;


/**
* Script Details - Appium Concepts : How to Fetch/Use 'SessionID' with 'Appium Inspector'-Mobile Automation-Appium2
*
* appium-java-client version: 9.3.0
*
* @author 'Ramesh Kodumuru' for AppiumGuide [appiumguide@gmail.com]
*/


public class SessionIdTest {

private AndroidDriver driver;

String AUTappPackage="com.wdiodemoapp";
String AUTappActivity="com.wdiodemoapp.MainActivity";

@BeforeTest
public void steup() throws MalformedURLException {
UiAutomator2Options cap =new UiAutomator2Options();
cap.setPlatformName("android");
cap.setAutomationName("uiautomator2");
cap.setDeviceName("device14");
cap.setAppPackage(AUTappPackage);
cap.setAppActivity(AUTappActivity);
cap.setNoReset(true);
cap.setNewCommandTimeout(Duration.ofSeconds(90));



driver=new AndroidDriver(new URL("http://127.0.0.1:4723"), cap);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

}
@AfterTest
public void teardown() {
if(driver!=null) {
driver.quit();
System.out.println("Test Execution Completed");

}
}

@Test
public void sessionidsample() throws InterruptedException {
Thread.sleep(5000);
SessionId sessionid_value=driver.getSessionId();
System.out.println(sessionid_value);
Thread.sleep(5000);



}

}

Output:

Observe that generated SessionId —da4c059a-2d37–4d1a-be1b-d669a83af68b

  1. Open the Appium Inspector.
  2. Navigate to the ‘Attach to session..’ tab
  3. Click on the dropdown
  4. Observe that the generated SessionId is displayed under the dropdown.
  5. Select the ‘SessionId’

6. Click on the “Attach to Session” button.

Observe that Session is created based on the selected ‘SessionId’

GitHub Link:


No comments:

Post a Comment