From 5cc91654c3e651c876875b8ad7187743d79da8e2 Mon Sep 17 00:00:00 2001
From: Patrick <50352812+Mueller-Patrick@users.noreply.github.com>
Date: Thu, 13 May 2021 16:42:55 +0200
Subject: [PATCH] BETTERZON-99: Adding some basic cucumber tests (#45)
---
CucumberTests/CucumberTests.iml | 43 ++++++--
CucumberTests/pom.xml | 19 +++-
CucumberTests/src/test/java/RunTest.java | 17 +++-
.../src/test/java/stepdefs/Preconditions.java | 7 ++
.../src/test/java/stepdefs/PriceAlarm.java | 97 ++++++++++---------
.../src/test/java/stepdefs/SearchProduct.java | 94 +++++++++++-------
.../src/test/resource/priceAlarms.feature | 48 ++++-----
.../src/test/resource/searchProduct.feature | 44 ++++-----
8 files changed, 223 insertions(+), 146 deletions(-)
create mode 100644 CucumberTests/src/test/java/stepdefs/Preconditions.java
diff --git a/CucumberTests/CucumberTests.iml b/CucumberTests/CucumberTests.iml
index 70e64e8..d398c4f 100644
--- a/CucumberTests/CucumberTests.iml
+++ b/CucumberTests/CucumberTests.iml
@@ -10,17 +10,24 @@
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -53,5 +60,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CucumberTests/pom.xml b/CucumberTests/pom.xml
index 3f233e8..c72eb52 100644
--- a/CucumberTests/pom.xml
+++ b/CucumberTests/pom.xml
@@ -13,21 +13,30 @@
- io.cucumber
- cucumber-java
- 2.3.1
+ junit
+ junit
+ 4.12
test
+
+ io.cucumber
+ cucumber-java
+ 6.10.3
+
io.cucumber
cucumber-junit
- 2.3.1
- test
+ 6.10.3
org.apache.maven.plugins
maven-compiler-plugin
3.8.1
+
+ org.seleniumhq.selenium
+ selenium-java
+ 3.141.59
+
diff --git a/CucumberTests/src/test/java/RunTest.java b/CucumberTests/src/test/java/RunTest.java
index f7c5387..fcbc954 100644
--- a/CucumberTests/src/test/java/RunTest.java
+++ b/CucumberTests/src/test/java/RunTest.java
@@ -1,6 +1,10 @@
-import cucumber.api.CucumberOptions;
-import cucumber.api.junit.Cucumber;
+import io.cucumber.junit.Cucumber;
+import io.cucumber.junit.CucumberOptions;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.runner.RunWith;
+import org.openqa.selenium.firefox.FirefoxDriver;
+import stepdefs.Preconditions;
@RunWith(Cucumber.class)
@CucumberOptions(
@@ -9,4 +13,13 @@ import org.junit.runner.RunWith;
)
public class RunTest {
+ @BeforeClass
+ public static void setup() {
+ Preconditions.driver= new FirefoxDriver();
+ }
+
+ @AfterClass
+ public static void teardown() {
+ Preconditions.driver.close();
+ }
}
diff --git a/CucumberTests/src/test/java/stepdefs/Preconditions.java b/CucumberTests/src/test/java/stepdefs/Preconditions.java
new file mode 100644
index 0000000..f9c22b1
--- /dev/null
+++ b/CucumberTests/src/test/java/stepdefs/Preconditions.java
@@ -0,0 +1,7 @@
+package stepdefs;
+
+import org.openqa.selenium.WebDriver;
+
+public class Preconditions {
+ public static WebDriver driver;
+}
diff --git a/CucumberTests/src/test/java/stepdefs/PriceAlarm.java b/CucumberTests/src/test/java/stepdefs/PriceAlarm.java
index 8c82759..83c332e 100644
--- a/CucumberTests/src/test/java/stepdefs/PriceAlarm.java
+++ b/CucumberTests/src/test/java/stepdefs/PriceAlarm.java
@@ -1,67 +1,68 @@
package stepdefs;
-import cucumber.api.java.en.Given;
-import cucumber.api.java.en.Then;
-import cucumber.api.java.en.When;
+import io.cucumber.java.PendingException;
+import io.cucumber.java.en.Given;
+import io.cucumber.java.en.Then;
+import io.cucumber.java.en.When;
public class PriceAlarm {
- @Given("^the user has at least (\\d+) price alarm set$")
- public void the_user_has_at_least_price_alarm_set(int arg1) throws Exception {
- }
+ @Given("^the user has at least (\\d+) price alarm set$")
+ public void the_user_has_at_least_price_alarm_set(int arg1) throws Exception {
+ }
- @When("^the user clicks on the profile icon$")
- public void the_user_clicks_on_the_profile_icon() throws Exception {
- }
+ @When("^the user clicks on the profile icon$")
+ public void the_user_clicks_on_the_profile_icon() throws Exception {
+ }
- @Then("^the profile details popup should open$")
- public void the_profile_details_popup_should_open() throws Exception {
- }
+ @Then("^the profile details popup should open$")
+ public void the_profile_details_popup_should_open() throws Exception {
+ }
- @When("^the user clicks on price alarms$")
- public void the_user_clicks_on_price_alarms() throws Exception {
- }
+ @When("^the user clicks on price alarms$")
+ public void the_user_clicks_on_price_alarms() throws Exception {
+ }
- @Then("^the price alarm list should open$")
- public void the_price_alarm_list_should_open() throws Exception {
- }
+ @Then("^the price alarm list should open$")
+ public void the_price_alarm_list_should_open() throws Exception {
+ }
- @Then("^the price alarm list should contain at least (\\d+) entry$")
- public void the_price_alarm_list_should_contain_at_least_entry(int arg1) throws Exception {
- }
+ @Then("^the price alarm list should contain at least (\\d+) entry$")
+ public void the_price_alarm_list_should_contain_at_least_entry(int arg1) throws Exception {
+ }
- @Then("^the price alarm list should contain a maximum of (\\d+) entries per page$")
- public void the_price_alarm_list_should_contain_a_maximum_of_entries_per_page(int arg1) throws Exception {
- }
+ @Then("^the price alarm list should contain a maximum of (\\d+) entries per page$")
+ public void the_price_alarm_list_should_contain_a_maximum_of_entries_per_page(int arg1) throws Exception {
+ }
- @Given("^the user is on the price alarm list page$")
- public void the_user_is_on_the_price_alarm_list_page() throws Exception {
- }
+ @Given("^the user is on the price alarm list page$")
+ public void the_user_is_on_the_price_alarm_list_page() throws Exception {
+ }
- @When("^the user clicks on the \"([^\"]*)\" button next to a price alarm$")
- public void the_user_clicks_on_the_button_next_to_a_price_alarm(String arg1) throws Exception {
- }
+ @When("^the user clicks on the \"([^\"]*)\" button next to a price alarm$")
+ public void the_user_clicks_on_the_button_next_to_a_price_alarm(String arg1) throws Exception {
+ }
- @Then("^a popup should open asking the user to confirm the removal$")
- public void a_popup_should_open_asking_the_user_to_confirm_the_removal() throws Exception {
- }
+ @Then("^a popup should open asking the user to confirm the removal$")
+ public void a_popup_should_open_asking_the_user_to_confirm_the_removal() throws Exception {
+ }
- @When("^the user confirms the removal of the price alarm$")
- public void the_user_confirms_the_removal_of_the_price_alarm() throws Exception {
- }
+ @When("^the user confirms the removal of the price alarm$")
+ public void the_user_confirms_the_removal_of_the_price_alarm() throws Exception {
+ }
- @Then("^the price alarm should be removed from the database$")
- public void the_price_alarm_should_be_removed_from_the_database() throws Exception {
- }
+ @Then("^the price alarm should be removed from the database$")
+ public void the_price_alarm_should_be_removed_from_the_database() throws Exception {
+ }
- @Then("^a popup should open where the user can edit the alarm$")
- public void a_popup_should_open_where_the_user_can_edit_the_alarm() throws Exception {
- }
+ @Then("^a popup should open where the user can edit the alarm$")
+ public void a_popup_should_open_where_the_user_can_edit_the_alarm() throws Exception {
+ }
- @When("^the user clicks on the \"([^\"]*)\" button$")
- public void the_user_clicks_on_the_button(String arg1) throws Exception {
- }
+ @When("^the user clicks on the \"([^\"]*)\" button$")
+ public void the_user_clicks_on_the_button(String arg1) throws Exception {
+ }
- @Then("^the price alarm should be updated in the database$")
- public void the_price_alarm_should_be_updated_in_the_database() throws Exception {
- }
+ @Then("^the price alarm should be updated in the database$")
+ public void the_price_alarm_should_be_updated_in_the_database() throws Exception {
+ }
}
diff --git a/CucumberTests/src/test/java/stepdefs/SearchProduct.java b/CucumberTests/src/test/java/stepdefs/SearchProduct.java
index 536a952..af32faa 100644
--- a/CucumberTests/src/test/java/stepdefs/SearchProduct.java
+++ b/CucumberTests/src/test/java/stepdefs/SearchProduct.java
@@ -1,52 +1,72 @@
package stepdefs;
-import cucumber.api.PendingException;
-import cucumber.api.java.en.Given;
-import cucumber.api.java.en.Then;
-import cucumber.api.java.en.When;
+import io.cucumber.java.PendingException;
+import io.cucumber.java.en.Given;
+import io.cucumber.java.en.Then;
+import io.cucumber.java.en.When;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+import org.openqa.selenium.support.ui.WebDriverWait;
public class SearchProduct {
- @Given("^the user is on the landing page$")
- public void the_user_is_on_the_landing_page() throws Exception {
- }
+ @Given("^the user is on the landing page$")
+ public void the_user_is_on_the_landing_page() throws Exception {
+ //throw new PendingException();
+ Preconditions.driver.get("https://betterzon.xyz");
+ WebElement logo = (new WebDriverWait(Preconditions.driver, 10))
+ .until(ExpectedConditions.elementToBeClickable(By.cssSelector(".logo")));
+ }
- @When("^the user enters the search term \"([^\"]*)\" and clicks search$")
- public void the_user_enters_the_search_term_and_clicks_search(String arg0) throws Exception {
- }
+ @When("^the user enters the search term \"([^\"]*)\" and clicks search$")
+ public void the_user_enters_the_search_term_and_clicks_search(String searchTerm) throws Exception {
+ WebElement searchField = Preconditions.driver.findElement(By.cssSelector(".ng-untouched.ng-pristine.ng-valid"));
+ searchField.sendKeys(searchTerm);
+ searchField.sendKeys(Keys.ENTER);
+ WebElement logo = (new WebDriverWait(Preconditions.driver, 10))
+ .until(ExpectedConditions.elementToBeClickable(By.cssSelector(".logo")));
+ }
- @Then("^the user should see the error page \"([^\"]*)\"$")
- public void the_user_should_see_the_error_page(String arg0) throws Exception {
- }
+ @Then("^the user should see the error page \"([^\"]*)\"$")
+ public void the_user_should_see_the_error_page(String arg0) throws Exception {
+ WebElement noProdsFoundMsg = (new WebDriverWait(Preconditions.driver, 10))
+ .until(ExpectedConditions.elementToBeClickable(By.cssSelector(".ng-star-inserted")));
+ assert(noProdsFoundMsg.getText().contains("No Products found!"));
+ }
- @Given("^the user is not logged in$")
- public void the_user_is_not_logged_in() throws Exception {
- }
+ @Given("^the user is not logged in$")
+ public void the_user_is_not_logged_in() throws Exception {
+ }
- @Given("^the user is logged in$")
- public void the_user_is_logged_in() throws Exception {
- }
+ @Given("^the user is logged in$")
+ public void the_user_is_logged_in() throws Exception {
+ }
- @Then("^the user should see a list of products$")
- public void the_user_should_see_a_list_of_products() throws Exception {
- }
+ @Then("^the user should see a list of products$")
+ public void the_user_should_see_a_list_of_products() throws Exception {
+ WebElement product = (new WebDriverWait(Preconditions.driver, 10))
+ .until(ExpectedConditions.elementToBeClickable(By.cssSelector(".productItem.ng-star-inserted")));
+ assert(product.isDisplayed());
+ }
- @When("^the user clicks on the first product$")
- public void the_user_clicks_on_the_first_product() throws Exception {
- }
+ @When("^the user clicks on the first product$")
+ public void the_user_clicks_on_the_first_product() throws Exception {
+ }
- @Then("^the user should see the product detail page$")
- public void the_user_should_see_the_product_detail_page() throws Exception {
- }
+ @Then("^the user should see the product detail page$")
+ public void the_user_should_see_the_product_detail_page() throws Exception {
+ }
- @Then("^the set price alarm box should show \"([^\"]*)\"$")
- public void the_set_price_alarm_box_should_show(String arg0) throws Exception {
- }
+ @Then("^the set price alarm box should show \"([^\"]*)\"$")
+ public void the_set_price_alarm_box_should_show(String arg0) throws Exception {
+ }
- @When("^the user sets a price alarm$")
- public void the_user_sets_a_price_alarm() throws Exception {
- }
+ @When("^the user sets a price alarm$")
+ public void the_user_sets_a_price_alarm() throws Exception {
+ }
- @Then("^the user should receive an email confirming the price alarm$")
- public void the_user_should_receive_an_email_confirming_the_price_alarm() throws Exception {
- }
+ @Then("^the user should receive an email confirming the price alarm$")
+ public void the_user_should_receive_an_email_confirming_the_price_alarm() throws Exception {
+ }
}
diff --git a/CucumberTests/src/test/resource/priceAlarms.feature b/CucumberTests/src/test/resource/priceAlarms.feature
index 1e75acb..0550eef 100644
--- a/CucumberTests/src/test/resource/priceAlarms.feature
+++ b/CucumberTests/src/test/resource/priceAlarms.feature
@@ -1,28 +1,28 @@
Feature: Price Alarms
- Scenario: Show a list of price alarms
- Given the user is on the landing page
- And the user is logged in
- And the user has at least 1 price alarm set
- When the user clicks on the profile icon
- Then the profile details popup should open
- When the user clicks on price alarms
- Then the price alarm list should open
- And the price alarm list should contain at least 1 entry
- And the price alarm list should contain a maximum of 20 entries per page
+ Scenario: Show a list of price alarms
+ Given the user is on the landing page
+ And the user is logged in
+ And the user has at least 1 price alarm set
+ When the user clicks on the profile icon
+ Then the profile details popup should open
+ When the user clicks on price alarms
+ Then the price alarm list should open
+ And the price alarm list should contain at least 1 entry
+ And the price alarm list should contain a maximum of 20 entries per page
- Scenario: Remove a price alarm
- Given the user is on the price alarm list page
- And the user is logged in
- When the user clicks on the "remove" button next to a price alarm
- Then a popup should open asking the user to confirm the removal
- When the user confirms the removal of the price alarm
- Then the price alarm should be removed from the database
+ Scenario: Remove a price alarm
+ Given the user is on the price alarm list page
+ And the user is logged in
+ When the user clicks on the "remove" button next to a price alarm
+ Then a popup should open asking the user to confirm the removal
+ When the user confirms the removal of the price alarm
+ Then the price alarm should be removed from the database
- Scenario: Edit a price alarm
- Given the user is on the price alarm list page
- And the user is logged in
- When the user clicks on the "edit" button next to a price alarm
- Then a popup should open where the user can edit the alarm
- When the user clicks on the "save changes" button
- Then the price alarm should be updated in the database
+ Scenario: Edit a price alarm
+ Given the user is on the price alarm list page
+ And the user is logged in
+ When the user clicks on the "edit" button next to a price alarm
+ Then a popup should open where the user can edit the alarm
+ When the user clicks on the "save changes" button
+ Then the price alarm should be updated in the database
diff --git a/CucumberTests/src/test/resource/searchProduct.feature b/CucumberTests/src/test/resource/searchProduct.feature
index 67d17f1..e73bdc5 100644
--- a/CucumberTests/src/test/resource/searchProduct.feature
+++ b/CucumberTests/src/test/resource/searchProduct.feature
@@ -1,26 +1,26 @@
Feature: Search a Product
- Scenario: User searches for unknown product
- Given the user is on the landing page
- When the user enters the search term "iPhone 13" and clicks search
- Then the user should see the error page "No products found"
+ Scenario: User searches for unknown product
+ Given the user is on the landing page
+ When the user enters the search term "iPhone 13" and clicks search
+ Then the user should see the error page "No products found"
- Scenario: User is not logged in, searches for known product
- Given the user is on the landing page
- And the user is not logged in
- When the user enters the search term "iPhone 12" and clicks search
- Then the user should see a list of products
- When the user clicks on the first product
- Then the user should see the product detail page
- And the set price alarm box should show "Log in to continue"
+ Scenario: User is not logged in, searches for known product
+ Given the user is on the landing page
+ And the user is not logged in
+ When the user enters the search term "iPhone 12" and clicks search
+ Then the user should see a list of products
+ When the user clicks on the first product
+ Then the user should see the product detail page
+ And the set price alarm box should show "Log in to continue"
- Scenario: User is logged in, searches for known product
- Given the user is on the landing page
- And the user is logged in
- When the user enters the search term "iPhone 12" and clicks search
- Then the user should see a list of products
- When the user clicks on the first product
- Then the user should see the product detail page
- And the set price alarm box should show "Set price alarm"
- When the user sets a price alarm
- Then the user should receive an email confirming the price alarm
+ Scenario: User is logged in, searches for known product
+ Given the user is on the landing page
+ And the user is logged in
+ When the user enters the search term "iPhone 12" and clicks search
+ Then the user should see a list of products
+ When the user clicks on the first product
+ Then the user should see the product detail page
+ And the set price alarm box should show "Set price alarm"
+ When the user sets a price alarm
+ Then the user should receive an email confirming the price alarm