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.

    }
}
