org.openqa.selenium.WebDriverException:第二个测试用例

时间:2017-03-10 11:08:30

标签: java selenium exception webdriver upgrade

我今天已升级到Selenium 3.3.0。

升级后,我的testNG成功执行第一次测试。

我的第二次测试引发了WebDriverException

  

org.openqa.selenium.WebDriverException:发生了未知错误   构建信息:版本:'未知',修订版:'b526bd5',时间:'2017-03-07   11:11:07 -0800'系统信息:主持人:'INDH001138',ip:'10 .244.44.33',   os.name:'Windows 7',os.arch:'amd64',os.version:'6.1',   java.version:'1.8.0_51'驱动程序信息:   org.openqa.selenium.firefox.FirefoxDriver功能   [{MOZ:轮廓= C:\用户\ z019999 \应用程序数据\本地\ TEMP \ rust_mozprofile.45imqIpOZwTh,   rotate = false,timeouts = {implicit = 0,page load = 300000,   script = 30000},pageLoadStrategy = normal,platform = ANY,   specificationLevel = 0,moz:accessibilityChecks = false,   acceptInsecureCerts = false,browserVersion = 52.0,platformVersion = 6.1,   moz:processID = 2808,browserName = firefox,platformName = windows_nt}]   会议ID:f8fdc26d-26c6-40d6-b4b4-f0bb4aae087a at   sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)     at sun.reflect.NativeConstructorAccessorImpl.newInstance(未知   来源)at   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(未知   来自java.lang.reflect.Constructor.newInstance(未知来源)     在   org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:127)     在   org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:93)     在   org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42)     在   org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)     在   org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)     在   org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)     在   org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:661)     在   org.openqa.selenium.remote.RemoteWebDriver $ RemoteTargetLocator.alert(RemoteWebDriver.java:990)     在   com.myCompany.myProject.utility.SeleniumLib.isAlertPresent(SeleniumLib.java:507)     在   com.myCompany.myProject.utility.SeleniumLib.handleAlertAccept(SeleniumLib.java:424)     在   com.myCompany.myProject.utility.SeleniumLib.executeTestCase(SeleniumLib.java:613)     在   com.myCompany.myProject.testEngine.TestCaseEngine.solo(TestCaseEngine.java:132)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at   sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at   java.lang.reflect.Method.invoke(未知来源)at   org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)     在org.testng.internal.Invoker.invokeMethod(Invoker.java:661)at   org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)at   org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)at   org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)     在   org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)     在org.testng.TestRunner.privateRun(TestRunner.java:744)at   org.testng.TestRunner.run(TestRunner.java:602)at   org.testng.SuiteRunner.runTest(SuiteRunner.java:380)at   org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)at at   org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)at at   org.testng.SuiteRunner.run(SuiteRunner.java:289)at   org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)at   org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)at   org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)at at   org.testng.TestNG.runSuitesLocally(TestNG.java:1226)at at   org.testng.TestNG.runSuites(TestNG.java:1144)at   org.testng.TestNG.run(TestNG.java:1115)at   org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)     at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)     在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)

代码停止的地方

private static boolean isAlertPresent() 
    { 
        try 
        { 
            driver.switchTo().alert(); // Place where my code fails
            return true; 
        } 
        catch (NoAlertPresentException Ex) 
        { 
            return false; 
        }
    }

注意:此代码适用于测试用例编号1.但对于测试用例编号2,3等则失败。

2 个答案:

答案 0 :(得分:0)

您似乎正在切换到警报。但是你没有点击" OK"或"取消"按钮。因此,您可能需要添加以下代码行来单击"确定"或"取消"。

//Switch to the Alert & Accept
driver.switchTo().alert().accept();

//Switch to the Alert & Dismiss
driver.switchTo().alert().dismiss();

让我知道它是否对你有所帮助。

答案 1 :(得分:0)

如果这在升级之前有效,我会降级为诚实。但是,如果你坚持,解决方法可能是在短暂的2秒延迟后尝试循环,以消除过早尝试定位警报的失败。

所以这是带有延迟的循环中的完整工作代码:

for(int i=1; i<3; i++)    
{
        try{
        TimeUnit.SECONDS.sleep(2);
        driver.switchTo().alert();
        System.out.printf("%n*** An alert was present ***");       
        alertPresent=true;
        }
        catch (NoAlertPresentException e) {
        System.out.printf("%n*** An alert was not present ***");
        alertPresent=false;
        }   
return alertPresent;
}