Commit e0f176c5 authored by Qazi Zain's avatar Qazi Zain

in Streams sorting code is added

parent a1af2b36
package Streams;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Alerts {
public static void main(String[] args) {
WebDriver obj = new FirefoxDriver();
obj.get("https://rahulshettyacademy.com/AutomationPractice/");
WebElement alertButton= obj.findElement(By.id("alertbtn"));
alertButton.click();
// now switch from window to alert for handle.
obj.switchTo().alert().accept();
// now click on confirm button
WebElement confirmButton = obj.findElement(By.id("confirmbtn"));
confirmButton.click();
obj.switchTo().alert().dismiss();
}
}
package Streams;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Sorting {
public static void main(String[] args) {
WebDriver obj = new FirefoxDriver();
obj.get("https://rahulshettyacademy.com/greenkart/#/offers");
obj.findElement(By.xpath("//tr/th[1]")).click();
// Capturing List .
List<WebElement> webList = obj.findElements(By.xpath("//tr/th[1]"));
// not storing in it arrayList.
List<String> realList = new ArrayList<>();
for (WebElement e: webList)
{
realList.add(e.getText()); // this will extract the text of web Element and store in List.
}
List<String> sortedList = new ArrayList<>(realList);
Collections.sort(sortedList);
// Creating Test using Assertion.
Assert.assertEquals(realList,sortedList); // if match then pass else fail.
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment