0
我寫了一個加載頁面導航鏈接的方法。該方法的工作原理,但當我添加代碼來檢查正確的URL和標籤標題我的測試不執行。有時候會發生這樣的情況:對於循環快速點擊頁面而沒有加載的頁面,我不知道這是否是一個問題,但我無法檢查加載了正確的url或tab標題的頁面,或者問題是我爲了檢查正確的網址或標籤標題而編寫的代碼。如何檢查頁面是否加載了正確的url和標籤標題
這是我的方法:
public void showNavigationLinks(){
Actions action = new Actions(driver);
String[] submenus = {"Accessories", "iMacs", "iPads" , "iPhones" , "iPods" , "MacBook"};
for(int i=0;i<submenus.length;i++)
{
Assert.assertTrue(driver.getCurrentUrl().toLowerCase().contains(submenus[i]));
Assert.assertTrue(driver.getTitle().contains(submenus[i]));
WebElement we = driver.findElement(By.xpath("//a[contains(.,'Product Category')]"));
wait(2000);
action.moveToElement(we).moveToElement(driver.findElement(By.xpath("//a[contains(.,'"+submenus[i]+"')]"))).click().build().perform();
wait(3000);
}
link_all_product.click();
}
這是我的錯誤:
Starting ChromeDriver 2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed) on port 2140
Only local connections are allowed.
Jan 17, 2017 4:51:23 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Jan 17, 2017 4:51:31 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
java.lang.AssertionError
at org.junit.Assert.fail(Assert.java:86)
at org.junit.Assert.assertTrue(Assert.java:41)
at org.junit.Assert.assertTrue(Assert.java:52)
at PageObject.ProductPage.showNavigationLinks(ProductPage.java:620)
當我運行測試時,即使我更改了assert,錯誤也是一樣的:java.lang.AssertionError –
@DyJon我不明白。你能提供[mcve]嗎? – SiKing
@DyJon更新了我的答案,爲您提供更多提示。 – SiKing