0

I am getting the following error when using Selenium:

org.openqa.selenium.WebDriverException: org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '4.8.2', revision: '826dbfc730'
System info: os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '13.2.1', java.version: '1.8.0_362'
Driver info: io.appium.java_client.android.AndroidDriver
Command: [null, findElement {using=xpath, value=//*[@text='Enter PIN']}]
Capabilities {appium:app: /Users/chandan/Desktop/mobi..., appium:appActivity: com.comviva.mobiquityconsum..., appium:appPackage: com.comviva.mobiquity.consu..., appium:autoGrantPermissions: true, appium:automationName: UiAutomator2, appium:clearDeviceLogsOnStart: true, appium:databaseEnabled: false, appium:desired: {app: /Users/chandan/Desktop/mobi..., appActivity: com.comviva.mobiquityconsum..., appPackage: com.comviva.mobiquity.consu..., autoGrantPermissions: true, automationName: UiAutomator2, clearDeviceLogsOnStart: true, deviceName: Pixel5, eventTimings: true, ignoreHiddenApiPolicyError: true, newCommandTimeout: 30000, noReset: false, platformName: android, platformVersion: 12, udid: emulator-5554}, appium:deviceApiLevel: 31, appium:deviceManufacturer: Google, appium:deviceModel: sdk_gphone64_arm64, appium:deviceName: emulator-5554, appium:deviceScreenDensity: 440, appium:deviceScreenSize: 1080x2340, appium:deviceUDID: emulator-5554, appium:eventTimings: true, appium:ignoreHiddenApiPolicyError: true, appium:javascriptEnabled: true, appium:locationContextEnabled: false, appium:networkConnectionEnabled: true, appium:newCommandTimeout: 30000, appium:noReset: false, appium:pixelRatio: 2.75, appium:platformVersion: 12, appium:statBarHeight: 145, appium:takesScreenshot: true, appium:udid: emulator-5554, appium:viewportRect: {height: 1927, left: 0, top: 145, width: 1080}, appium:warnings: {}, appium:webStorageEnabled: false, platformName: ANDROID}

This is my Test Class:

   @AfterMethod
    public void tearDown(){
        DriverFactory.quitDriver();
    }

    @BeforeMethod
    public void startDriver(){
        DriverFactory.getMobileAppDriver();
    }

    @Test(priority = 1)
    public void  InvalidLogin(){
        ExtentManager.startTestFromProperty(pNode, TestCases.getTestCase("SMOKE_TC_07"));
        startPositveTest();
        login.login(DataDriven.getUserByStatus("Y"),"1234");
    }

    @Test(priority = 2)
    public  void  ElectricBill(){
        ExtentManager.startTestFromProperty(pNode, TestCases.getTestCase("SMOKE_TC_02"));
        startPositveTest();
        login.enterPin(DataDriven.getUserPinByStatus("Y"));
        billPay.electricityBillPay("50","OD23432123",DataDriven.getUserPinByStatus("Y"));
    }

This is my Driver Factory:

public class DriverFactory {

    private static WebDriver driver;
    private static AppiumDriver mobileDriver;
    private static final Logger logger = LoggerFactory.getLogger(DriverFactory.class);



    public static AppiumDriver getMobileAppDriver(){
       try{
           if(mobileDriver != null){
               return mobileDriver;
           }

           if (MobileProperties.getProperty("device.platform").equalsIgnoreCase("android")) {
               mobileDriver = MobileDriver.getAndroidDriver();
               logger.info("Info :  ");
           }
           else {
               mobileDriver = MobileDriver.getIOSDriver();
           }
       }
        catch (Exception e){
           e.printStackTrace();
        }
        return mobileDriver;
    }




    public static void quitDriver() {
        if (mobileDriver == null) {
            return;
        }
        mobileDriver.quit();
        mobileDriver = null;
    }
}
  • 1) Your `getMobileAppDriver();` returns a value. Why don't you use that value in your `startDriver`? 2) Where does exception happen exactly? 3) And obvious question: don't you use your driver after calling `quit()`? – Alexey R. Mar 26 '23 at 17:38
  • Hi @AlexeyR. Thank you for your valuable time. Actually I'm fresher in this field. Can you please help me with some line of code statement. I didn't get your point. – Chandan Dash Mar 28 '23 at 11:11
  • Well the problem is that the code you provided does not let us judge what the reason is. Since the error message is pretty much self-explanatory I suggest you first of all to check if you really use your driver after you have quit it. Try to put more logs so that you could test if the order of your logic parts is actually what you expect – Alexey R. Mar 28 '23 at 11:35

0 Answers0