0
package StepDefinations;

import java.time.Duration;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;

import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import pageObjects.loginPage;


public class POMLoginStepsDefination {
     WebDriver driver;
     loginPage login;

    @Given("User is login psge")
    public void user_is_login_psge() {
        // Write code here that turns the phrase above into concrete actions
      driver = new EdgeDriver();
      driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
      driver.get("https://www.saucedemo.com/");
    }

    //@When("User enters valid username and password")
    @When("User enters valid {string} and {string}")
    public void user_enters_valid_and(String username, String password) throws InterruptedException {
    //public void user_enters_valid_username_and_password() {
        // Write code here that turns the phrase above into concrete actions

        login = new loginPage(driver);
        login.enterUsername(username);
        login.enterPassword(password);
        /*
     * driver.findElement(By.id("user-name")).sendKeys("standard_user");
     * driver.findElement(By.id("password")).sendKeys("secret_sauce");
     * Thread.sleep(2000);
     */
    }

    @And("clicks on Login Button")
    public void clicks_on_login_button() {
        // Write code here that turns the phrase above into concrete actions
    // driver.findElement(By.xpath("//input[@id='login-button']")).click();
        login.clickLogin();
    }

    @Then("User is navigated to Home Page")
    public void user_is_navigated_to_home_page() {
        // Write code here that turns the phrase above into concrete actions
        login.isLogoDisplayed();
        //Assert.isTrue(driver.findElements(By.xpath("//div[@class='app_logo']")).size()>0,"User is navigated to Home Page");
    }

    @And("Close the browser")
    public void close_the_browser() {
        // Write code here that turns the phrase above into concrete actions
      driver.close();
    }



}
João Farias
  • 10,876
  • 2
  • 18
  • 39
  • Tejas, to make clear and easier for people to contribute, I suggest you editing your code to only the relevant code, showing how you are running, and what outputs you see. – João Farias Mar 24 '24 at 17:46

0 Answers0