I wrote a method to load the page navigation links. The method works, but when I added code to check the correct URL and tab title my test is not performed. Sometimes it happens that for loop fast clicks on the pages the side that does not get loaded, I do not know whether it is a problem but I can not check whether a page loaded with the correct url or tab title, or the problem is the code that I wrote for check the correct url or tab title.
This is my method:
public void showNavigationLinks(){ Actions action = new Actions(driver); String[] submenus = {"Accessories", "iMacs", "iPads" , "iPhones" , "iPods" , "MacBook"}; for(int i=0;i<submenus.length;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); waitForElementToBeDisplayed(driver.findElement(By.xpath("//a[contains(.,'"+submenus[i]+"')]")) , 500); Assert.assertTrue(driver.getCurrentUrl().toLowerCase().contains(submenus[i])); Assert.assertTrue(driver.getTitle().contains(submenus[i])); } link_all_product.click(); }
This is my error:
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:627)