0

I have a table with some data like:

|_name_|___email_____|

|website|website@test.com|

After clicking on the name Website, a settings page of the Website is displayed. On the top, there is a header with the "Website" name.

I need a solution for JUnit to verify that after click on the "Website" name in the table user is redirected to the "Website" settings page.

I tried the way below but didn't help:

String firstNameInTheTable = driver.findElement(By.xpath(TestPage.FIRST_NAME_IN_THE_TABLE)).getText();
driver.findElement(By.xpath(TestPage.FIRST_NAME_IN_THE_TABLE)).click();
assertEquals(firstNameInTheTable, WebsitePage.WEBSITE_TITLE_TEXT);

Actually it would be better to verify that text from the first column ("name" in our case) is the same as on the settings page. So it may happen that we do not have a Website text but another Name. Still the test should pass.

Showme
  • 69
  • 1
  • 3
  • 8

2 Answers2

1

1.Select and get the name of the website.

WebElement element = driver.findElement(By.xpath("//xpath"))
String name = element.getText();
element.click();

2.Wait the load, select the title and assertEquals.

sleep(3);
String title = driver.findElement(By.xpath("//xpath")).getText();
Assert.assertTrue(name.equals(title));

/!\ If the 2nd step is to open a new window, take a look at the tutorial here (to put between the sleep(3); and String title ...).

Other :

sleep method

protected void sleep(int i) {
    driver.manage().timeouts().implicitlyWait(i, TimeUnit.SECONDS);
}
Community
  • 1
  • 1
e1che
  • 1,241
  • 1
  • 17
  • 34
0

This is example, you can refer it and create your TCs accordingly

    WebDriver driver = new FirefoxDriver();
    driver.get("https://www.google.co.in/");

    String linkTitle = driver.findElement(By.xpath("//a[@href='/intl/en/about.html']")).getText();
    driver.findElement(By.xpath("//a[@href='/intl/en/about.html']")).click();
    System.out.println(driver.findElement(By.xpath("//div[@id='corp-crumb']/ol/li")).getText());
    Assert.assertTrue(linkTitle.equals(driver.findElement(By.xpath("//div[@id='corp-crumb']/ol/li")).getText()));
Anand Somani
  • 801
  • 1
  • 6
  • 15