2017-05-24 82 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

相關問題