Skip to content

Commit 53ce6a9

Browse files
authored
Merge pull request #1 from shayan-bstack/main
feat:codecept-playwright-sdk-launch
2 parents 3556265 + 46d24df commit 53ce6a9

File tree

10 files changed

+261
-2
lines changed

10 files changed

+261
-2
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
playwright-report
3+
test-results
4+
log/
5+
package-lock.json
6+
local.log
7+
output/

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,32 @@
1-
# codecept-js-playwright-browserstack
2-
Sample code for running sessions with Codecept Playwright on Browserstack
1+
# CodeceptJS-Playwright-Browserstack
2+
3+
# Integrating Playwright <a href="https://playwright.dev/docs/intro"><img src="https://playwright.dev/img/playwright-logo.svg" alt="Node.js" height="22" /></a> and CodeceptJS <a href="https://codecept.io/"><img src="https://codecept.io/logo.svg" alt="Node.js" height="22" /></a> with BrowserStack <a href="https://browserstack.com"><img src="https://raw.githubusercontent.com/browserstack/MSTest-playwright-browserstack/main/assets/browserstack.png" alt="BrowserStack" height="22" /></a>
4+
5+
6+
## Setup
7+
* Clone the repo `git clone https://github.com/browserstack/codecept-js-playwright-browserstack.git`.
8+
* Run `cd codecept-js-playwright-browserstack`.
9+
* Install dependencies `npm install`
10+
11+
12+
## Running your tests
13+
14+
- To run the sample tests in parallel across the platforms specified in the `browserstack.yml`, run `npm run sample-test`.
15+
- To run the sample local tests in parallel across the platforms specified in the `browserstack.yml`, run `npm run sample-local-test`.
16+
17+
## Notes
18+
* You can export the environment variables for the Username and Access Key of your BrowserStack account.
19+
20+
```
21+
export BROWSERSTACK_USERNAME=<browserstack-username> &&
22+
export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
23+
```
24+
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)
25+
* Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
26+
27+
## Addtional Resources
28+
* [Documentation for writing Automate test scripts in CodeceptJS](https://codecept.io/helpers/WebDriver/#webdriver)
29+
* [Documentation for playwright](https://playwright.dev/docs/intro)
30+
* [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities)
31+
32+

browserstack.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# =============================
2+
# Set BrowserStack Credentials
3+
# =============================
4+
# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and
5+
# BROWSERSTACK_ACCESS_KEY as env variables
6+
userName: YOUR_USERNAME
7+
accessKey: YOUR_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+
# =======================================
25+
# Platforms (Browsers / Devices to test)
26+
# =======================================
27+
# Platforms object contains all the browser / device combinations you want to test on.
28+
# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)
29+
platforms:
30+
- os: Windows
31+
osVersion: 11
32+
browserName: chrome
33+
browserVersion: latest
34+
- os: OS X
35+
osVersion: Ventura
36+
browserName: playwright-webkit
37+
browserVersion: latest
38+
- os: Windows
39+
osVersion: 11
40+
browserName: playwright-firefox
41+
browserVersion: latest
42+
43+
# =======================
44+
# Parallels per Platform
45+
# =======================
46+
# The number of parallel threads to be used for each platform set.
47+
# BrowserStack's SDK runner will select the best strategy based on the configured value
48+
#
49+
# Example 1 - If you have configured 3 platforms and set `parallelsPerPlatform` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack
50+
#
51+
# Example 2 - If you have configured 1 platform and set `parallelsPerPlatform` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack
52+
parallelsPerPlatform: 1
53+
54+
# ==========================================
55+
# BrowserStack Local
56+
# (For localhost, staging/private websites)
57+
# ==========================================
58+
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
59+
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
60+
browserstackLocal: true # <boolean> (Default false)
61+
# browserStackLocalOptions:
62+
# Options to be passed to BrowserStack local in-case of advanced configurations
63+
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
64+
# forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
65+
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections
66+
67+
framework: playwright
68+
source: codeceptjs-playwright:sample-sdk:v1
69+
70+
# ===================
71+
# Debugging features
72+
# ===================
73+
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
74+
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
75+
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
76+
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)
77+
# CUSTOM_TAG_<INT>: # <string> (Default: parent folder name of the test file) Custom tag for your test suite
78+
79+
# Test Observability is an intelligent test reporting & debugging product. It collects data using the SDK. Read more about what data is collected at https://www.browserstack.com/docs/test-observability/references/terms-and-conditions
80+
# Visit observability.browserstack.com to see your test reports and insights. To disable test observability, specify `testObservability: false` in the key below.
81+
testObservability: true

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "codecept-js-playwright-browserstack",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"sample-test": "browserstack-node-sdk codeceptjs run -c src/test/sample/codecept.conf.js --steps",
9+
"sample-local-test": "browserstack-node-sdk codeceptjs run -c src/test/local/codecept.conf.js --steps",
10+
"postinstall": "npm update browserstack-node-sdk"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/browserstack/codecept-js-playwright-browserstack"
15+
},
16+
"author": "",
17+
"license": "ISC",
18+
"bugs": {
19+
"url": "https://github.com/browserstack/codecept-js-playwright-browserstack/issues"
20+
},
21+
"homepage": "https://github.com/browserstack/codecept-js-playwright-browserstack#readme",
22+
"devDependencies": {
23+
"browserstack-node-sdk": "latest",
24+
"codeceptjs": "^3.2.3",
25+
"playwright": "^1.41.2"
26+
},
27+
"dependencies": {
28+
"browserstack-local": "^1.5.2",
29+
"dotenv": "^16.0.0"
30+
}
31+
}

