获取会话 ID 为空。调用 quit() 后使用 WebDriver?

问题描述 投票:0回答:0

我在使用 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}

这是我的测试课:

   @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"));
    }

这是我的司机工厂:

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;
    }
}
java selenium-webdriver appium-android appium-java
© www.soinside.com 2019 - 2024. All rights reserved.