Skip to content
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

Initial Commit Repo #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
.DS_Store
package-lock.json
local.log
log/
output/
67 changes: 66 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,67 @@
# codecept-js-appium-app-browserstack
This repository demonstrates how to run Appium tests in CodeCeptJs on BrowserStack App Automate.
This repository demonstrates how to run Appium tests in CodeceptJs on BrowserStack App Automate.

## Setup

### Requirements

1. Node.js

- If not installed, install Node.js from [here](https://nodejs.org/en/download/)

- Ensure you have node & npm installed by running `node -v` & `npm -v`

### Install the dependencies

For Android tests, run the following command in project's base directory :

```
cd android
npm install
```
Or,

For dependencies for iOS tests, run following command in project's base directory :
```
cd ios
npm install
```
## Getting Started

Getting Started with Appium tests in CodeceptJs on BrowserStack couldn't be easier!

### Run your first test :

Open `Android` or in `ios` folder

- 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.

- Run `npm run sample-test`

- 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)

---

### **Use Local testing for apps that access resources hosted in development or testing environments :**

Open `Android` or in `ios` folder

- Ensure that `browserstackLocal` capability is set to `true` in the `browserstack.yml` file.

- 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.

- Run `npm run sample-local-test`

- 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)

## Integration with other NodeJS frameworks

For other NodeJS frameworks samples, refer to following repositories :

- [WebdriverIO](https://github.com/browserstack/webdriverio-appium-app-browserstack)

Note: For other test frameworks supported by App-Automate refer our [Developer documentation](https://www.browserstack.com/docs/)

## Getting Help

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).
2 changes: 2 additions & 0 deletions android/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BROWSERSTACK_USERNAME=
BROWSERSTACK_ACCESS_KEY=
Binary file added android/LocalSample.apk
Binary file not shown.
Binary file added android/WikipediaSample.apk
Binary file not shown.
69 changes: 69 additions & 0 deletions android/browserstack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# =============================
# Set BrowserStack Credentials
# =============================
# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and
# BROWSERSTACK_ACCESS_KEY as env variables
userName: BROWSERSTACK_USERNAME
accessKey: BROWSERSTACK_ACCESS_KEY

# ======================
# BrowserStack Reporting
# ======================
# The following capabilities are used to set up reporting on BrowserStack:
# Set 'projectName' to the name of your project. Example, Marketing Website
projectName: BrowserStack Samples
# Set `name` to set the session name
name: BStack android test
# Set `buildName` as the name of the job / testsuite being run
buildName: browserstack build
# `buildIdentifier` is a unique id to differentiate every execution that gets appended to
# buildName. Choose your buildIdentifier format from the available expressions:
# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution
# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30
# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests
buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression}

source: codecept-js:appium-sample-main:v1.0

# Set `app` to define the app that is to be used for testing.
# It can either take the id of any uploaded app or the path of the app directly.
app: ./WikipediaSample.apk
# app: ./LocalSample.apk #For running local tests

# =======================================
# Platforms (Browsers / Devices to test)
# =======================================
# Platforms object contains all the browser / device combinations you want to test on.
# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)

platforms:
- deviceName: Samsung Galaxy S22 Ultra
osVersion: 12.0
platformName: android
- deviceName: OnePlus 11R
osVersion: 13.0
platformName: android
- deviceName: Google Pixel 6 Pro
osVersion: 12.0
platformName: android

# ==========================================
# BrowserStack Local
# (For localhost, staging/private websites)
# ==========================================
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
browserstackLocal: true # <boolean> (Default false)
#browserStackLocalOptions:
#Options to be passed to BrowserStack local in-case of advanced configurations
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
# forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections

# ===================
# Debugging features
# ===================
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)
32 changes: 32 additions & 0 deletions android/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "codecept-js-appium-app-browserstack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"sample-test": "browserstack-node-sdk codeceptjs run -c src/test/sample/codecept.conf.js --steps",
"sample-local-test": "browserstack-node-sdk codeceptjs run -c src/test/local/codecept.conf.js --steps",
"postinstall": "npm update browserstack-node-sdk"
},
"repository": {
"type": "git",
"url": "git+https://github.com/browserstack/codecept-js-appium-app-browserstack"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/browserstack/codecept-js-appium-app-browserstack/issues"
},
"homepage": "https://github.com/browserstack/codecept-js-appium-app-browserstack#readme",
"devDependencies": {
"browserstack-node-sdk": "latest",
"codeceptjs": "^3.2.3",
"webdriverio": "^7.17.4"
},
"dependencies": {
"appium": "^2.12.1",
"browserstack-local": "^1.5.2",
"dotenv": "^16.0.0"
}
}
45 changes: 45 additions & 0 deletions android/src/test/local/codecept.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const browserstack = require("browserstack-local");
const util = require('util');
require('dotenv').config()

