Skip to content

Instantly share code, notes, and snippets.

@batmi02
Created October 30, 2019 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save batmi02/41ad57ac427571e6831c49a4e03ed4b5 to your computer and use it in GitHub Desktop.
Save batmi02/41ad57ac427571e6831c49a4e03ed4b5 to your computer and use it in GitHub Desktop.
@Before
public void beforeEach() {
//Open the app
driver.get("http://localhost:8000/tablesort.html");
//Click on the Rank column
driver.findElement(By.id("rank")).click();
}
//Legacy Way
@Test
public void ascendingTest() throws InterruptedException {
//Get the 2nd column's elements using CSS Selector
List<WebElement> elementsList = driver.findElements(By.cssSelector("tr td:nth-child(1)"));
//Extract the text from each element and store it in a list
ArrayList<String> originalList = new ArrayList<String>();
for(int i=0; i < elementsList.size(); i++) {
originalList.add(elementsList.get(i).getText());
}
//Create a copy so we can sort this and compare with what we get from the UI
ArrayList<String> copiedList = new ArrayList<String>();
for(int i=0; i < originalList.size(); i++) {
copiedList.add(originalList.get(i));
}
System.out.println(copiedList);
//Sort the copied list
Collections.sort(copiedList);
System.out.println(copiedList);
//assert
assertTrue(originalList.equals(copiedList));
//Close
driver.close
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment