Created
October 30, 2019 18:24
-
-
Save batmi02/41ad57ac427571e6831c49a4e03ed4b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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