Skip to content

Commit 5347da1

Browse files
authored
Merge pull request #1 from browserstack/SDKAD-227-sample
Adding sample script for cucumber-js with sdk
2 parents d68a1cd + cb2c71f commit 5347da1

25 files changed

+10739
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# This job is to test different npm profiles in master branch against Pull Request raised
2+
# This workflow targets cucumber-js
3+
4+
name: NodeJS SDK Test workflow on workflow_dispatch
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
commit_sha:
10+
description: 'The full commit id to build'
11+
required: true
12+
package_url:
13+
description: 'Staging package url'
14+
required: false
15+
16+
jobs:
17+
comment-run:
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
fail-fast: false
21+
max-parallel: 3
22+
matrix:
23+
node: ['14', '16', '18', '20']
24+
os: [ macos-latest, windows-latest, ubuntu-latest ]
25+
name: Cucumber-js Appium Repo ${{ matrix.node }} - ${{ matrix.os }} Sample
26+
env:
27+
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
28+
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
29+
PACKAGE_URL: ${{ github.event.inputs.package_url }}
30+
31+
steps:
32+
- uses: actions/checkout@v3
33+
with:
34+
ref: ${{ github.event.inputs.commit_sha }}
35+
- uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975
36+
id: status-check-in-progress
37+
env:
38+
job_name: Cucumber-js Appium Repo ${{ matrix.node }} - ${{ matrix.os }} Sample
39+
commit_sha: ${{ github.event.inputs.commit_sha }}
40+
with:
41+
github-token: ${{ github.token }}
42+
script: |
43+
const result = await github.rest.checks.create({
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
name: process.env.job_name,
47+
head_sha: process.env.commit_sha,
48+
status: 'in_progress'
49+
}).catch((err) => ({status: err.status, response: err.response}));
50+
console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`)
51+
if (result.status !== 201) {
52+
console.log('Failed to create check run')
53+
}
54+
55+
- name: Setup node
56+
uses: actions/setup-node@v3
57+
with:
58+
node-version: ${{ matrix.node }}
59+
60+
- name: Setup staging npm package
61+
if: ${{ github.event.inputs.package_url != '' }}
62+
run: |
63+
echo 'Publishing tar.gz to local registry'
64+
curl -o staging_package.tgz "$PACKAGE_URL"
65+
npm install verdaccio@5.32.2 -g
66+
verdaccio &
67+
npm config set registry http://localhost:4873
68+
npm install -g npm-cli-adduser && npm-cli-adduser -u dummy -p dummy -e dummy@gmail.com -r http://localhost:4873
69+
npm publish staging_package.tgz --registry http://localhost:4873/
70+
shell: bash
71+
72+
- name: Install android dependencies
73+
run: |
74+
cd android
75+
npm install
76+
77+
- name: Run android sample tests
78+
run: |
79+
cd android
80+
npm run sample-test
81+
82+
- name: Run android local tests
83+
run: |
84+
cd android
85+
npm run sample-local-test
86+
env:
87+
BROWSERSTACK_APP: "./LocalSample.apk"
88+
89+
- name: Install ios dependencies
90+
run: |
91+
cd ios
92+
npm install
93+
94+
- name: Run ios sample tests
95+
run: |
96+
cd ios
97+
npm run sample-test
98+
99+
- name: Run ios local tests
100+
run: |
101+
cd ios
102+
npm run sample-local-test
103+
env:
104+
BROWSERSTACK_APP: "./LocalSample.ipa"
105+
106+
- if: always()
107+
uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975
108+
id: status-check-completed
109+
env:
110+
conclusion: ${{ job.status }}
111+
job_name: Cucumber-js Appium Repo ${{ matrix.node }} - ${{ matrix.os }} Sample
112+
commit_sha: ${{ github.event.inputs.commit_sha }}
113+
with:
114+
github-token: ${{ github.token }}
115+
script: |
116+
const result = await github.rest.checks.create({
117+
owner: context.repo.owner,
118+
repo: context.repo.repo,
119+
name: process.env.job_name,
120+
head_sha: process.env.commit_sha,
121+
status: 'completed',
122+
conclusion: process.env.conclusion
123+
}).catch((err) => ({status: err.status, response: err.response}));
124+
console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`)
125+
if (result.status !== 201) {
126+
console.log('Failed to create check run')
127+
}

.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+
});

0 commit comments

Comments
 (0)