Skip to content

Commit b90cde0

Browse files
Integration with cucumber (#1)
* Init : [Integration with cucumber] * Add : [Cucumber Scenario Login] * Add : [Cucumber Scenario Add to Cart Part 1]
1 parent dfed76f commit b90cde0

File tree

14 files changed

+276
-185
lines changed

14 files changed

+276
-185
lines changed

pom.xml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,45 @@
3232
<dependency>
3333
<groupId>io.github.bonigarcia</groupId>
3434
<artifactId>webdrivermanager</artifactId>
35-
<version>5.4.1</version>
35+
<version>5.5.3</version>
36+
</dependency>
37+
38+
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
39+
<dependency>
40+
<groupId>io.cucumber</groupId>
41+
<artifactId>cucumber-java</artifactId>
42+
<version>7.14.0</version>
3643
</dependency>
37-
</dependencies>
3844

45+
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
46+
<dependency>
47+
<groupId>io.cucumber</groupId>
48+
<artifactId>cucumber-junit</artifactId>
49+
<version>7.14.0</version>
50+
<scope>test</scope>
51+
</dependency>
52+
53+
<!-- https://mvnrepository.com/artifact/org.junit.platform/junit-platform-console -->
54+
<dependency>
55+
<groupId>org.junit.platform</groupId>
56+
<artifactId>junit-platform-console</artifactId>
57+
<version>1.10.0</version>
58+
</dependency>
59+
</dependencies>
60+
<build>
61+
<plugins>
62+
<plugin>
63+
<groupId>org.apache.maven.plugins</groupId>
64+
<artifactId>maven-surefire-plugin</artifactId>
65+
<version>3.0.0-M5</version>
66+
<configuration>
67+
<properties>
68+
<configurationParameters>
69+
cucumber.junit-platform.naming-strategy=long
70+
</configurationParameters>
71+
</properties>
72+
</configuration>
73+
</plugin>
74+
</plugins>
75+
</build>
3976
</project>

src/test/java/config/Config.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,13 @@
11
package config;
22

3-
import config.models.User;
4-
53
public class Config {
64
private final String baseUrl = "https://www.saucedemo.com/";
75

8-
public User standardUser, lockedOutUser, problemUser, errorUser;
9-
10-
public Config() {
11-
this.standardUser = new User("standard_user", "secret_sauce");
12-
this.lockedOutUser = new User("locked_out_user", "secret_sauce");
13-
this.problemUser = new User("problem_user", "secret_sauce");
14-
this.errorUser = new User("error_user", "secret_sauce");
15-
}
16-
176
public String getBaseUrl() {
187
return this.baseUrl;
198
}
209

2110
public String currentUrl(String path) {
2211
return this.baseUrl + path;
2312
}
24-
25-
public User getStandardUser() {
26-
return this.standardUser;
27-
}
28-
29-
public User getLockedOutUser() {
30-
return this.lockedOutUser;
31-
}
32-
33-
public User getProblemUser() {
34-
return this.problemUser;
35-
}
36-
37-
public User getErrorUser() {
38-
return this.errorUser;
39-
}
4013
}

src/test/java/config/SetupDriver.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package config;
22

33
import io.github.bonigarcia.wdm.WebDriverManager;
4-
import org.junit.jupiter.api.AfterEach;
5-
import org.junit.jupiter.api.BeforeAll;
6-
import org.junit.jupiter.api.BeforeEach;
74
import org.openqa.selenium.WebDriver;
85
import org.openqa.selenium.chrome.ChromeDriver;
96

@@ -14,25 +11,23 @@ public class SetupDriver {
1411

1512
public SetupDriver() {
1613
this.config = new Config();
14+
15+
setUpTest();
16+
1717
webDriver = new ChromeDriver();
1818
webDriver.manage().window().maximize();
19+
20+
openUrl();
1921
}
2022

21-
@BeforeAll
22-
static void setUpTest() {
23+
void setUpTest() {
2324
WebDriverManager.chromedriver().setup();
2425
}
2526

26-
@BeforeEach
2727
void openUrl() {
2828
webDriver.get(this.config.getBaseUrl());
2929
}
3030

31-
@AfterEach
32-
void closeBrowser() {
33-
webDriver.close();
34-
}
35-
3631
public String getCurrentUrl() {
3732
return this.webDriver.getCurrentUrl();
3833
}

src/test/java/config/ElementFormLogin.java renamed to src/test/java/config/elements/ElementFormLogin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package config;
1+
package config.elements;
22

33
import org.openqa.selenium.By;
44
import org.openqa.selenium.WebDriver;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package config.elements;
2+
3+
import org.openqa.selenium.By;
4+
import org.openqa.selenium.WebDriver;
5+
import org.openqa.selenium.WebElement;
6+
7+
public class ElementInventory {
8+
private final WebDriver webDriver;
9+
10+
public ElementInventory(WebDriver webDriver) {
11+
this.webDriver = webDriver;
12+
}
13+
14+
public WebElement buttonAddToCart(String productName) {
15+
return this.webDriver.findElement(By.id("add-to-cart-" + productName));
16+
}
17+
18+
public WebElement buttonRemoveFromCart(String productName) {
19+
return this.webDriver.findElement(By.id("remove-" + productName));
20+
}
21+
22+
public WebElement shoppingCart() {
23+
return this.webDriver.findElement(By.cssSelector(".shopping_cart_link > .shopping_cart_badge"));
24+
}
25+
}

src/test/java/config/models/User.java

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Feature: Add Product to Cart
2+
3+
Background:
4+
Given The user is logged in
5+
6+
Scenario: User successfully adds a product to the cart
7+
When The user clicks the add to cart button
8+
Then The text on the add to cart button should change to remove
9+
Then The number of items in the cart icon should be 1
10+
When The user click the add to cart button other product
11+
Then The text on the add to cart button other product should change to remove
12+
Then The number of items in the cart icon should be 2
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Feature: Login feature
2+
3+
Scenario Outline: User successfully logs in with valid credentials
4+
Given The user opens the web page or app
5+
When The user enters <username> as username
6+
And The user enters <password> as password
7+
And The user clicks the login button
8+
Then The user should be logged in successfully
9+
10+
Examples:
11+
| username | password |
12+
| standard_user | secret_sauce |
13+
14+
Scenario Outline: User fails to log in with invalid credentials
15+
Given The user opens the web page or app
16+
When The user enters <username> as username
17+
And The user enters <password> as password
18+
And The user clicks the login button
19+
Then The user should see an authentication error message
20+
21+
Examples:
22+
| username | password |
23+
| example | 123 |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package runner;
2+
3+
import io.cucumber.junit.Cucumber;
4+
import io.cucumber.junit.CucumberOptions;
5+
import org.junit.runner.RunWith;
6+
7+
@RunWith(Cucumber.class)
8+
@CucumberOptions(
9+
features = "src/test/java/resources/features",
10+
glue = "stepDef",
11+
plugin = {"html:target/AddToCart_report.html"}
12+
)
13+
public class RunAddToCart {
14+
}

src/test/java/runner/RunLogin.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package runner;
2+
3+
import io.cucumber.junit.Cucumber;
4+
import io.cucumber.junit.CucumberOptions;
5+
import org.junit.runner.RunWith;
6+
7+
@RunWith(Cucumber.class)
8+
@CucumberOptions(
9+
features = "src/test/java/resources/features",
10+
glue = "stepDef",
11+
plugin = {"html:target/Login_report.html"}
12+
)
13+
public class RunLogin {
14+
}

0 commit comments

Comments
 (0)