-
Notifications
You must be signed in to change notification settings - Fork 0
Added sample cucumber-testng project #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,46 @@ | ||
# browserstack-cucumber-testng-load-testing-sample | ||
Sample repository for cucumber-testng framework to do load testing. | ||
|
||
 | ||
|
||
## Getting Started | ||
|
||
### Run Sample Build | ||
|
||
1. **Clone the repository** | ||
|
||
```sh | ||
git clone [email protected]:browserstack/browserstack-cucumber-testng-load-testing-sample.git | ||
``` | ||
|
||
2. **Install BrowserStack CLI** | ||
|
||
Download the appropriate BrowserStack CLI binary based on your operating system: | ||
|
||
- **macOS x86** | ||
[browserstack-cli-macOS-x86](https://load-api.browserstack.com/api/v1/binary?os=macos&arch=x64) | ||
|
||
- **macOS ARM** | ||
[browserstack-cli-macOS-arm](https://load-api.browserstack.com/api/v1/binary?os=macos&arch=arm64) | ||
|
||
- **Windows x86** | ||
[browserstack-cli-windows](https://load-api.browserstack.com/api/v1/binary?os=win&arch=x64) | ||
|
||
- **Linux x86** | ||
[browserstack-cli-linux-x86](https://load-api.browserstack.com/api/v1/binary?os=linux&arch=x64) | ||
|
||
- **Linux ARM** | ||
[browserstack-cli-linux-arm](https://load-api.browserstack.com/api/v1/binary?os=linux&arch=arm64) | ||
|
||
> Place the downloaded `browserstack-cli` binary in the root of your project. | ||
4. **Run tests using BrowserStack CLI** | ||
|
||
```sh | ||
./browserstack-cli load run | ||
``` | ||
|
||
5. **View Test Results** | ||
|
||
Visit the [BrowserStack Load-Testing Dashboard](https://load.browserstack.com/projects) to monitor and analyze your test runs. | ||
|
||
--- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# ============================= | ||
# Set BrowserStack Credentials | ||
# ============================= | ||
# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY as env variables. | ||
userName: BROWSERSTACK_USERNAME | ||
accessKey: BROWSERSTACK_ACCESS_KEY | ||
|
||
# ====================== | ||
# BrowserStack Reporting | ||
# ====================== | ||
# The following parameters are used to set up reporting on BrowserStack Load Testing: | ||
# Set 'projectName' to the name of your project. Example: 'Product ABC'. Tests under the same projectName will be grouped together. | ||
projectName: Default Project | ||
|
||
# Set 'testName' to the name of your test. Example: 'First Load Test'. Test runs with the same testName will be grouped together. | ||
testName: Default Test | ||
|
||
# ====================== | ||
# Set Load Configuration | ||
# ====================== | ||
# The following parameters are used to set load configuration for your test: | ||
# Set 'testType' to the type of load test that you want to execute. Example:'Playwright', 'Selenium'. This is a required parameter. | ||
testType: Selenium | ||
|
||
# Set 'vus' to the maximum number of virtual users to simulate during the test. | ||
vus: 5 | ||
|
||
# Set 'duration' to the total duration of the entire test, in minutes and seconds. The test will run infinite iterations until the duration is met. Example: '2m', '3m 40s'. This is not a required parameter. | ||
duration: 5m | ||
|
||
# Set multiple regions from which you would want to generate the load (percent should total 100 across all loadzones). | ||
regions: | ||
- loadzone: us-east-1 | ||
percent: 100 | ||
|
||
# Set language to the programming language used in your project. Example: 'java', 'nodejs'. | ||
language: java | ||
|
||
# Set framework to the test framework used in your Selenium project. Example: 'testng'. | ||
framework: cucumber-testng | ||
|
||
# Add list of file paths under 'dependencies' to help set up the test environment by installing required packages. Example: path to 'pom.xml' for Java projects using Maven, path to 'package.json' for Node.js projects. | ||
# Add list of file paths under 'testConfigs' to define which configuration files should be used to run tests. Example: path to 'playwright.config.ts' for Playwright (Node.js), path to 'testng.xml' for Selenium (TestNG). | ||
files: | ||
dependencies: | ||
- ./pom.xml | ||
testConfigs: | ||
- src/test/java/runners/TestRunner.java |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.example</groupId> | ||
<artifactId>cucumber-testng-sample</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<name>Cucumber TestNG Selenium Sample</name> | ||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-java</artifactId> | ||
<version>4.20.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.cucumber</groupId> | ||
<artifactId>cucumber-java</artifactId> | ||
<version>7.16.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.cucumber</groupId> | ||
<artifactId>cucumber-testng</artifactId> | ||
<version>7.16.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<version>7.10.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>3.2.5</version> | ||
<configuration> | ||
<includes> | ||
<include>**/TestRunner.java</include> | ||
</includes> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Feature: Add product to cart on bstack demo | ||
As a user of the bstack demo site | ||
I want to add a product to the cart | ||
So that I can verify the product appears correctly | ||
|
||
Scenario: Add first product to cart | ||
Given I open the bstack demo homepage | ||
Then the bstack demo title should be "StackDemo" | ||
When I note the name of the first product | ||
And I add the first product to the cart | ||
Then the mini cart should be displayed | ||
And the product name in the cart should match noted name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package runners; | ||
|
||
import io.cucumber.testng.AbstractTestNGCucumberTests; | ||
import io.cucumber.testng.CucumberOptions; | ||
|
||
@CucumberOptions( | ||
features = "src/test/java/features/BStackDemo.feature", | ||
glue = {"stepdefinitions"}, | ||
plugin = {"pretty", "html:target/cucumber-reports.html"} | ||
) | ||
public class TestRunner extends AbstractTestNGCucumberTests { | ||
} |
73 changes: 73 additions & 0 deletions
73
src/test/java/stepdefinitions/bstack_test_add_to_cart.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package stepdefinitions; | ||
|
||
import io.cucumber.java.After; | ||
import io.cucumber.java.en.And; | ||
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.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.chrome.ChromeDriver; | ||
import org.openqa.selenium.remote.DesiredCapabilities; | ||
import org.openqa.selenium.remote.RemoteWebDriver; | ||
import org.testng.Assert; | ||
|
||
import java.net.URL; | ||
import java.time.Duration; | ||
|
||
public class bstack_test_add_to_cart { | ||
|
||
private RemoteWebDriver driver; | ||
private String notedProductName; | ||
|
||
@Given("I open the bstack demo homepage") | ||
public void i_open_the_bstack_demo_homepage() throws Exception { | ||
DesiredCapabilities caps = new DesiredCapabilities(); | ||
caps.setBrowserName("chrome"); | ||
|
||
// Set the BrowserStack HUB URL | ||
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), caps); | ||
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); | ||
driver.get("https://www.bstackdemo.com"); | ||
} | ||
|
||
@Then("the bstack demo title should be {string}") | ||
public void the_bstack_demo_title_should_be(String expected) { | ||
Assert.assertTrue(driver.getTitle().contains(expected), "Expected title to contain: " + expected + " but was: " + driver.getTitle()); | ||
} | ||
|
||
@When("I note the name of the first product") | ||
public void i_note_the_name_of_the_first_product() { | ||
WebElement nameEl = driver.findElement(By.xpath("//*[@id='1']/p")); | ||
notedProductName = nameEl.getText(); | ||
Assert.assertNotNull(notedProductName, "Product name should not be null"); | ||
} | ||
|
||
@And("I add the first product to the cart") | ||
public void i_add_the_first_product_to_the_cart() { | ||
driver.findElement(By.xpath("//*[@id='1']/div[4]")) | ||
rohit-Bstack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.click(); | ||
} | ||
|
||
@Then("the mini cart should be displayed") | ||
public void the_mini_cart_should_be_displayed() { | ||
WebElement cart = driver.findElement(By.cssSelector(".float\\-cart__content")); | ||
Assert.assertTrue(cart.isDisplayed(), "Mini cart not displayed"); | ||
} | ||
|
||
@And("the product name in the cart should match noted name") | ||
public void the_product_name_in_the_cart_should_match_noted_name() { | ||
WebElement nameInCart = driver.findElement(By.xpath("//*[@id='__next']/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]")); | ||
rohit-Bstack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
String cartName = nameInCart.getText(); | ||
Assert.assertEquals(cartName, notedProductName, "Product names differ between main page and cart"); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
if (driver != null) { | ||
try { driver.quit(); } catch (Exception ignored) {} | ||
driver = null; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.