when i try to run my test in appium, my second test is not running. Its shows "A new session could not be created". My second test function name is BAddon, while second test execution the error thrown
Here is my code
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class FirstAutomate {
private WebDriver driver;
@Before
public void setup() throws Exception {
//File app = new File("C:\\sdk\\platform-tools\\Myapp.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
//capabilities.setCapability("BROWSER_NAME", "Android");
capabilities.setCapability("VERSION", "5.0.2");
capabilities.setCapability("deviceName","G3 Beat");
capabilities.setCapability("appPackage", "com.myapp.app");
capabilities.setCapability("appActivity","com.myapp.app.screens.prehomescreens.activities.SplashScreen");
capabilities.setCapability("platformName","Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,MobilePlatform.ANDROID);
//capabilities.setCapability("app", app.getAbsolutePath());
try{
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}catch(MalformedURLException e)
{
e.printStackTrace();
}
// TODO Auto-generated method stub
}
@Test
public void AppLogin() throws InterruptedException {
//Tapping login button
Thread.sleep(5000);
driver.findElement(By.id("loginButtonTextView")).click();
//User inputs mail id
driver.findElement(By.id("emailIdEditText")).sendKeys("[email protected]");
//User login button click
driver.findElement(By.id("loginBtnRCB")).click();
//User inputs OTP
driver.findElement(By.id("pinPadContainer")).sendKeys("123456");
WebElement loginBtn = driver.findElement(By.id("nextBtnRCB"));
if(loginBtn.isDisplayed())
{
loginBtn.click();
}else
{
System.out.println("Button is not present");
}
Thread.sleep(15000);
}
@Test
public void BAddOn() throws InterruptedException{
//Thread.sleep(10000);
WebElement AddonBtn = driver.findElement(By.id("studentStatusButton"));
if(AddonBtn.isDisplayed())
{
AddonBtn.click();
}else{
System.out.println("AddOnBtn is not visible");
}
}
}
I guess setup is called before every test case. Once the server is running you don't need setup to be called again.
You need to figure out a way so that appium server setup is only called once before the execution of ur test cases begin. I think there is @BeforeClass
annotation to do that.