Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@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
You can’t perform that action at this time.