LambdaTest Community

Find answers, support, and inspiration from other users

Questions
LambdaTest Community
Unanswered

Checking correct url and title page automatically

I tried to create a method that I'm going to check whether the page is loaded with the correct URL and title. My code pass several times, several times fall. This is my error:

java.lang.AssertionError: Checking if http://store.demoqa.com/products-page/product-category/accessories/ contains: imacs

This is my code:

public void showNavigationLinks() {

        Actions action = new Actions(driver);
        String[] submenu = {"Accessories", "iMacs", "iPads" , "iPhones" , "iPods" , "MacBook"};

        for(int i=0; i < submenu.length; i++) {

            WebElement productCategory = waitForElementToBeDisplayed(By.xpath("//a[contains(.,'Product Category')]"), 5000);
            action = action.moveToElement(productCategory);

            WebElement submenuItem = waitForElementToBeDisplayed(By.xpath("//a[contains(.,'" + submenu[i] + "')]"), 5000);
            action.moveToElement(submenuItem).click().build().perform();

            String currentUrl = driver.getCurrentUrl();
            String title = driver.getTitle();

            Assert.assertTrue("Checking if " + currentUrl + " contains: " + submenu[i].toLowerCase(),
                    currentUrl.contains(submenu[i].toLowerCase()));

            Assert.assertTrue("Checking if title contains: " + submenu[i],
                    title.contains(submenu[i]));
            System.out.println(title);
        }
Up Vote Down Vote 0 Votes
Posted 29 days ago

Answers

126 Views
0 Answers
29 days ago