BDD-JSON based Cucumber report
Using the terminal, you can create BDD-JSON based reports from Cucumber and upload them to Test Management.
Executing a Test Case with Cucumber
You can initiate an example Cucumber project with this sample code to execute a Test Case.
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
Given("I visit bstackdemo website") do
driver.navigate.to 'https://www.bstackdemo.com/'
#sleep(5)
end
When("I click on orders") do
driver.manage.window.maximize
driver.find_element(:id, 'orders').click
end
Then("I should see signin page") do
sleep(1)
logintext = driver.find_element(:id, 'login-btn').text
expect(logintext).to eq('LOG IN')
puts(logintext)
end
Given('I visit wikipedia') do
driver.navigate.to 'https://www.wikipedia.org/'
end
When('I search for BrowserStack') do
driver.find_element(:id, 'searchInput').send_keys('BrowserStack')
sleep(10)
end
Then('I should see BrowserStack page') do
result = driver.find_element(:class, 'suggestion-title').text
#header = driver.find_element(:id, 'first_heading').text
expect(result).to eq('BrowserStack')
end
Create BDD-JSON test report with Cucumber
Cucumber by default generates a BDD-JSON based report. Run the following command to execute test run and generate BDD-JSON report.
$ cucumber --format json --out results/test-results.json
Sample BDD-JSON report generated from Cucumber.
[
{
"id": "browserstack-test",
"uri": "features/sample.feature",
"keyword": "Feature",
"name": "Browserstack test",
"description": "",
"line": 1,
"elements": [
{
"id": "browserstack-test;can-add-the-product-in-cart",
"keyword": "Scenario",
"name": "Can add the product in cart",
"description": "",
"line": 3,
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "I visit bstackdemo website",
"line": 4,
"match": {
"location": "features/step_definitions/sample_steps.rb:4"
},
"result": {
"status": "passed",
"duration": 4600928000
}
},
{
"keyword": "When ",
"name": "I click on orders",
"line": 5,
"match": {
"location": "features/step_definitions/sample_steps.rb:9"
},
"result": {
"status": "passed",
"duration": 518495000
}
},
{
"keyword": "Then ",
"name": "I should see signin page",
"line": 6,
"match": {
"location": "features/step_definitions/sample_steps.rb:14"
},
"result": {
"status": "passed",
"duration": 1031290000
}
}
]
},
{
"id": "browserstack-test;search-wikipedia",
"keyword": "Scenario",
"name": "Search Wikipedia",
"description": "",
"line": 8,
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "I visit wikipedia",
"line": 9,
"match": {
"location": "features/step_definitions/sample_steps.rb:21"
},
"result": {
"status": "passed",
"duration": 666769000
}
},
{
"keyword": "When ",
"name": "I search for BrowserStack",
"line": 10,
"match": {
"location": "features/step_definitions/sample_steps.rb:25"
},
"result": {
"status": "passed",
"duration": 10150496000
}
},
{
"keyword": "Then ",
"name": "I should see BrowserStack page",
"line": 11,
"match": {
"location": "features/step_definitions/sample_steps.rb:30"
},
"result": {
"status": "passed",
"duration": 33933000
}
}
]
}
]
}
]
Steps to upload BDD-JSON test report
Open the project directory in the Terminal and load the variables.
export TEST_MANAGEMENT_API_TOKEN="*************28a42"
export TEST_MANAGEMENT_PROJECT_NAME="<Project Name>"
export BDD_JSON_FILE_PATH="<Report Path>"
export TEST_RUN_NAME="<Test Run Name"
TEST_MANAGEMENT_API_TOKEN
from the Active API Key section in the Settings of BrowserStack Test Management.
Upload the BDD-JSON test report using curl
command.
curl -k -X POST https://test-management.browserstack.com/api/v1/import/results/json/bdd \
-u $TEST_MANAGEMENT_API_TOKEN \
-F project_name="$TEST_MANAGEMENT_PROJECT_NAME" \
-F "file_path=@$BDD_JSON_FILE_PATH" \
-F test_run_name="$TEST_RUN_NAME"
cURL
command until you get the response back.
You can also upload BDD-JSON test report with Cucumber using CI/CD.
Access the test run report from the console generated URL
After your report is successfully uploaded, you see a message similar to the following in your terminal. This message also generates a URL with "url"
parameter that you can use to access your automated test run.
{"message":"File uploaded successfully.","url":"https://test-management.browserstack.com/projects/<project id>/test-runs/<test run id>","success":true}
View test run report in Test Management
- Log in to the BrowserStack Test Management dashboard.
- Select the relevant project that has the test report uploaded.
- Click Test Runs.
- Open the Test Run generated from automation test exectution.
- You will find all the test cases with their respective results here.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!