BETTERZON-99: Adding some basic cucumber tests (#45)

This commit is contained in:
Patrick 2021-05-13 16:42:55 +02:00 committed by GitHub
parent 0be394fc1d
commit 5cc91654c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 223 additions and 146 deletions

View File

@ -10,17 +10,24 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/resource" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/test/resource" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" /> <excludeFolder url="file://$MODULE_DIR$/target" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="openjdk-16" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: io.cucumber:cucumber-java:2.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.cucumber:cucumber-core:2.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: info.cukes:cucumber-html:0.2.6" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.cucumber:cucumber-jvm-deps:1.0.6" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.cucumber:gherkin:5.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.cucumber:tag-expressions:1.1.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: io.cucumber:cucumber-junit:2.3.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: io.cucumber:cucumber-java:6.10.3" level="project" />
<orderEntry type="library" name="Maven: io.cucumber:cucumber-core:6.10.3" level="project" />
<orderEntry type="library" name="Maven: io.cucumber:cucumber-gherkin:6.10.3" level="project" />
<orderEntry type="library" name="Maven: io.cucumber:cucumber-gherkin-messages:6.10.3" level="project" />
<orderEntry type="library" name="Maven: io.cucumber:messages:15.0.0" level="project" />
<orderEntry type="library" name="Maven: io.cucumber:tag-expressions:3.0.1" level="project" />
<orderEntry type="library" name="Maven: io.cucumber:cucumber-expressions:10.3.0" level="project" />
<orderEntry type="library" name="Maven: io.cucumber:datatable:3.5.0" level="project" />
<orderEntry type="library" name="Maven: io.cucumber:cucumber-plugin:6.10.3" level="project" />
<orderEntry type="library" name="Maven: io.cucumber:docstring:6.10.3" level="project" />
<orderEntry type="library" name="Maven: io.cucumber:html-formatter:13.0.0" level="project" />
<orderEntry type="library" name="Maven: io.cucumber:create-meta:4.0.0" level="project" />
<orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.1.1" level="project" />
<orderEntry type="library" name="Maven: io.cucumber:cucumber-junit:6.10.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven.plugins:maven-compiler-plugin:3.8.1" level="project" /> <orderEntry type="library" name="Maven: org.apache.maven.plugins:maven-compiler-plugin:3.8.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-plugin-api:3.0" level="project" /> <orderEntry type="library" name="Maven: org.apache.maven:maven-plugin-api:3.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.maven:maven-model:3.0" level="project" /> <orderEntry type="library" name="Maven: org.apache.maven:maven-model:3.0" level="project" />
@ -53,5 +60,25 @@
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-compiler-api:2.8.4" level="project" /> <orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-compiler-api:2.8.4" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-compiler-manager:2.8.4" level="project" /> <orderEntry type="library" name="Maven: org.codehaus.plexus:plexus-compiler-manager:2.8.4" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.codehaus.plexus:plexus-compiler-javac:2.8.4" level="project" /> <orderEntry type="library" scope="RUNTIME" name="Maven: org.codehaus.plexus:plexus-compiler-javac:2.8.4" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-java:3.141.59" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-api:3.141.59" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-chrome-driver:3.141.59" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-edge-driver:3.141.59" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-firefox-driver:3.141.59" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-ie-driver:3.141.59" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-opera-driver:3.141.59" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-remote-driver:3.141.59" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-safari-driver:3.141.59" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-support:3.141.59" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.8.15" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-exec:1.3" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:25.0-jre" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
<orderEntry type="library" name="Maven: org.checkerframework:checker-compat-qual:2.0.0" level="project" />
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.1.3" level="project" />
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.1" level="project" />
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.11.0" level="project" />
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
</component> </component>
</module> </module>

View File

@ -13,21 +13,30 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>io.cucumber</groupId> <groupId>junit</groupId>
<artifactId>cucumber-java</artifactId> <artifactId>junit</artifactId>
<version>2.3.1</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.10.3</version>
</dependency>
<dependency> <dependency>
<groupId>io.cucumber</groupId> <groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId> <artifactId>cucumber-junit</artifactId>
<version>2.3.1</version> <version>6.10.3</version>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
</dependency> </dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,6 +1,10 @@
import cucumber.api.CucumberOptions; import io.cucumber.junit.Cucumber;
import cucumber.api.junit.Cucumber; import io.cucumber.junit.CucumberOptions;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.openqa.selenium.firefox.FirefoxDriver;
import stepdefs.Preconditions;
@RunWith(Cucumber.class) @RunWith(Cucumber.class)
@CucumberOptions( @CucumberOptions(
@ -9,4 +13,13 @@ import org.junit.runner.RunWith;
) )
public class RunTest { public class RunTest {
@BeforeClass
public static void setup() {
Preconditions.driver= new FirefoxDriver();
}
@AfterClass
public static void teardown() {
Preconditions.driver.close();
}
} }

View File

@ -0,0 +1,7 @@
package stepdefs;
import org.openqa.selenium.WebDriver;
public class Preconditions {
public static WebDriver driver;
}

View File

@ -1,67 +1,68 @@
package stepdefs; package stepdefs;
import cucumber.api.java.en.Given; import io.cucumber.java.PendingException;
import cucumber.api.java.en.Then; import io.cucumber.java.en.Given;
import cucumber.api.java.en.When; import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
public class PriceAlarm { public class PriceAlarm {
@Given("^the user has at least (\\d+) price alarm set$") @Given("^the user has at least (\\d+) price alarm set$")
public void the_user_has_at_least_price_alarm_set(int arg1) throws Exception { public void the_user_has_at_least_price_alarm_set(int arg1) throws Exception {
} }
@When("^the user clicks on the profile icon$") @When("^the user clicks on the profile icon$")
public void the_user_clicks_on_the_profile_icon() throws Exception { public void the_user_clicks_on_the_profile_icon() throws Exception {
} }
@Then("^the profile details popup should open$") @Then("^the profile details popup should open$")
public void the_profile_details_popup_should_open() throws Exception { public void the_profile_details_popup_should_open() throws Exception {
} }
@When("^the user clicks on price alarms$") @When("^the user clicks on price alarms$")
public void the_user_clicks_on_price_alarms() throws Exception { public void the_user_clicks_on_price_alarms() throws Exception {
} }
@Then("^the price alarm list should open$") @Then("^the price alarm list should open$")
public void the_price_alarm_list_should_open() throws Exception { public void the_price_alarm_list_should_open() throws Exception {
} }
@Then("^the price alarm list should contain at least (\\d+) entry$") @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 { 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$") @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 { 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$") @Given("^the user is on the price alarm list page$")
public void the_user_is_on_the_price_alarm_list_page() throws Exception { 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$") @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 { 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$") @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 { 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$") @When("^the user confirms the removal of the price alarm$")
public void the_user_confirms_the_removal_of_the_price_alarm() throws Exception { public void the_user_confirms_the_removal_of_the_price_alarm() throws Exception {
} }
@Then("^the price alarm should be removed from the database$") @Then("^the price alarm should be removed from the database$")
public void the_price_alarm_should_be_removed_from_the_database() throws Exception { 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$") @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 { public void a_popup_should_open_where_the_user_can_edit_the_alarm() throws Exception {
} }
@When("^the user clicks on the \"([^\"]*)\" button$") @When("^the user clicks on the \"([^\"]*)\" button$")
public void the_user_clicks_on_the_button(String arg1) throws Exception { public void the_user_clicks_on_the_button(String arg1) throws Exception {
} }
@Then("^the price alarm should be updated in the database$") @Then("^the price alarm should be updated in the database$")
public void the_price_alarm_should_be_updated_in_the_database() throws Exception { public void the_price_alarm_should_be_updated_in_the_database() throws Exception {
} }
} }

View File

@ -1,52 +1,72 @@
package stepdefs; package stepdefs;
import cucumber.api.PendingException; import io.cucumber.java.PendingException;
import cucumber.api.java.en.Given; import io.cucumber.java.en.Given;
import cucumber.api.java.en.Then; import io.cucumber.java.en.Then;
import cucumber.api.java.en.When; 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 { public class SearchProduct {
@Given("^the user is on the landing page$") @Given("^the user is on the landing page$")
public void the_user_is_on_the_landing_page() throws Exception { 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$") @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 { 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 \"([^\"]*)\"$") @Then("^the user should see the error page \"([^\"]*)\"$")
public void the_user_should_see_the_error_page(String arg0) throws Exception { 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$") @Given("^the user is not logged in$")
public void the_user_is_not_logged_in() throws Exception { public void the_user_is_not_logged_in() throws Exception {
} }
@Given("^the user is logged in$") @Given("^the user is logged in$")
public void the_user_is_logged_in() throws Exception { public void the_user_is_logged_in() throws Exception {
} }
@Then("^the user should see a list of products$") @Then("^the user should see a list of products$")
public void the_user_should_see_a_list_of_products() throws Exception { 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$") @When("^the user clicks on the first product$")
public void the_user_clicks_on_the_first_product() throws Exception { public void the_user_clicks_on_the_first_product() throws Exception {
} }
@Then("^the user should see the product detail page$") @Then("^the user should see the product detail page$")
public void the_user_should_see_the_product_detail_page() throws Exception { public void the_user_should_see_the_product_detail_page() throws Exception {
} }
@Then("^the set price alarm box should show \"([^\"]*)\"$") @Then("^the set price alarm box should show \"([^\"]*)\"$")
public void the_set_price_alarm_box_should_show(String arg0) throws Exception { public void the_set_price_alarm_box_should_show(String arg0) throws Exception {
} }
@When("^the user sets a price alarm$") @When("^the user sets a price alarm$")
public void the_user_sets_a_price_alarm() throws Exception { public void the_user_sets_a_price_alarm() throws Exception {
} }
@Then("^the user should receive an email confirming the price alarm$") @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 { public void the_user_should_receive_an_email_confirming_the_price_alarm() throws Exception {
} }
} }

View File

@ -1,28 +1,28 @@
Feature: Price Alarms Feature: Price Alarms
Scenario: Show a list of price alarms Scenario: Show a list of price alarms
Given the user is on the landing page Given the user is on the landing page
And the user is logged in And the user is logged in
And the user has at least 1 price alarm set And the user has at least 1 price alarm set
When the user clicks on the profile icon When the user clicks on the profile icon
Then the profile details popup should open Then the profile details popup should open
When the user clicks on price alarms When the user clicks on price alarms
Then the price alarm list should open 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 at least 1 entry
And the price alarm list should contain a maximum of 20 entries per page And the price alarm list should contain a maximum of 20 entries per page
Scenario: Remove a price alarm Scenario: Remove a price alarm
Given the user is on the price alarm list page Given the user is on the price alarm list page
And the user is logged in And the user is logged in
When the user clicks on the "remove" button next to a price alarm 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 Then a popup should open asking the user to confirm the removal
When the user confirms the removal of the price alarm When the user confirms the removal of the price alarm
Then the price alarm should be removed from the database Then the price alarm should be removed from the database
Scenario: Edit a price alarm Scenario: Edit a price alarm
Given the user is on the price alarm list page Given the user is on the price alarm list page
And the user is logged in And the user is logged in
When the user clicks on the "edit" button next to a price alarm 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 Then a popup should open where the user can edit the alarm
When the user clicks on the "save changes" button When the user clicks on the "save changes" button
Then the price alarm should be updated in the database Then the price alarm should be updated in the database

View File

@ -1,26 +1,26 @@
Feature: Search a Product Feature: Search a Product
Scenario: User searches for unknown product Scenario: User searches for unknown product
Given the user is on the landing page Given the user is on the landing page
When the user enters the search term "iPhone 13" and clicks search When the user enters the search term "iPhone 13" and clicks search
Then the user should see the error page "No products found" Then the user should see the error page "No products found"
Scenario: User is not logged in, searches for known product Scenario: User is not logged in, searches for known product
Given the user is on the landing page Given the user is on the landing page
And the user is not logged in And the user is not logged in
When the user enters the search term "iPhone 12" and clicks search When the user enters the search term "iPhone 12" and clicks search
Then the user should see a list of products Then the user should see a list of products
When the user clicks on the first product When the user clicks on the first product
Then the user should see the product detail page Then the user should see the product detail page
And the set price alarm box should show "Log in to continue" And the set price alarm box should show "Log in to continue"
Scenario: User is logged in, searches for known product Scenario: User is logged in, searches for known product
Given the user is on the landing page Given the user is on the landing page
And the user is logged in And the user is logged in
When the user enters the search term "iPhone 12" and clicks search When the user enters the search term "iPhone 12" and clicks search
Then the user should see a list of products Then the user should see a list of products
When the user clicks on the first product When the user clicks on the first product
Then the user should see the product detail page Then the user should see the product detail page
And the set price alarm box should show "Set price alarm" And the set price alarm box should show "Set price alarm"
When the user sets a price alarm When the user sets a price alarm
Then the user should receive an email confirming the price alarm Then the user should receive an email confirming the price alarm