package DataProvider;

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 org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class DataProvider {

    WebDriver obj;

    @BeforeClass
    void before() {
        obj = new FirefoxDriver();
        obj.get("https://rahulshettyacademy.com/locatorspractice/");
    }

    @Test(dataProvider = "getData")   // adding data provider name on the test.
    void Test1(String Username, String Password)
    {

        WebElement username = obj.findElement(By.id("inputUsername"));
        username.clear();      // --------> for next value to be test.
        username.sendKeys(Username);

        WebElement password = obj.findElement(By.xpath("//input[@placeholder='Password']"));
        password.clear();      //---------> clearing for next value to be test.
        password.sendKeys(Password);

        obj.findElement(By.className("signInBtn")).click(); // clicking on button.


    }

    @org.testng.annotations.DataProvider
    Object[][] getData() {
        Object[][] data = new Object[3][2]; // creating a Dynamic Array. size 3 rows 2 Col
        data[0][0] = "Qazi";                // storing value on indexes
        data[0][1] = "rahulshettyacademy";

        data[1][0] = "Zain";
        data[1][1] = "rahulshettyacademy";

        data[2][0] = "Ali";
        data[2][1] = "rahulshettyacademy";

        return data;                       // returning Array
    }

    @AfterClass
    void tearDown() {
        obj.quit();          // close the browser after test.
    }
}