src/test/local/codecept.conf.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const browserstack = require("browserstack-local");
2+
const util = require('util');
3+
require('dotenv').config()
4+
5+
const BROWSERSTACK_USERNAME = process.env.BROWSERSTACK_USERNAME
6+
const BROWSERSTACK_ACCESS_KEY = process.env.BROWSERSTACK_ACCESS_KEY
7+
8+
exports.config = {
9+
tests: './*_test.js',
10+
output: './output',
11+
timeout: 120,
12+
helpers: {
13+
Playwright: {
14+
url: 'http://bs-local.com:45454/',
15+
show: true,
16+
restart: 'keep',
17+
}
18+
},
19+
include: {
20+
I: './steps_file.js'
21+
},
22+
mocha: {},
23+
name: 'CodeceptJS-Playwright-BrowserStack-Local',
24+
plugins: {
25+
pauseOnFail: {},
26+
retryFailedStep: {
27+
enabled: true
28+
},
29+
tryTo: {
30+
enabled: true
31+
},
32+
screenshotOnFail: {
33+
enabled: true
34+
}
35+
}
36+
}

src/test/local/local_test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const assert = require('assert');
2+
Feature('BrowserStack Local Testing');
3+
4+
Scenario('BStack Local Test', async ({ I }) => {
5+
I.amOnPage("http://bs-local.com:45454/")
6+
let text = await I.grabTitle()
7+
console.log(text)
8+
assert.equal(text, "BrowserStack Local", "Local Instance is not runnning!")
9+
});

src/test/local/steps_file.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// in this file you can append custom step methods to 'I' object
2+
3+
module.exports = function() {
4+
return actor({
5+
6+
// Define custom steps here, use 'this' to access default methods of I.
7+
// It is recommended to place a general 'login' function here.
8+
9+
});
10+
}

src/test/sample/codecept.conf.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require('dotenv').config()
2+
const BROWSERSTACK_USERNAME = process.env.BROWSERSTACK_USERNAME
3+
const BROWSERSTACK_ACCESS_KEY = process.env.BROWSERSTACK_ACCESS_KEY
4+
5+
exports.config = {
6+
tests: './*_test.js',
7+
output: './output',
8+
timeout: 120,
9+
helpers: {
10+
Playwright: {
11+
url: 'https://bstackdemo.com',
12+
show: true,
13+
restart: 'keep',
14+
}
15+
},
16+
include: {
17+
I: './steps_file.js'
18+
},
19+
bootstrap: null,
20+
mocha: {},
21+
name: 'CodeceptJS-Playwright-BrowserStack',
22+
plugins: {
23+
pauseOnFail: {},
24+
retryFailedStep: {
25+
enabled: true
26+
},
27+
tryTo: {
28+
enabled: true
29+
},
30+
screenshotOnFail: {
31+
enabled: true
32+
}
33+
}
34+
}

src/test/sample/sample_test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const assert = require('assert');
2+
Feature('Add to Cart');
3+
4+
Scenario('BStack Sample Test One', async ({ I }) => {
5+
I.amOnPage("https://bstackdemo.com")
6+
let expectedProductName = await I.grabTextFrom('//*[@id="1"]/p')
7+
I.click('//*[@id="1"]/div[4]')
8+
9+
let productName = await I.grabTextFrom('//*[@id="__next"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]')
10+
assert.equal(productName, expectedProductName, "Product Did Not Match!")
11+
})

src/test/sample/steps_file.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// in this file you can append custom step methods to 'I' object
2+
3+
module.exports = function() {
4+
return actor({
5+
6+
// Define custom steps here, use 'this' to access default methods of I.
7+
// It is recommended to place a general 'login' function here.
8+
9+
});
10+
}

0 commit comments

Comments
 (0)