2017-05-24 55 views
2

我已经创建了以下方法,该方法点击将打开警报的特定按钮,然后下面列出的相同方法将处理警报。Webdriver:为什么我仍然收到'意外的警报打开'?

但我似乎越来越奇詹金斯打造这将(间断)失败的原因说意外警报开放(如下除外),任何想法?

异常标记:

unexpected alert open 
    (Session info: chrome=58.0.3029.110) 
    (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 63 milliseconds: null 
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' 
System info: host: 'DEV007', ip: '172.16.2.192', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131' 
Driver info: org.openqa.selenium.chrome.ChromeDriver 
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233), userDataDir=C:\Users\GIANNI~1.BRU\AppData\Local\Temp\2\scoped_dir9140_30313}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=58.0.3029.110, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}] 
Session ID: 699ee1257882397cd7695aeaf919c68f 
*** Element info: {Using=xpath, value=//button[contains(text(), "Pay Securely Now")]} 



org.openqa.selenium.UnhandledAlertException: 
unexpected alert open 
    (Session info: chrome=58.0.3029.110) 
    (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 63 milliseconds: null 
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' 
System info: host: 'DEV007', ip: '172.16.2.192', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131' 
Driver info: org.openqa.selenium.chrome.ChromeDriver 
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233), userDataDir=C:\Users\GIANNI~1.BRU\AppData\Local\Temp\2\scoped_dir9140_30313}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=58.0.3029.110, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}] 
Session ID: 699ee1257882397cd7695aeaf919c68f 
*** Element info: {Using=xpath, value=//button[contains(text(), "Pay Securely Now")]} 
    at BuyAGiftFramework.complete.AddingDrivingExperienceToBasketTest.clickOn_PaySecurelyNowButton(AddingDrivingExperienceToBasketTest.java:51) 






TEST CLASS END TIME: 03.10.30 
0 
0 
Tests run: 314, Failures: 80, Errors: 0, Skipped: 214, Time elapsed: 62.972 sec <<< FAILURE! - in TestSuite 
clickOn_PaySecurelyNowButton(BuyAGiftFramework.complete.AddingDrivingExperienceToBasketTest) Time elapsed: 0.298 sec <<< FAILURE! 
org.openqa.selenium.UnhandledAlertException: 
unexpected alert open 
    (Session info: chrome=58.0.3029.110) 
    (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 63 milliseconds: null 
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' 
System info: host: 'DEV007', ip: '172.16.2.192', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131' 
Driver info: org.openqa.selenium.chrome.ChromeDriver 
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233), userDataDir=C:\Users\GIANNI~1.BRU\AppData\Local\Temp\2\scoped_dir9140_30313}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=58.0.3029.110, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}] 
Session ID: 699ee1257882397cd7695aeaf919c68f 
*** Element info: {Using=xpath, value=//button[contains(text(), "Pay Securely Now")]} 
     at BuyAGiftFramework.complete.AddingDrivingExperienceToBasketTest.clickOn_PaySecurelyNowButton(AddingDrivingExperienceToBasketTest.java:51) 

EmailFormatAndDataCapture(BuyAGiftFramework.complete.AddingDrivingExperienceToBasketTest) Time elapsed: 0.299 sec <<< FAILURE! 
org.openqa.selenium.UnhandledAlertException: 
unexpected alert open: {Alert text : Click OK to confirm your personal message is correct as this is exactly how it will be printed.} 
    (Session info: chrome=58.0.3029.110) 
    (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) 
Command duration or timeout: 4 milliseconds: null 
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' 
System info: host: 'DEV007', ip: '172.16.2.192', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131' 
Driver info: org.openqa.selenium.chrome.ChromeDriver 
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233), userDataDir=C:\Users\GIANNI~1.BRU\AppData\Local\Temp\2\scoped_dir9140_30313}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=58.0.3029.110, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, 
+0

哪一行抛出该erorr? – kushal

+0

@ kushal.im不确定,我从詹金斯添加了例外行 – Gbru

+0

在收到此错误消息后,您是否有任何已打开的警报? – kushal

回答

1

在这一行你已经采取了警告:Alert alert = tempWait.until(ExpectedConditions.alertIsPresent());

,而不是写driver.switchTo().alert().accept();的,尝试做这种方式:alert.accept();

更新:
如果你只是想不惜一切代价接受警报,最好将点击线外的尝试区块移开。我有一个很好的理由相信点击行会导致你的未处理的警报异常,因为我以前遇到同样的问题。

尝试更新,像这样的代码:

public void clickPaySecurelyNowButton() throws InterruptedException { 

    try { 
     waitAndclickElementUsingJS(button_PaySecurelyNowTop); 

     WebDriverWait tempWait = new WebDriverWait(this.driver, 30); 
     tempWait.until(ExpectedConditions.alertIsPresent()); 
     boolean boolAlert = false; 
     int attempts = 0; 
     while (!boolAlert && attempts < 1000) { 
      attempts++; 
      driver.switchTo().alert().accept(); 
      System.out.println("Successfully clicked on the 'Pay Securely Now Button' and 'Closed the popup'"); 
      boolAlert = true; 
     } 
    } catch (org.openqa.selenium.UnhandledAlertException e) { 
     driver.switchTo().alert().accept(); 
     boolAlert = true; 
     System.out.println("Sucesffuly clicked on the 'Pay Securely Now Button' and 'Closed the popup'"); 
    } catch (Exception e) { 
     System.out.println("Unable to click on the 'Pay Securely Now Button', Exception: " + e.getMessage()); 
     Assert.fail("Method failed: clickPaySecurelyNowButton"); 
    } 
} 

== == OR
可以驱动程序安装过程中使用Chrome功能使用全局设置:

DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); 

WebDriver driver = new ChromeDriver(capabilities); 
+0

我害怕我已经试过这个了,我担心这个问题仍然存在 – Gbru

+0

而不是直接从詹金斯运行,你可以尝试从你的IDE进行调试,看看哪一行导致抛出错误?你需要检查你是否到达'try'块,或者在'try'块本身之前发生错误。我以前有类似的问题,我猜你的错误发生在这一行:'waitAndclickElementUsingJS(button_PaySecurelyNowTop);'请检查,如果它确实,我会相应地更新我的答案。 – iamkenos

+0

问题在于它非常难以复制问题,例如在200个版本中,如果每次都手动触发构建,则会导致异常,因此难以复制:/ – Gbru

相关问题