Skip to content

Commit b2ba657

Browse files
Merge pull request #1 from browserstack/SDKAD-231-jest-sample
Initial commit Sample Repo
2 parents 701721b + 2d7a3b2 commit b2ba657

20 files changed

+14416
-1
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# This job is to test different npm profiles in main branch against Pull Requests raised
2+
# This workflow targets Jest-js
3+
4+
name: Jest Appium 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: Jest-js 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: Jest-js 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+
- name: Setup node
55+
uses: actions/setup-node@v3
56+
with:
57+
node-version: ${{ matrix.node }}
58+
59+
- name: Setup staging npm package
60+
if: ${{ github.event.inputs.package_url != '' }}
61+
run: |
62+
echo 'Publishing tar.gz to local registry'
63+
curl -o staging_package.tgz "$PACKAGE_URL"
64+
npm install [email protected] -g
65+
verdaccio &
66+
npm config set registry http://localhost:4873
67+
npm install -g npm-cli-adduser && npm-cli-adduser -u dummy -p dummy -e [email protected] -r http://localhost:4873
68+
npm publish staging_package.tgz --registry http://localhost:4873/
69+
shell: bash
70+
71+
- name: Install dependencies for android
72+
run: |
73+
cd android
74+
npm install
75+
76+
- name: Run sample tests for android
77+
run: |
78+
cd android
79+
npm run sample-test
80+
81+
- name: Run local tests for android
82+
run: |
83+
cd android
84+
npm run sample-local-test
85+
86+
- name: Install dependencies for ios
87+
run: |
88+
cd ios
89+
npm install
90+
91+
- name: Run sample tests for ios
92+
run: |
93+
cd ios
94+
npm run sample-test
95+
96+
- name: Run local tests for ios
97+
run: |
98+
cd ios
99+
npm run sample-local-test
100+
101+
- if: always()
102+
uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975
103+
id: status-check-completed
104+
env:
105+
conclusion: ${{ job.status }}
106+
job_name: Jest-js Repo ${{ matrix.node }} - ${{ matrix.os }} Sample
107+
commit_sha: ${{ github.event.inputs.commit_sha }}
108+
with:
109+
github-token: ${{ github.token }}
110+
script: |
111+
const result = await github.rest.checks.create({
112+
owner: context.repo.owner,
113+
repo: context.repo.repo,
114+
name: process.env.job_name,
115+
head_sha: process.env.commit_sha,
116+
status: 'completed',
117+
conclusion: process.env.conclusion
118+
}).catch((err) => ({status: err.status, response: err.response}));
119+
console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`)
120+
if (result.status !== 201) {
121+
console.log('Failed to create check run')
122+
}

.gitignore

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

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @browserstack/automate-public-repos
1+
* @browserstack/app-automate-public-repos

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,67 @@
11
# jest-appium-app-browserstack
22
This repository demonstrates how to run Appium tests in Jest on BrowserStack App Automate.
3+
4+
## Setup
5+
6+
### Requirements
7+
8+
1. Node.js
9+
10+
- If not installed, install Node.js from [here](https://nodejs.org/en/download/)
11+
12+
- Ensure you have node & npm installed by running `node -v` & `npm -v`
13+
14+
### Install the dependencies
15+
16+
For Android tests, run the following command in project's base directory :
17+
18+
```
19+
cd android
20+
npm install
21+
```
22+
Or,
23+
24+
For dependencies for iOS tests, run following command in project's base directory :
25+
```
26+
cd ios
27+
npm install
28+
```
29+
## Getting Started
30+
31+
Getting Started with Appium tests in NodeJS mocha on BrowserStack couldn't be easier!
32+
33+
### Run your first test :
34+
35+
Open `Android` or in `ios` folder
36+
37+
- 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.
38+
39+
- Run `npm run sample-test`
40+
41+
- 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)
42+
43+
---
44+
45+
### **Use Local testing for apps that access resources hosted in development or testing environments :**
46+
47+
Open `Android` or in `ios` folder
48+
49+
- Ensure that `browserstackLocal` capability is set to `true` in the `browserstack.yml` file.
50+
51+
- 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.
52+
53+
- Run `npm run sample-local-test`
54+
55+
- 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)
56+
57+
## Integration with other NodeJS frameworks
58+
59+
For other NodeJS frameworks samples, refer to following repositories :
60+
61+
- [WebdriverIO](https://github.com/browserstack/webdriverio-appium-app-browserstack)
62+
63+
Note: For other test frameworks supported by App-Automate refer our [Developer documentation](https://www.browserstack.com/docs/)
64+
65+
## Getting Help
66+
67+
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: jest-js:appium-sample-main: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/jest.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
coverageProvider: "v8",
3+
maxConcurrency: 5,
4+
maxWorkers: 5,
5+
roots: ["src"],
6+
testMatch: ["**/*.test.js"],
7+
testPathIgnorePatterns: ["/node_modules/"],
8+
testTimeout: 60 * 1000,
9+
};

0 commit comments

Comments
 (0)