completed first demo test
This commit is contained in:
parent
8d743d9fa9
commit
9a98767b67
@ -1,5 +1,6 @@
|
||||
package org.example.pages;
|
||||
|
||||
import com.microsoft.playwright.Locator;
|
||||
import com.microsoft.playwright.Page;
|
||||
|
||||
public class Login {
|
||||
@ -15,9 +16,18 @@ public class Login {
|
||||
|
||||
public Login(Page page) {
|
||||
this.page = page;
|
||||
}
|
||||
public String title() {
|
||||
return page.title();
|
||||
}
|
||||
|
||||
}public String verifyTitle() {
|
||||
return page.title();}
|
||||
public Locator usernameField() {
|
||||
return page.locator("//*[@id=\"user-name\"]");
|
||||
}
|
||||
|
||||
public Locator passwordField() {
|
||||
return page.locator("//*[@id=\"password\"]");
|
||||
}
|
||||
|
||||
public void loginIntoApplication(String email, String pass) {
|
||||
enterUserName(email);
|
||||
@ -26,7 +36,7 @@ public class Login {
|
||||
|
||||
public void logoutApplication() {
|
||||
clickOnHamburger();
|
||||
clickOnLogout(); } // Logout from the application
|
||||
clickOnLogout(); }
|
||||
|
||||
public void enterUserName(String email) {
|
||||
page.fill(username, email);}
|
||||
|
@ -1,13 +1,17 @@
|
||||
# Sample Cucumber test using the SWAGLABS site
|
||||
|
||||
Feature: Login
|
||||
Description: Demonstration of cucumber with Junit, and Playwright
|
||||
|
||||
Background:
|
||||
Given User has a functional browser
|
||||
When User navigates to the Swaglabs site
|
||||
Then User can see the SwagLabs login page
|
||||
|
||||
Scenario Outline: Login to SwagLabs Application with Correct credentials
|
||||
Given User launched SwagLabs application
|
||||
When User verify the Page title
|
||||
When User logged in the app using username “<UserName>” and password “<Password>”
|
||||
Then User verify the product name “<ProductName>”
|
||||
Then User logout from the application
|
||||
Given Unauthenticated user is at the SwagLabs login page
|
||||
When User logs in using username "<UserName>" and password "<Password>"
|
||||
Then User can see product "<ProductName>"
|
||||
|
||||
Examples:
|
||||
| UserName | Password | ProductName |
|
||||
|
@ -7,8 +7,10 @@ import org.junit.runner.RunWith;
|
||||
@RunWith(Cucumber.class)
|
||||
@CucumberOptions(
|
||||
features = "src/test/java/org/example/features/",
|
||||
glue = {"steps"},
|
||||
plugin = {"pretty"})
|
||||
glue = {"org.example.steps"},
|
||||
plugin = {"pretty"},
|
||||
publish = true
|
||||
)
|
||||
public class DemoRunner {
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
package org.example.steps;
|
||||
|
||||
import com.microsoft.playwright.Browser;
|
||||
import com.microsoft.playwright.BrowserType;
|
||||
import com.microsoft.playwright.Page;
|
||||
import com.microsoft.playwright.Playwright;
|
||||
import io.cucumber.java.AfterAll;
|
||||
import io.cucumber.java.Before;
|
||||
import io.cucumber.java.After;
|
||||
import io.cucumber.java.en.Given;
|
||||
import io.cucumber.java.en.Then;
|
||||
import io.cucumber.java.en.When;
|
||||
import org.example.TestContext;
|
||||
import org.example.pages.Home;
|
||||
import org.example.pages.Login;
|
||||
import org.junit.Assert;
|
||||
@ -18,32 +17,51 @@ public class LoginSteps {
|
||||
TestContext testContext = new TestContext("webkit", true);
|
||||
Page page = testContext.page;
|
||||
|
||||
@Given("User launched SwagLabs application")
|
||||
@Before
|
||||
public void setUp() {
|
||||
page.navigate("https://www.saucedemo.com/");
|
||||
home = new Home(page);
|
||||
login = new Login(page);
|
||||
}
|
||||
@When("User verify the Page title")
|
||||
public void verifyPageTitle() {
|
||||
String title = login.verifyTitle();
|
||||
Assert.assertEquals(title, "Swag Labs");
|
||||
|
||||
|
||||
@Given("User has a functional browser")
|
||||
public void userHasAFunctionalBrowser() {
|
||||
Assert.assertEquals("webkit", testContext.browser.browserType().name());
|
||||
}
|
||||
|
||||
@Then("User can see the SwagLabs login page")
|
||||
public void userCanSeeTheSwagLabsLoginPage() {
|
||||
Assert.assertTrue(login.usernameField().isVisible() && login.usernameField().isEditable());
|
||||
Assert.assertTrue(login.passwordField().isVisible() && login.passwordField().isEditable());
|
||||
}
|
||||
|
||||
@Given("User navigates to the Swaglabs site")
|
||||
public void userNavigatesToSwagLabs() {
|
||||
page.navigate("https://www.saucedemo.com/");
|
||||
Assert.assertEquals(login.title(), "Swag Labs");
|
||||
}
|
||||
|
||||
@Given("Unauthenticated user is at the SwagLabs login page")
|
||||
public void verifyLoginPage() {
|
||||
Assert.assertTrue(login.usernameField().isVisible() && login.usernameField().isEditable());
|
||||
Assert.assertTrue(login.passwordField().isVisible() && login.passwordField().isEditable());
|
||||
}
|
||||
//Login into the application
|
||||
@When("User logged in the app using username {string} and password {string}")
|
||||
@When("User logs in using username {string} and password {string}")
|
||||
public void loginIntoTheApplication(String username,String password ) {
|
||||
login.loginIntoApplication(username, password);
|
||||
Assert.assertEquals("hello","hello");
|
||||
}
|
||||
//Verify product name after login
|
||||
@Then("User verify the product name {string}")
|
||||
@Then("User can see product {string}")
|
||||
public void verifyProductsName(String productname) {
|
||||
String productName = home.getProductName();
|
||||
Assert.assertEquals(productName, productname);
|
||||
|
||||
}
|
||||
|
||||
//Logout from application
|
||||
@Then("User logout from the application")
|
||||
@After
|
||||
public void logoutFromApplication() {
|
||||
login.logoutApplication();}
|
||||
login.logoutApplication();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.example;
|
||||
package org.example.steps;
|
||||
|
||||
import com.microsoft.playwright.Browser;
|
||||
import com.microsoft.playwright.BrowserType;
|
||||
@ -29,5 +29,6 @@ public class TestContext {
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
2
src/test/resources/cucumber.properties
Normal file
2
src/test/resources/cucumber.properties
Normal file
@ -0,0 +1,2 @@
|
||||
cucumber.publish.enabled=true
|
||||
cucumber.publish.quiet=true
|
2
src/test/resources/junit-platform.properties
Normal file
2
src/test/resources/junit-platform.properties
Normal file
@ -0,0 +1,2 @@
|
||||
cucumber.publish.enabled=true
|
||||
cucumber.publish.quiet=true
|
Loading…
Reference in New Issue
Block a user