Skip to content

Commit bd659f7

Browse files
sourav-kundufrancisf
authored andcommitted
Puppeteer code samples initial commit
1 parent 8473270 commit bd659f7

23 files changed

+7178
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,78 @@
11
# puppeteer-browserstack
2-
Sample repo for Puppeteer samples with BrowserStack.
2+
Sample Puppeteer tests to run on BrowserStack
3+
4+
## Introduction
5+
6+
You can now run your Puppeteer tests on the BrowserStack infrastructure. Porting your existing Puppeteer tests to run on BrowserStack, can be done in a matter of minutes.
7+
8+
This guide walks you through running a sample Puppeteer test on BrowserStack and then goes on to run tests on privately hosted websites.
9+
10+
## Pre-requisites
11+
12+
You need BrowserStack credentials to be able to run Puppeteer tests and also you need to be included in the Beta group so that we can enable Puppeteer access for you in our infra while the integration is in closed-beta.
13+
14+
If you have already been included in the beta group, proceed ahead. Else, you can [reach out to support](https://www.browserstack.com/contact#technical-support) to get included in the beta group.
15+
16+
You have to replace `YOUR_USERNAME` and `YOUR_ACCESS_KEY` in the sample scripts in this repository with your BrowserStack credentials which can be found in your [Account Settings](https://www.browserstack.com/accounts/settings) page.
17+
18+
**Alternatively, you can set the environment variables `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` with your credentials and all the scripts in this repository should work fine**
19+
20+
## Run your first Playwright test on BrowserStack
21+
22+
1. Clone this repository
23+
2. Install the dependencies using `npm install`
24+
3. Replace `YOUR_USERNAME` and `YOUR_ACCESS_KEY` in `google_search.js` with your BrowserStack credentials
25+
3. Run the sample script using `node google_search.js`
26+
27+
## Test across multiple browser and OS versions in parallel
28+
29+
1. Clone this repository (if not already done)
30+
2. Install the dependencies using `npm install` (if not already done)
31+
3. Replace `YOUR_USERNAME` and `YOUR_ACCESS_KEY` in `parallel_test.js` file, with your BrowserStack credentials
32+
4. Run across 8 different browser and OS combinations in parallel using `node parallel_test.js`
33+
34+
35+
## Run sample test on privately hosted websites
36+
37+
1. You have to download the BrowserStack Local binary from the links below (depending on your local machine's environment):
38+
* [OS X (10.7 and above)](https://www.browserstack.com/browserstack-local/BrowserStackLocal-darwin-x64.zip)
39+
* [Linux 32-bit](https://www.browserstack.com/browserstack-local/BrowserStackLocal-linux-ia32.zip)
40+
* [Linux 64-bit](https://www.browserstack.com/browserstack-local/BrowserStackLocal-linux-x64.zip)
41+
* [Windows (XP and above)](https://www.browserstack.com/browserstack-local/BrowserStackLocal-win32.zip)
42+
2. Once you have downloaded and unzipped the file, you can initiate the binary by running the command: `./BrowserStackLocal --key YOUR_ACCESS_KEY`
43+
3. Once you see the terminal say “\[SUCCESS\] You can now access your local server(s) in our remote browser”, your local testing connection is considered established.
44+
4. You can then replace `YOUR_USERNAME` and `YOUR_ACCESS_KEY` in `local_test.js` with your BrowserStack credentials and run the sample Local test using `node local_test.js`
45+
46+
## Supported browser versions
47+
48+
Puppeteer tests can be run on BrowserStack in the following browsers (including versions):
49+
1. `chrome` browser version `72` and above across different versions of Windows and macOS operating systems mentioned below.
50+
2. `firefox` browser version `86` and above across all supported OS versions as mentioned below.
51+
3. `edge` browser version `80` and above across all supported OS versions as mentioned below.
52+
53+
You can use the `browser_version` capability to specify the version of the browser where you want to run your tests. We support values like `latest-beta`, `latest`, `latest-1`, `latest-2` and so on, in the `browser_version` capability so specify the current beta, latest or latest-n browser version to run your tests.
54+
55+
You can specify the `browser` and `browser_version` capability as follows:<br> (`'browser': 'chrome', 'browser_version': 'latest-beta'`)
56+
57+
### OS (with versions) supported
58+
1. Windows 10 (`'os': 'Windows', 'os_version': '10'`)
59+
2. Windows 8.1 (`'os': 'Windows', 'os_version': '8.1'`)
60+
3. Windows 8 (`'os': 'Windows', 'os_version': '8'`)
61+
4. Windows 7 (`'os': 'Windows', 'os_version': '7'`)
62+
5. macOS Big Sur (`'os': 'osx', 'os_version': 'Big Sur'`)
63+
6. macOS Catalina (`'os': 'osx', 'os_version': 'Catalina'`)
64+
7. macOS High Sierra (`'os': 'osx', 'os_version': 'High Sierra'`)
65+
8. macOS Sierra (`'os': 'osx', 'os_version': 'Sierra'`)
66+
9. macOS El Capitan (`'os': 'osx', 'os_version': 'El Capitan'`)
67+
68+
## Get Puppeteer session details
69+
70+
While your Puppeteer session runs on BrowserStack, we generate a unique ID for the session, build and also generate URLs for the various types of logs which you can use to build your own reporting or for any other purpose that you might like.
71+
72+
A sample script with the use of the API to fetch all the relevant session details is shown in the [sample_session_details_API.js](./sample_session_details_API.js).
73+
74+
You can see the [documentation for marking test status using REST API](https://www.browserstack.com/docs/automate/api-reference/selenium/session#set-test-status) using the session ID for the session, any time even after the session has completed its execution.
75+
76+
## Facing issues?
77+
78+
If you are facing any issue with any of the above or any other issue in trying to run your Playwright tests on BrowserStack, you can reach out to me directly at `[email protected]` and I will be happy to debug your issues or at the least ensure that your issue becomes our top priority to resolve.

codeceptjs-example/codecept.conf.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const { setHeadlessWhen } = require('@codeceptjs/configure');
2+
3+
// turn on headless mode when running with HEADLESS=true environment variable
4+
// export HEADLESS=true && npx codeceptjs run
5+
setHeadlessWhen(process.env.HEADLESS);
6+
7+
const caps = {
8+
'browser': 'chrome',
9+
'browser_version': 'latest',
10+
'os': 'osx',
11+
'os_version': 'catalina',
12+
'name': 'Codecept test using Puppeteer',
13+
'build': 'CodeceptJS Puppeteer on BrowserStack',
14+
'browserstack.username': process.env.BROWSERSTACK_USERNAME || 'YOUR_USERNAME',
15+
'browserstack.accessKey': process.env.BROWSERSTACK_ACCESS_KEY || 'YOUR_ACCESS_KEY'
16+
};
17+
18+
exports.config = {
19+
tests: './*_test.js',
20+
output: './output',
21+
helpers: {
22+
Puppeteer: {
23+
chrome: {
24+
browserWSEndpoint: `wss://cdp.browserstack.com?caps=${encodeURIComponent(JSON.stringify(caps))}`
25+
}
26+
}
27+
},
28+
include: {
29+
I: './steps_file.js'
30+
},
31+
bootstrap: null,
32+
mocha: {},
33+
name: 'codeceptjs-example',
34+
plugins: {
35+
pauseOnFail: {},
36+
retryFailedStep: {
37+
enabled: true
38+
},
39+
tryTo: {
40+
enabled: true
41+
},
42+
screenshotOnFail: {
43+
enabled: true
44+
}
45+
}
46+
}

codeceptjs-example/jsconfig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true
4+
}
5+
}

codeceptjs-example/login_test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Feature('login');
2+
3+
Scenario('Login on GitHub', ({ I }) => {
4+
I.amOnPage('https://github.com');
5+
I.click('Sign in', '//html/body/div[1]/header');
6+
I.see('Sign in to GitHub', 'h1');
7+
I.fillField('Username or email address', '[email protected]');
8+
I.fillField('Password', '123456');
9+
I.click('Sign in');
10+
I.see('Incorrect username or password.', '.flash-error');
11+
});

0 commit comments

Comments
 (0)