forked from browserstack/automate-node-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle.js
37 lines (31 loc) · 1.11 KB
/
single.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const { Builder, By, Key, until } = require('selenium-webdriver');
const http = require('http');
const BROWSERSTACK_USERNAME = process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME';
const BROWSERSTACK_ACCESS_KEY = process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY';
const buildName = process.env.BROWSERSTACK_BUILD_NAME || 'BROWSERSTACK_BUILD_NAME';
let HttpAgent = new http.Agent({
keepAlive: true,
});
let capabilities = {
browserName: 'Firefox',
name: 'Firefox Test',
os: 'Windows',
build: buildName,
project: 'My Awesome App',
'browserstack.debug': true,
};
let driver = new Builder()
.usingHttpAgent(HttpAgent)
.withCapabilities(capabilities)
.usingServer(`http://${BROWSERSTACK_USERNAME}:${BROWSERSTACK_ACCESS_KEY}@hub-cloud.browserstack.com/wd/hub`)
.build();
driver.get('http://www.google.com/ncr').then(() => {
driver.findElement(By.name('q')).then((element) => {
element.sendKeys('BrowserStack', Key.RETURN).then(() => {
driver.wait(until.titleContains('BrowserStack')).then(() => driver.getTitle().then((title) => {
console.log(title);
driver.quit();
}));
})
});
});