Skip to content

Commit

Permalink
Add browser stack support to selenium test
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Jul 31, 2021
1 parent 4ef8e36 commit cf89bfd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/browserstack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'BrowserStack Test'
on: [push, pull_request]
jobs:
ubuntu-job:
name: 'BrowserStack Test on Ubuntu'
runs-on: ubuntu-latest # Can be self-hosted runner also
steps:
- name: 'BrowserStack Env Setup' # Invokes the setup-env action
uses: browserstack/github-actions/setup-env@master
with:
username: ${{ secrets.BROWSERSTACK_USERNAME }}
access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
- name: 'BrowserStack Local Tunnel Setup' # Invokes the setup-local action
uses: browserstack/github-actions/setup-local@master
with:
local-testing: start
local-identifier: random
# The next 3 steps are for building the web application to be tested and starting the web server on the runner environment
- name: 'Checkout the repository'
uses: actions/checkout@v2

- name: Copy configuration
run: cp config.json.example config.json

- name: 'Building web application to be tested'
run: npm install
# - name: 'Running application under test'
# run: npm test
- name: 'Running test on BrowserStack'
run: npm test
- name: 'BrowserStackLocal Stop' # Terminating the BrowserStackLocal tunnel connection
uses: browserstack/github-actions/setup-local@master
with:
local-testing: stop
30 changes: 28 additions & 2 deletions test/selenium.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,35 @@ async function setup(): Promise<WebDriver> {
const options = new Chrome.Options();
options.addArguments("--load-extension=" + Path.join(__dirname, "../dist/"));
options.addArguments("--mute-audio");
options.addArguments("--disable-features=PreloadMediaEngagementData, MediaEngagementBypassAutoplayPolicies")
options.addArguments("--disable-features=PreloadMediaEngagementData, MediaEngagementBypassAutoplayPolicies");

let driver;
if (process.env.BROWSERSTACK_BUILD_NAME) {
const capabilities = {
'os': 'ubuntu',
'os_version': '20',
'browserName': 'chrome',
'browser_version' : 'latest',
'browserstack.local': 'true',
'build': process.env.BROWSERSTACK_BUILD_NAME,
'project': process.env.BROWSERSTACK_PROJECT_NAME,
'browserstack.localIdentifier': process.env.BROWSERSTACK_LOCAL_IDENTIFIER,
'browserstack.user': process.env.BROWSERSTACK_USERNAME,
'browserstack.key': process.env.BROWSERSTACK_ACCESS_KEY
}

driver = await new Builder()
.usingServer('http://hub-cloud.browserstack.com/wd/hub')
.setChromeOptions(options)
.withCapabilities(capabilities)
.build();
} else {
driver = await new Builder()
.forBrowser("chrome")
.setChromeOptions(options)
.build();
}

const driver = await new Builder().forBrowser("chrome").setChromeOptions(options).build();
driver.manage().setTimeouts({
implicit: 5000
});
Expand Down

0 comments on commit cf89bfd

Please sign in to comment.