From f34f9da1455f4df221724197d9b796f9d4cf141a Mon Sep 17 00:00:00 2001 From: Abhi Singh Date: Mon, 14 Mar 2022 17:46:24 +0530 Subject: [PATCH 1/8] adds selenium 4 capabilities --- pom.xml | 2 +- .../com/browserstack/stepdefs/SearchSteps.java | 14 +++++++++++--- src/test/java/com/browserstack/util/Utility.java | 12 ++++++++---- src/test/resources/conf/local.conf.json | 10 ++++++---- src/test/resources/conf/parallel.conf.json | 14 ++++++++------ src/test/resources/conf/single.conf.json | 8 +++++--- 6 files changed, 39 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 37a685e..b37da18 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ 1.8 1.8 6.9.1 - 3.141.59 + 4.1.2 1.0.6 1.1.1 1.7.30 diff --git a/src/test/java/com/browserstack/stepdefs/SearchSteps.java b/src/test/java/com/browserstack/stepdefs/SearchSteps.java index acce60e..76b12c3 100644 --- a/src/test/java/com/browserstack/stepdefs/SearchSteps.java +++ b/src/test/java/com/browserstack/stepdefs/SearchSteps.java @@ -14,6 +14,8 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.net.URL; import java.util.HashMap; @@ -26,6 +28,7 @@ public class SearchSteps { private WebDriver driver; private SearchPage searchPage; private Local l; + private final Logger LOG = LoggerFactory.getLogger(SearchSteps.class); @Before public void setUp(Scenario scenario) throws Exception { @@ -34,10 +37,12 @@ public void setUp(Scenario scenario) throws Exception { DesiredCapabilities caps = new DesiredCapabilities(capability); caps.setCapability("name", scenario.getName()); - if (caps.getCapability("browserstack.local")!=null && caps.getCapability("browserstack.local").toString().equals("true")) { + Map bstackOptions = (Map) caps.getCapability("bstack:options"); + if (bstackOptions!=null && bstackOptions.get("local")!=null && bstackOptions.get("local").toString().equals("true")) { + LOG.info("Start BrowserStack Local"); l = new Local(); Map options = new HashMap(); - options.put("key", caps.getCapability("browserstack.key").toString()); + options.put("key", bstackOptions.get("accessKey").toString()); l.start(options); } @@ -77,6 +82,9 @@ public void teardown(Scenario scenario) throws Exception { } Thread.sleep(2000); driver.quit(); - if (l != null) l.stop(); + if (l != null) { + l.stop(); + LOG.info("Stop BrowserStack Local"); + } } } \ No newline at end of file diff --git a/src/test/java/com/browserstack/util/Utility.java b/src/test/java/com/browserstack/util/Utility.java index 1f30bd1..af92e60 100644 --- a/src/test/java/com/browserstack/util/Utility.java +++ b/src/test/java/com/browserstack/util/Utility.java @@ -15,13 +15,13 @@ public static JSONObject getCombinedCapability(Map envCapabiliti Iterator it = envCapabilities.entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); - capabilities.put(pair.getKey().toString(), pair.getValue().toString()); + capabilities.put(pair.getKey().toString(), pair.getValue()); } it = commonCapabilities.entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); if (capabilities.get(pair.getKey().toString()) == null) { - capabilities.put(pair.getKey().toString(), pair.getValue().toString()); + capabilities.put(pair.getKey().toString(), pair.getValue()); } } String username = System.getenv("BROWSERSTACK_USERNAME"); @@ -33,8 +33,12 @@ public static JSONObject getCombinedCapability(Map envCapabiliti if(accessKey == null) { accessKey = (String) config.get("key"); } - capabilities.put("browserstack.user", username); - capabilities.put("browserstack.key", accessKey); + JSONObject bstackOptions = (JSONObject) capabilities.get("bstack:options"); + if(bstackOptions == null) + bstackOptions = new JSONObject(); + bstackOptions.put("userName", username); + bstackOptions.put("accessKey", accessKey); + capabilities.put("bstack:options", bstackOptions); return capabilities; } diff --git a/src/test/resources/conf/local.conf.json b/src/test/resources/conf/local.conf.json index 306fa86..5b1f6d4 100644 --- a/src/test/resources/conf/local.conf.json +++ b/src/test/resources/conf/local.conf.json @@ -4,12 +4,14 @@ "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "build": "cucumber-java-browserstack", - "browserstack.debug": true, - "browserstack.local": true + "bstack:options" : { + "buildName" : "cucumber-java-browserstack", + "local" : "true", + "debug" : "true" + } }, "environments": [{ - "browser": "chrome" + "browserName": "chrome" }] } diff --git a/src/test/resources/conf/parallel.conf.json b/src/test/resources/conf/parallel.conf.json index 67d5177..8be305b 100644 --- a/src/test/resources/conf/parallel.conf.json +++ b/src/test/resources/conf/parallel.conf.json @@ -4,22 +4,24 @@ "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "build": "cucumber-java-browserstack", - "browserstack.debug": true + "bstack:options" : { + "buildName" : "cucumber-java-browserstack", + "debug" : "true" + } }, "environments": [ { - "browser": "chrome" + "browserName": "chrome" }, { - "browser": "firefox" + "browserName": "firefox" }, { - "browser": "safari" + "browserName": "safari" }, { - "browser": "Internet Explorer" + "browserName": "IE" } ] } diff --git a/src/test/resources/conf/single.conf.json b/src/test/resources/conf/single.conf.json index 0f2dc7a..62547a1 100644 --- a/src/test/resources/conf/single.conf.json +++ b/src/test/resources/conf/single.conf.json @@ -4,11 +4,13 @@ "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "build": "cucumber-java-browserstack", - "browserstack.debug": true + "bstack:options" : { + "buildName" : "cucumber-java-browserstack", + "debug" : "true" + } }, "environments": [{ - "browser": "chrome" + "browserName": "chrome" }] } From 15a7fd4731477bbfcbe219d07b2426b6c485234d Mon Sep 17 00:00:00 2001 From: Abhi Singh Date: Tue, 15 Mar 2022 16:15:40 +0530 Subject: [PATCH 2/8] adds EoF --- src/test/java/com/browserstack/stepdefs/SearchSteps.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/browserstack/stepdefs/SearchSteps.java b/src/test/java/com/browserstack/stepdefs/SearchSteps.java index 76b12c3..34fbd88 100644 --- a/src/test/java/com/browserstack/stepdefs/SearchSteps.java +++ b/src/test/java/com/browserstack/stepdefs/SearchSteps.java @@ -87,4 +87,4 @@ public void teardown(Scenario scenario) throws Exception { LOG.info("Stop BrowserStack Local"); } } -} \ No newline at end of file +} From fdfcc46d195fe55309be6c9c696a61e93eb10a46 Mon Sep 17 00:00:00 2001 From: Abhi Singh Date: Tue, 15 Mar 2022 16:16:11 +0530 Subject: [PATCH 3/8] fixes JSON formatting --- src/test/resources/conf/local.conf.json | 8 ++++---- src/test/resources/conf/parallel.conf.json | 6 +++--- src/test/resources/conf/single.conf.json | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/resources/conf/local.conf.json b/src/test/resources/conf/local.conf.json index 5b1f6d4..6703b3a 100644 --- a/src/test/resources/conf/local.conf.json +++ b/src/test/resources/conf/local.conf.json @@ -4,10 +4,10 @@ "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "bstack:options" : { - "buildName" : "cucumber-java-browserstack", - "local" : "true", - "debug" : "true" + "bstack:options": { + "buildName": "cucumber-java-browserstack", + "local": "true", + "debug": "true" } }, diff --git a/src/test/resources/conf/parallel.conf.json b/src/test/resources/conf/parallel.conf.json index 8be305b..3a15cff 100644 --- a/src/test/resources/conf/parallel.conf.json +++ b/src/test/resources/conf/parallel.conf.json @@ -4,9 +4,9 @@ "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "bstack:options" : { - "buildName" : "cucumber-java-browserstack", - "debug" : "true" + "bstack:options": { + "buildName": "cucumber-java-browserstack", + "debug": "true" } }, diff --git a/src/test/resources/conf/single.conf.json b/src/test/resources/conf/single.conf.json index 62547a1..ee140d3 100644 --- a/src/test/resources/conf/single.conf.json +++ b/src/test/resources/conf/single.conf.json @@ -4,9 +4,9 @@ "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "bstack:options" : { - "buildName" : "cucumber-java-browserstack", - "debug" : "true" + "bstack:options": { + "buildName": "cucumber-java-browserstack", + "debug": "true" } }, From 4cf6bef004d7ea9cc291d2ad0837858286030e44 Mon Sep 17 00:00:00 2001 From: Abhi Singh Date: Wed, 30 Mar 2022 22:50:39 +0530 Subject: [PATCH 4/8] added BstackDemo test --- .../browserstack/pageobjects/HomePage.java | 52 +++++++++++++++++++ .../browserstack/pageobjects/SearchPage.java | 23 -------- .../{SearchSteps.java => StackDemoSteps.java} | 32 ++++++------ .../resources/features/test/Search.feature | 6 --- .../resources/features/test/StackDemo.feature | 6 +++ 5 files changed, 73 insertions(+), 46 deletions(-) create mode 100644 src/test/java/com/browserstack/pageobjects/HomePage.java delete mode 100644 src/test/java/com/browserstack/pageobjects/SearchPage.java rename src/test/java/com/browserstack/stepdefs/{SearchSteps.java => StackDemoSteps.java} (75%) delete mode 100644 src/test/resources/features/test/Search.feature create mode 100644 src/test/resources/features/test/StackDemo.feature diff --git a/src/test/java/com/browserstack/pageobjects/HomePage.java b/src/test/java/com/browserstack/pageobjects/HomePage.java new file mode 100644 index 0000000..33dfd00 --- /dev/null +++ b/src/test/java/com/browserstack/pageobjects/HomePage.java @@ -0,0 +1,52 @@ +package com.browserstack.pageobjects; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.time.Duration; + +public class HomePage { + private WebDriver webDriver; + + private String selectedProductName; + + public HomePage(WebDriver webDriver) { + this.webDriver = webDriver; + this.selectedProductName = ""; + } + + private By firstProductName = By.xpath("//*[@id=\"1\"]/p"); + + private By firstProductAddToCartButton = By.xpath("//*[@id=\"1\"]/div[4]"); + + private By cartPane = By.cssSelector(".float-cart__content"); + + private By productCartText = By.xpath("//*[@id=\"__next\"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]"); + + public void selectFirstProductName() { + String firstProduct = webDriver.findElement(firstProductName).getText(); + setSelectedProductName(firstProduct); + } + + public void clickAddToCartButton() { + webDriver.findElement(firstProductAddToCartButton).click(); + } + + public void waitForCartToOpen() { + new WebDriverWait(webDriver, Duration.ofSeconds(30)).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(cartPane)); + } + + public String getProductCartText() { + return webDriver.findElement(productCartText).getText(); + } + + public void setSelectedProductName(String selectedProductName) { + this.selectedProductName = selectedProductName; + } + + public String getSelectedProductName() { + return selectedProductName; + } +} diff --git a/src/test/java/com/browserstack/pageobjects/SearchPage.java b/src/test/java/com/browserstack/pageobjects/SearchPage.java deleted file mode 100644 index e7cb592..0000000 --- a/src/test/java/com/browserstack/pageobjects/SearchPage.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.browserstack.pageobjects; - -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; - -public class SearchPage { - private WebDriver webDriver; - - public SearchPage(WebDriver webDriver) { - this.webDriver = webDriver; - } - - private By searchTermField = By.name("q"); - - public void enterSearchTerm(String searchTerm) { - webDriver.findElement(searchTermField).sendKeys(searchTerm); - } - - public void submitSearch() { - webDriver.findElement(searchTermField).submit(); - } - -} diff --git a/src/test/java/com/browserstack/stepdefs/SearchSteps.java b/src/test/java/com/browserstack/stepdefs/StackDemoSteps.java similarity index 75% rename from src/test/java/com/browserstack/stepdefs/SearchSteps.java rename to src/test/java/com/browserstack/stepdefs/StackDemoSteps.java index 34fbd88..4cb50be 100644 --- a/src/test/java/com/browserstack/stepdefs/SearchSteps.java +++ b/src/test/java/com/browserstack/stepdefs/StackDemoSteps.java @@ -2,7 +2,7 @@ import com.browserstack.TestRunner; import com.browserstack.local.Local; -import com.browserstack.pageobjects.SearchPage; +import com.browserstack.pageobjects.HomePage; import com.browserstack.util.Utility; import io.cucumber.java.After; import io.cucumber.java.Before; @@ -24,11 +24,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -public class SearchSteps { +public class StackDemoSteps { private WebDriver driver; - private SearchPage searchPage; + private HomePage homePage; private Local l; - private final Logger LOG = LoggerFactory.getLogger(SearchSteps.class); + private final Logger LOG = LoggerFactory.getLogger(StackDemoSteps.class); @Before public void setUp(Scenario scenario) throws Exception { @@ -47,7 +47,7 @@ public void setUp(Scenario scenario) throws Exception { } driver = new RemoteWebDriver(new URL(URL), caps); - searchPage = new SearchPage(driver); + homePage = new HomePage(driver); } @Given("^I am on the website '(.+)'$") @@ -56,20 +56,21 @@ public void I_am_on_the_website(String url) throws Throwable { Thread.sleep(2000); } - @When("^I submit the search term '(.+)'$") - public void I_submit_the_search_term(String searchTerm) throws Throwable { - searchPage.enterSearchTerm(searchTerm); - searchPage.submitSearch(); + @When("^I select a product and click on 'Add to cart' button") + public void I_select_a_product_and_add_to_cart() throws Throwable { + homePage.selectFirstProductName(); + homePage.clickAddToCartButton(); Thread.sleep(2000); } - @Then("the page title should be '(.+)'$") - public void I_should_see_pagetitle(String expectedTitle) throws Throwable { - assertEquals(expectedTitle, driver.getTitle()); + @Then("the product should be added to cart") + public void product_should_be_added_to_cart() { + homePage.waitForCartToOpen(); + assertEquals(homePage.getSelectedProductName(), homePage.getProductCartText()); } @Then("the page should contain '(.+)'$") - public void page_should_contain(String expectedTitle) throws Throwable { + public void page_should_contain(String expectedTitle) { assertTrue(driver.getPageSource().contains(expectedTitle)); } @@ -82,9 +83,6 @@ public void teardown(Scenario scenario) throws Exception { } Thread.sleep(2000); driver.quit(); - if (l != null) { - l.stop(); - LOG.info("Stop BrowserStack Local"); - } + if (l != null) l.stop(); } } diff --git a/src/test/resources/features/test/Search.feature b/src/test/resources/features/test/Search.feature deleted file mode 100644 index 48e0bac..0000000 --- a/src/test/resources/features/test/Search.feature +++ /dev/null @@ -1,6 +0,0 @@ -Feature: Automatically correct mistyped search terms - - Scenario: Enter search term and get page title - Given I am on the website 'http://www.google.com' - When I submit the search term 'BrowserStack' - Then the page title should be 'BrowserStack - Google Search' \ No newline at end of file diff --git a/src/test/resources/features/test/StackDemo.feature b/src/test/resources/features/test/StackDemo.feature new file mode 100644 index 0000000..9e3a2e5 --- /dev/null +++ b/src/test/resources/features/test/StackDemo.feature @@ -0,0 +1,6 @@ +Feature: BrowserStack Demo + + Scenario: Add product to cart + Given I am on the website 'https://www.bstackdemo.com' + When I select a product and click on 'Add to cart' button + Then the product should be added to cart From c514e39c299f26906eaf452546e3f4952aed9236 Mon Sep 17 00:00:00 2001 From: Abhi Singh Date: Thu, 31 Mar 2022 16:37:53 +0530 Subject: [PATCH 5/8] removed IE browser --- pom.xml | 2 +- src/test/resources/conf/parallel.conf.json | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index b37da18..07ee094 100644 --- a/pom.xml +++ b/pom.xml @@ -144,7 +144,7 @@ parallel-count - 5 + 3 features diff --git a/src/test/resources/conf/parallel.conf.json b/src/test/resources/conf/parallel.conf.json index 3a15cff..6590da0 100644 --- a/src/test/resources/conf/parallel.conf.json +++ b/src/test/resources/conf/parallel.conf.json @@ -19,9 +19,6 @@ }, { "browserName": "safari" - }, - { - "browserName": "IE" } ] } From 63b5a26ac3d9a490b60e78a2e7b1235bbe57fb09 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Wed, 21 Jun 2023 14:01:55 +0530 Subject: [PATCH 6/8] Added BStack to scenerio --- src/test/resources/features/localtest/Local.feature | 2 +- src/test/resources/features/test/StackDemo.feature | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/resources/features/localtest/Local.feature b/src/test/resources/features/localtest/Local.feature index 8d1601f..6c65e4e 100644 --- a/src/test/resources/features/localtest/Local.feature +++ b/src/test/resources/features/localtest/Local.feature @@ -1,5 +1,5 @@ Feature: Verify Local test - Scenario: Navigate to Local check page + Scenario: BStack Local Test: Navigate to Local check page Given I am on the website 'http://bs-local.com:45691/check' Then the page should contain 'Up and running' \ No newline at end of file diff --git a/src/test/resources/features/test/StackDemo.feature b/src/test/resources/features/test/StackDemo.feature index 9e3a2e5..be84742 100644 --- a/src/test/resources/features/test/StackDemo.feature +++ b/src/test/resources/features/test/StackDemo.feature @@ -1,6 +1,6 @@ Feature: BrowserStack Demo - Scenario: Add product to cart + Scenario: BStack Sample Test: Add product to cart Given I am on the website 'https://www.bstackdemo.com' When I select a product and click on 'Add to cart' button Then the product should be added to cart From 0b1b5cc5433958add220cccf6fdfdd5c2fd1d0ae Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Wed, 21 Jun 2023 14:10:11 +0530 Subject: [PATCH 7/8] Added newline --- src/test/resources/features/localtest/Local.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/features/localtest/Local.feature b/src/test/resources/features/localtest/Local.feature index 6c65e4e..ce1381b 100644 --- a/src/test/resources/features/localtest/Local.feature +++ b/src/test/resources/features/localtest/Local.feature @@ -2,4 +2,4 @@ Feature: Verify Local test Scenario: BStack Local Test: Navigate to Local check page Given I am on the website 'http://bs-local.com:45691/check' - Then the page should contain 'Up and running' \ No newline at end of file + Then the page should contain 'Up and running' From ad1054844ccc809d5074c2280db909b2e795d157 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Fri, 23 Jun 2023 17:25:30 +0530 Subject: [PATCH 8/8] fixed syntax in feature file --- src/test/resources/features/localtest/Local.feature | 2 +- src/test/resources/features/test/StackDemo.feature | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/resources/features/localtest/Local.feature b/src/test/resources/features/localtest/Local.feature index ce1381b..1e3d812 100644 --- a/src/test/resources/features/localtest/Local.feature +++ b/src/test/resources/features/localtest/Local.feature @@ -1,5 +1,5 @@ Feature: Verify Local test - Scenario: BStack Local Test: Navigate to Local check page + Scenario: BStack Local Test - Navigate to Local check page Given I am on the website 'http://bs-local.com:45691/check' Then the page should contain 'Up and running' diff --git a/src/test/resources/features/test/StackDemo.feature b/src/test/resources/features/test/StackDemo.feature index be84742..f0df316 100644 --- a/src/test/resources/features/test/StackDemo.feature +++ b/src/test/resources/features/test/StackDemo.feature @@ -1,6 +1,6 @@ Feature: BrowserStack Demo - Scenario: BStack Sample Test: Add product to cart + Scenario: BStack Sample Test - Add product to cart Given I am on the website 'https://www.bstackdemo.com' When I select a product and click on 'Add to cart' button Then the product should be added to cart