package zacksolutions;

import com.microsoft.playwright.*;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.nio.file.Paths;

public class TextSelectorTest {
    Playwright playwright;
    Browser browser;
    Page page;
    @BeforeTest
    public void setUp(){
        playwright = Playwright.create();
        browser = playwright.firefox().launch(new BrowserType.LaunchOptions().setHeadless(false));
        page = browser.newPage();
    }
    @Test
    public void browserLaunch() {
        page.navigate("https://amazon.com");
        System.out.println(page.title());
        Locator linkCount = page.locator("text=Amazon");
        System.out.println(linkCount.count());
        for (int i = 0; i < linkCount.count(); i++) {
            String text = linkCount.nth(i).textContent();
            if(text.contains("Science")){
                System.out.println(text);
                linkCount.nth(i).click();
                break;
            }
        }
    }
    @AfterTest
    public void tearDown() {
/*
        browser.close();
        playwright.close();
*/
    }
}
