How to preserve Appium session between multiple testng class

0
0

I am automating Android application using Appium, I have One Base Class with Setup and Tear down (In setup initialization appium session and in teardown destroying session ).

This Base Class I inherited in all testng classes, now for each test class Appium new session generated.

So My question is that How we maintain appium session through out the all class once it generate for any class.

Thanks
Sadik

  • You must to post comments
0
0

I have implemented this approach using Singlton design pattern here is approach:

public class SingltonFactory{
private static SingltonFactory instance = new SingltonFactory();
private static AppiumDriver<MobileElement> driver;
private SingltonFactory() {
}
// Get the only object available
public static SingltonFactory getInstance() {
return instance;
}
// Get the only object available
public void setDriver(AppiumDriver<MobileElement> driver1) {
driver
= driver1;
}
public AppiumDriver<MobileElement> getAppiumDriver() {
return driver;
}

}

Add initialize SingltonFactory in your before test cases and assign driver object like below:

AppiumFactory appiumFactory = AppiumFactory.getInstance();
if(appiumFactory.getAppiumDriver() == null) {
driver
= new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
}
else{
driver
= appiumFactory.getAppiumDriver();
}
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website