Getting “org.openqa.selenium.WebDriverException: Session [null] not available and is not among the last 1000 terminated sessions.” when I run Mobile Tests for Android and iOS on Selenium Hub with two nodes
org.openqa.selenium.WebDriverException:
Session [null] not available and is not among the last 1000 terminated sessions.
Active sessions are[ext. key 515a8c57-05e6-4f36-8f86-e43e6c54bf84]
Command duration or timeout: 25 milliseconds
Build info: version: ‘2.53.0’, revision: ‘35ae25b1534ae328c771e0856c93e187490ca824’, time: ‘2016-03-15 10:43:46’
System info: host: ‘MacBook-Pro.local’, ip: ‘10.255.132.41’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.14.5’, java.version: ‘1.8.0_202’
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{capabilities={appPackage=com.edfenergy.rapmobile.dev, server:CONFIG_UUID=30fc4cda-1e96-45e4-a671-ba3a6b8787f0, statBarHeight=66, noReset=false, viewportRect={top=66, left=0, width=1080, height=1962}, deviceName=emulator-5554, fullReset=true, platform=LINUX, deviceUDID=emulator-5554, desired={app=/Users/financefree/Desktop/Contino/development/edf/edf-rap-tools-mobile-automation/resources/app/android/app-dev-debug.apk, appActivity=com.edfenergy.rapmobile.MainActivity, appPackage=com.edfenergy.rapmobile.dev, server:CONFIG_UUID=30fc4cda-1e96-45e4-a671-ba3a6b8787f0, noReset=false, platformVersion=9, automationName=UiAutomator2, autoDismissAlerts=true, platformName=android, udid=emulator-5554, deviceName=Pixel_3_API_28_Android_9.0, fullReset=true}, platformVersion=9, webStorageEnabled=false, automationName=UiAutomator2, takesScreenshot=true, javascriptEnabled=true, platformName=android, udid=emulator-5554, deviceApiLevel=28, deviceManufacturer=Google, app=/Users/financefree/Desktop/Contino/development/edf/edf-rap-tools-mobile-automation/resources/app/android/app-dev-debug.apk, deviceScreenSize=1080x2160, networkConnectionEnabled=true, warnings={}, autoDismissAlerts=true, databaseEnabled=false, appActivity=com.edfenergy.rapmobile.MainActivity, pixelRatio=2.75, locationContextEnabled=false, deviceScreenDensity=440, deviceModel=Android SDK built for x86}, sessionId=515a8c57-05e6-4f36-8f86-e43e6c54bf84, platform=ANY}]
Session ID: null
at com.rap.mobiletests.InitialTest.loginBasicTest(InitialTest.java:18)
Caused by: org.openqa.selenium.WebDriverException:
Session [null] not available and is not among the last 1000 terminated sessions.
Active sessions are[ext. key 515a8c57-05e6-4f36-8f86-e43e6c54bf84]
Build info: version: ‘2.53.0’, revision: ‘35ae25b1534ae328c771e0856c93e187490ca824’, time: ‘2016-03-15 10:43:46’
System info: host: ‘Deyans-MacBook-Pro.local’, ip: ‘10.255.132.41’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.14.5’, java.version: ‘1.8.0_202’
Driver info: driver.version: unknown
I manage to start the Selenium Server, have two nodes added to it with .json files and when I run the login test against iOS and Android sequentially I can see the app being installed and started, but when it comes to starting the Webdriver to interact with the elements I get the above error. All works when I run them locally sequentially
This is my AppiumController
public class AppiumController {
public static AppiumController instance = new AppiumController();
public static AppiumDriver driver;
public void start(String platformName, String platformVersion, String deviceName) throws MalformedURLException {
if (driver != null) {
System.out.println("Driver is already started and no new capabilities are loaded");
return;
}
DesiredCapabilities capabilities = new DesiredCapabilities();
switch (platformName.toLowerCase()) {
case "android":
File androidApp = new File("resources/app/android/app-dev-debug.apk");
String absoluteAndroidAppPath = androidApp.getAbsolutePath();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, platformName);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, platformVersion);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
capabilities.setCapability(MobileCapabilityType.APP, absoluteAndroidAppPath);
capabilities.setCapability("appPackage", "com.edfenergy.rapmobile.dev");
capabilities.setCapability("appActivity", "com.edfenergy.rapmobile.MainActivity");
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
capabilities.setCapability("autoDismissAlerts", true);
capabilities.setCapability("fullReset", true);
capabilities.setCapability("noReset", false);
// driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
driver = new AndroidDriver(new URL(“http://127.0.0.1:4444/wd/hub”), capabilities);
break;
case “ios”:
File iOSApp = new File(“resources/app/ios/Glow QA-debug.app”);
String absoluteIOSAppPath = iOSApp.getAbsolutePath();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, platformName);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, platformVersion);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);
capabilities.setCapability(MobileCapabilityType.APP, absoluteIOSAppPath);
capabilities.setCapability("bundleId", "com.edfenergy.rapmobile.dev");
capabilities.setCapability("udid", "E52560B2-59DD-4167-80FB-055CA21C7215");
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
capabilities.setCapability("useNewWDA", true);
capabilities.setCapability("waitForQuiescence", false);
capabilities.setCapability("autoDismissAlerts", true);
capabilities.setCapability("fullReset", true);
capabilities.setCapability("noReset", false);
// driver = new IOSDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
driver = new IOSDriver(new URL(“http://127.0.0.1:4444/wd/hub”), capabilities);
break;
default:
throw new IllegalArgumentException(“The platform name " + platformName + " was not found”);
}
}
public void stop() {
if (driver != null) {
driver.quit();
driver = null;
System.out.println("Stopping Driver");
}
}
}
Base Page
public class BasePage {
protected final AppiumDriver driver;
public BasePage(AppiumDriver driver) {
this.driver = driver;
PageFactory.initElements(new AppiumFieldDecorator(driver, 30, TimeUnit.SECONDS), this);
}
public void hideKeyboard() {
if (isAndroid()) {
driver.hideKeyboard();
} else {
IOSDriver iosDriver = (IOSDriver) driver;
iosDriver.hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done");
}
}
public boolean isAndroid() {
return driver instanceof AndroidDriver;
}
public boolean isIOS() {
return driver instanceof IOSDriver;
}
public void swipeToBottom()
{
new TouchAction(driver).press(115, 650)
.waitAction(1000)
.moveTo(115, 350)
.release()
.perform();
}
}
Login Screen
package com.rap.pageobjects;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import io.appium.java_client.pagefactory.iOSFindBy;
import io.qameta.allure.Step;
import org.openqa.selenium.support.PageFactory;
import java.util.concurrent.TimeUnit;
public class LoginScreenPage extends BasePage{
public LoginScreenPage(AppiumDriver driver) {
super(driver);
onPage();
}
@AndroidFindBy(className = "android.widget.EditText")
@iOSFindBy(xpath = "//XCUIElementTypeOther[@name='Email address']/XCUIElementTypeOther/XCUIElementTypeTextField")
private MobileElement emailField;
@AndroidFindBy(xpath = "//android.widget.TextView[@text='Sign in Button']")
@iOSFindBy(xpath = "//XCUIElementTypeOther[@name='Sign in Button\']")
private MobileElement signInButton;
@AndroidFindBy(xpath = "//android.widget.TextView[@text='Welcome to Glow, sign in to continue']")
@iOSFindBy(xpath = "//XCUIElementTypeStaticText[@name='Welcome to Glow, sign in to continue']")
private MobileElement welcomeText;
private void enterEmail(String email){
System.out.println("Entering email with value: " + email);
emailField.clear();
System.out.println("Cleared the email field");
emailField.sendKeys(email);
System.out.println("Entered the email");
}
private void clickSignInButton(){
signInButton.click();
System.out.println("Clicked on Sign In Button");
}
@Step("Login step for user with email {0}")
public void logInAs(String email){
enterEmail(email);
clickSignInButton();
}
private void onPage(){
welcomeText.isDisplayed();
}
}
BaseTest
public class BaseTest extends AppiumBaseClass {
public AppiumDriver driver;
@Getter
@Setter
private String platformName;
@Getter
@Setter
private String platformVersion;
@Getter
@Setter
private String deviceName;
@Parameters({"platformName", "platformVersion", "deviceName"})
@BeforeMethod(description = "Starting appium driver and passing all desired capabilities")
public void setUp(@Optional("Android") String _platformName, @Optional("9") String _platformVersion, @Optional("Pixel_3_API_28_Android_9.0") String _deviceName, ITestContext context) throws Exception {
System.out.println("Starting test: " + context.getName());
AppiumController.instance.start(_platformName, _platformVersion, _deviceName);
this.driver = driver();
setPlatformName(_platformName);
setPlatformVersion(_platformVersion);
setDeviceName(_deviceName);
}
@AfterMethod(description = "Stopping appium driver")
public void tearDown(ITestResult testResult) {
try{
AppiumController.instance.stop();
}
catch (Exception ex){
System.out.println("This is the exception: " + ex.toString());
}
System.out.println("Did the test pass: " + testResult.isSuccess());
testResult.getName();
testResult.getEndMillis();
System.out.format("The time for test %s is: %s", testResult.getName(), testResult.getEndMillis());
}
}
And the test itself
public class InitialTest extends BaseTest {
@Description("Testing the login functionality")
@Feature("Login")
@Story("Valid Login")
@Test(description = "Login First Test")
public void loginBasicTest() throws InterruptedException {
LoginScreenPage loginScreenPage = new LoginScreenPage(driver);
loginScreenPage.logInAs(User.USER_JUST_ONBOARDED.email);
// CoolingOffHomePage coolingOffHomePage = new CoolingOffHomePage(driver);
}
}
Could you please assist me what the issue might be? Thanks