Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit c351d2fd authored by rui rodrigues's avatar rui rodrigues
Browse files

add: procuct scenario to demo

parent 4fa00591
No related branches found
No related tags found
No related merge requests found
......@@ -3,4 +3,8 @@ package configuration.data;
public class Login {
public static final String URL = "https://www.saucedemo.com/";
public static final String SWAG_LABS = "Swag Labs";
public static final String USERNAME = "standard_user";
public static final String PASSWORD = "secret_sauce";
public static final String WRONG_TITLE = "SWAG FUN LABS";
}
package configuration.data;
public class Product {
public static final String BACKPACK_NAME = "Sauce Backpack";
}
package configuration.locators;
public class Home {
public class Product {
public static final String PRODUCT_NAME ="id=item_4_title_link";
}
......@@ -8,6 +8,8 @@ import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
import io.cucumber.java.Scenario;
import java.awt.*;
public class Framework {
private static Browser browser;
private static Page page;
......@@ -18,8 +20,10 @@ public class Framework {
Framework.scenario = scenario;
Playwright playwright = Playwright.create();
BrowserType chrome = playwright.chromium();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
browser = chrome.launch(new BrowserType.LaunchOptions().setHeadless(false));
page = browser.newPage();
page.setViewportSize(screenSize.width, screenSize.height);
}
@After
......@@ -39,5 +43,4 @@ public class Framework {
public static Scenario getScenario() {
return scenario;
}
}
package helpers;
import static configuration.locators.Home.PRODUCT_NAME;
import static configuration.locators.Product.PRODUCT_NAME;
import com.microsoft.playwright.Page;
public class HomePage {
public class ProductPage {
Page page;
public HomePage(Page page) {
public ProductPage(Page page) {
this.page = page;
}
......
@login
Feature: Login
@L01
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
Examples:
| UserName | Password | ProductName |
| standard_user | secret_sauce | Sauce Labs Backpack |
\ No newline at end of file
@L01
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
Examples:
| UserName | Password | ProductName |
| standard_user | secret_sauce | Sauce Labs Backpack |
@L01
Scenario Outline: Login to SwagLabs Application with Correct credentials
Given User launched SwagLabs application
When User verify the Page title with wrong 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
Examples:
| UserName | Password | ProductName |
| standard_user | secret_sauce | Sauce Labs Backpack |
\ No newline at end of file
@product
Feature: Product
@P01
Scenario: Assert that Backpack product exits
Given User launched SwagLabs application
When User verify the Page title
When User logged in the app using username and password
Then User assert that backpack product exists
Then User logout from the application
......@@ -3,7 +3,6 @@ package stepDefinitions;
import framework.Framework;
import com.microsoft.playwright.Page;
import helpers.HomePage;
import helpers.LoginPage;
import io.cucumber.java.Scenario;
......@@ -12,8 +11,7 @@ import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.junit.Assert;
import static configuration.data.Login.SWAG_LABS;
import static configuration.data.Login.URL;
import static configuration.data.Login.*;
public class LoginSteps {
......@@ -32,21 +30,24 @@ public class LoginSteps {
public void verifyPageTitle() {
String title = login.verifyTitle();
Assert.assertEquals(title, SWAG_LABS);
scenario.attach(SWAG_LABS, "text/plain", "title verified");
}
@When("User logged in the app using username {string} and password {string}")
public void loginIntoTheApplication(String username, String password) {
login.loginIntoApplication(username, password);
scenario.attach(username, "text/plain", "username");
@When("User verify the Page title with wrong title")
public void verifyPageTitleWrongly() {
String title = login.verifyTitle();
scenario.attach(WRONG_TITLE, "text/plain", "title verified");
Assert.assertEquals(title, WRONG_TITLE);
}
@Then("User verify the product name {string}")
public void verifyProductsName(String productname) {
HomePage home = new HomePage(page);
String productName = home.productName();
Assert.assertEquals(productName, productname);
byte[] screenshot = page.screenshot(new Page.ScreenshotOptions());
scenario.attach(screenshot, "image/png", "Evidence");
@When("User logged in the app using username and password")
public void loginIntoTheApplication() {
login.loginIntoApplication(USERNAME, PASSWORD);
}
@When("User logged in the app using username {string} and password {string}")
public void loginIntoTheApplicationWrongWay(String username, String password) {
login.loginIntoApplication(username, password);
}
@Then("User logout from the application")
......
package stepDefinitions;
import com.microsoft.playwright.Page;
import framework.Framework;
import helpers.ProductPage;
import io.cucumber.java.Scenario;
import io.cucumber.java.en.Then;
import org.junit.Assert;
import static configuration.data.Product.BACKPACK_NAME;
public class ProductSteps {
private final Page page = Framework.getPage();
private final Scenario scenario = Framework.getScenario();
@Then("User verify the product name {string}")
public void verifyProductsNameWrongly(String productname) {
ProductPage product = new ProductPage(page);
String productName = product.productName();
Assert.assertEquals(productName, productname);
byte[] screenshot = page.screenshot(new Page.ScreenshotOptions());
scenario.attach(screenshot, "image/png", "Evidence");
}
@Then("User assert that backpack product exists")
public void verifyBackpackProduct() {
ProductPage product = new ProductPage(page);
String productName = product.productName();
Assert.assertEquals(productName, BACKPACK_NAME);
byte[] screenshot = page.screenshot(new Page.ScreenshotOptions());
scenario.attach(screenshot, "image/png", "Evidence");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment