Skip to content

Commit 44919a0

Browse files
Adding sample script for cucumber-js with sdk
1 parent d68a1cd commit 44919a0

24 files changed

+14878
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
local.log
3+
screenshots
4+
log/
5+
browserstack.err
6+
**/.DS_Store
7+
.vscode/
8+
.env

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,68 @@
11
# cucumber-js-appium-app-browserstack
2+
3+
This repository demonstrates how to run Appium Cucumber JS tests on BrowserStack App Automate.
4+
5+
## Setup
6+
7+
### Requirements
8+
9+
1. Node.js
10+
11+
- If not installed, install Node.js from [here](https://nodejs.org/en/download/)
12+
13+
- Ensure you have node & npm installed by running `node -v` & `npm -v`
14+
15+
### Install the dependencies
16+
17+
For Android tests, run the following command in project's base directory :
18+
19+
```
20+
cd android
21+
npm install
22+
```
23+
Or,
24+
25+
For dependencies for iOS tests, run following command in project's base directory :
26+
```
27+
cd ios
28+
npm install
29+
```
30+
## Getting Started
31+
32+
Getting Started with Appium tests in NodeJS mocha on BrowserStack couldn't be easier!
33+
34+
### Run your first test :
35+
36+
Open `Android` or in `ios` folder
37+
38+
- If you have uploaded your app then add the app id to the `browserstack.yml` config file, or you can directly specify the path to your app in the `browserstack.yml` file.
39+
40+
- Run `npm run sample-test`
41+
42+
- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard)
43+
44+
---
45+
46+
### **Use Local testing for apps that access resources hosted in development or testing environments :**
47+
48+
Open `Android` or in `ios` folder
49+
50+
- Ensure that `browserstackLocal` capability is set to `true` in the `browserstack.yml` file.
51+
52+
- If you have uploaded your app then add the app id to the `browserstack.yml` config file, or you can directly specify the path to your app in the `browserstack.yml` file.
53+
54+
- Run `npm run sample-local-test`
55+
56+
- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard)
57+
58+
## Integration with other NodeJS frameworks
59+
60+
For other NodeJS frameworks samples, refer to following repositories :
61+
62+
- [WebdriverIO](https://github.com/browserstack/webdriverio-appium-app-browserstack)
63+
64+
Note: For other test frameworks supported by App-Automate refer our [Developer documentation](https://www.browserstack.com/docs/)
65+
66+
## Getting Help
67+
68+
If you are running into any issues or have any queries, please check [Browserstack Support page](https://www.browserstack.com/support/app-automate) or [get in touch with us](https://www.browserstack.com/contact?ref=help).

android/LocalSample.apk

3.84 MB
Binary file not shown.

android/WikipediaSample.apk

19.4 MB
Binary file not shown.

android/browserstack.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# =============================
2+
# Set BrowserStack Credentials
3+
# =============================
4+
# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and
5+
# BROWSERSTACK_ACCESS_KEY as env variables
6+
userName: BROWSERSTACK_USERNAME
7+
accessKey: BROWSERSTACK_ACCESS_KEY
8+
9+
# ======================
10+
# BrowserStack Reporting
11+
# ======================
12+
# The following capabilities are used to set up reporting on BrowserStack:
13+
# Set 'projectName' to the name of your project. Example, Marketing Website
14+
projectName: BrowserStack Samples
15+
# Set `buildName` as the name of the job / testsuite being run
16+
buildName: browserstack build
17+
# `buildIdentifier` is a unique id to differentiate every execution that gets appended to
18+
# buildName. Choose your buildIdentifier format from the available expressions:
19+
# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution
20+
# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30
21+
# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests
22+
buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression}
23+
24+
source: cucumber-js:appium-sample-master:v1.0
25+
26+
# Set `app` to define the app that is to be used for testing.
27+
# It can either take the id of any uploaded app or the path of the app directly.
28+
app: ./WikipediaSample.apk
29+
# app: ./LocalSample.apk #For running local tests
30+
31+
# =======================================
32+
# Platforms (Browsers / Devices to test)
33+
# =======================================
34+
# Platforms object contains all the browser / device combinations you want to test on.
35+
# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)
36+
37+
platforms:
38+
- deviceName: Samsung Galaxy S22 Ultra
39+
osVersion: 12.0
40+
platformName: android
41+
- deviceName: OnePlus 11R
42+
osVersion: 13.0
43+
platformName: android
44+
- deviceName: Google Pixel 6 Pro
45+
osVersion: 12.0
46+
platformName: android
47+
48+
# ==========================================
49+
# BrowserStack Local
50+
# (For localhost, staging/private websites)
51+
# ==========================================
52+
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
53+
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
54+
browserstackLocal: true # <boolean> (Default false)
55+
#browserStackLocalOptions:
56+
#Options to be passed to BrowserStack local in-case of advanced configurations
57+
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
58+
# forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
59+
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections
60+
61+
# ===================
62+
# Debugging features
63+
# ===================
64+
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
65+
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
66+
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
67+
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)

android/features/local.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Feature: BrowserStack Local Testing
2+
3+
Scenario: BStack Local Test - Can check tunnel working
4+
When I start test on the Local Sample App
5+
Then I should see "Up and running"

android/features/single.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Feature: Browserstack test
2+
3+
Scenario: BStack Sample Test - Search BrowserStack
4+
Given I try to search using Wikipedia App
5+
Then I search with keyword BrowserStack
6+
Then The search results should be listed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
var assert = require('assert');
4+
const { Given, When, Then } = require("@cucumber/cucumber");
5+
const { By, until } = require("selenium-webdriver");
6+
7+
Given(/^I try to search using Wikipedia App/, async function () {
8+
await this.driver
9+
.wait(
10+
until.elementLocated(
11+
By.xpath(
12+
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.view.ViewGroup/android.support.v4.view.ViewPager/android.view.ViewGroup/android.widget.FrameLayout/android.support.v7.widget.RecyclerView/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.TextView"
13+
)
14+
),
15+
30000
16+
)
17+
.click();
18+
});
19+
20+
When(/^I search with keyword BrowserStack/, async function () {
21+
var insertTextSelector = await this.driver.wait(
22+
until.elementLocated(
23+
By.xpath(
24+
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup/android.widget.LinearLayout/android.support.v7.widget.LinearLayoutCompat/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.AutoCompleteTextView"
25+
),
26+
30000
27+
)
28+
);
29+
await insertTextSelector.sendKeys("BrowserStack");
30+
await this.driver.sleep(5000);
31+
});
32+
33+
Then(/^The search results should be listed/, async function () {
34+
var allProductsName = await this.driver.findElements(
35+
By.xpath(
36+
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout[1]/android.widget.FrameLayout[2]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ListView/android.widget.LinearLayout"
37+
)
38+
);
39+
40+
assert(allProductsName.length > 0);
41+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
var assert = require('assert');
4+
const { When, Then } = require("@cucumber/cucumber");
5+
const { By, until } = require("selenium-webdriver");
6+
7+
When(/^I start test on the Local Sample App$/, async function () {
8+
await this.driver.wait(
9+
until.elementLocated(
10+
By.xpath(
11+
'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.view.ViewGroup/android.widget.Button'
12+
)
13+
), 30000
14+
).click();
15+
});
16+
17+
Then(/^I should see "([^"]*)"$/, async function (sourceMatch) {
18+
var textElement = await this.driver.wait(
19+
until.elementLocated(
20+
By.xpath(
21+
'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.view.ViewGroup/android.widget.TextView'
22+
), 30000
23+
)
24+
).getText();
25+
26+
assert(textElement.includes('The active connection is wifi'));
27+
assert(textElement.includes('Up and running'));
28+
});

android/features/support/env.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
const { setDefaultTimeout } = require("@cucumber/cucumber");
4+
5+
setDefaultTimeout(60 * 1000);

0 commit comments

Comments
 (0)