const BROWSERSTACK_USERNAME = process.env.BROWSERSTACK_USERNAME
const BROWSERSTACK_ACCESS_KEY = process.env.BROWSERSTACK_ACCESS_KEY

exports.config = {
tests: './*_test.js',
output: './output',
timeout: 120,
helpers: {
Appium: {
url: 'https://bstackdemo.com',
app: "../LocalSample.apk",
user: BROWSERSTACK_USERNAME,
key: BROWSERSTACK_ACCESS_KEY,
host: "hub.browserstack.com",
port: 4444,
platform: "Android",
desiredCapabilities: {
'appiumV2': true, // Enable Appium 2.x
'browserstack.debug': true,
'browserstack.networkLogs': true,
}
}
},
include: {
I: './steps_file.js'
},
mocha: {},
name: 'CodeceptJS-Appium-BrowserStack',
plugins: {
pauseOnFail: {},
retryFailedStep: {
enabled: true
},
tryTo: {
enabled: true
},
screenshotOnFail: {
enabled: true
}
}
}
12 changes: 12 additions & 0 deletions android/src/test/local/local_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const assert = require('assert');
Feature('BrowserStack Local Testing');

Scenario('BStack Local Test - Can check tunnel working', async ({ I }) => {
I.waitForElement('//hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.view.ViewGroup/android.widget.Button', 30);
I.tap('//hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.view.ViewGroup/android.widget.Button');

I.waitForElement('//hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.view.ViewGroup/android.widget.TextView', 30);
const textElement = await I.grabTextFrom('//hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[2]/android.view.ViewGroup/android.widget.TextView');
I.assert(textElement.includes('The active connection is wifi'), 'Expected text not found: "The active connection is wifi"');
I.assert(textElement.includes('Up and running'), 'Expected text not found: "Up and running"');
});
10 changes: 10 additions & 0 deletions android/src/test/local/steps_file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// in this file you can append custom step methods to 'I' object

module.exports = function() {
return actor({

// Define custom steps here, use 'this' to access default methods of I.
// It is recommended to place a general 'login' function here.

});
}
45 changes: 45 additions & 0 deletions android/src/test/sample/codecept.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const browserstack = require("browserstack-local");
const util = require('util');
require('dotenv').config()

const BROWSERSTACK_USERNAME = process.env.BROWSERSTACK_USERNAME
const BROWSERSTACK_ACCESS_KEY = process.env.BROWSERSTACK_ACCESS_KEY

exports.config = {
tests: './*_test.js',
output: './output',
timeout: 120,
helpers: {
Appium: {
url: 'https://bstackdemo.com',
app: "../WikipediaSample.apk",
user: BROWSERSTACK_USERNAME,
key: BROWSERSTACK_ACCESS_KEY,
host: "hub.browserstack.com",
port: 4444,
platform: "Android",
desiredCapabilities: {
'appiumV2': true, // Enable Appium 2.x
'browserstack.debug': true,
'browserstack.networkLogs': true,
}
}
},
include: {
I: './steps_file.js'
},
mocha: {},
name: 'CodeceptJS-Appium-BrowserStack',
plugins: {
pauseOnFail: {},
retryFailedStep: {
enabled: true
},
tryTo: {
enabled: true
},
screenshotOnFail: {
enabled: true
}
}
}
18 changes: 18 additions & 0 deletions android/src/test/sample/sample_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions android/src/test/sample/steps_file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// in this file you can append custom step methods to 'I' object

module.exports = function() {
return actor({

// Define custom steps here, use 'this' to access default methods of I.
// It is recommended to place a general 'login' function here.

});
}
2 changes: 2 additions & 0 deletions ios/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BROWSERSTACK_USERNAME=
BROWSERSTACK_ACCESS_KEY=
Binary file added ios/BStackSampleApp.ipa
Binary file not shown.
Binary file added ios/LocalSample.ipa
Binary file not shown.
Loading