-
Notifications
You must be signed in to change notification settings - Fork 96
/
simple.safari.spec.js
42 lines (41 loc) · 1.39 KB
/
simple.safari.spec.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
37
38
39
40
41
42
const webdriver = require('selenium-webdriver');
async function runTestWithCaps (capabilities) {
let driver = new webdriver.Builder()
.usingServer(`http://${process.env.SAUCE_USERNAME}:${process.env.SAUCE_ACCESS_KEY}@ondemand.us-west-1.saucelabs.com/wd/hub`)
.withCapabilities({
...capabilities,
...capabilities['browser'] && { browserName: capabilities['browser']} // Because NodeJS language binding requires browserName to be defined
})
.build();
await driver.get("http://www.duckduckgo.com");
const inputField = await driver.findElement(webdriver.By.name("q"));
await inputField.sendKeys("SauceLabs", webdriver.Key.ENTER); // this submits on desktop browsers
try {
await driver.wait(webdriver.until.titleMatches(/SauceLabs/i), 5000);
} catch (e) {
await inputField.submit(); // this helps in mobile browsers
}
try {
await driver.wait(webdriver.until.titleMatches(/SauceLabs/i), 5000);
console.log(await driver.getTitle());
await driver.executeScript(
'sauce:job-result=passed'
);
} catch (e) {
console.log('test failed');
await driver.executeScript(
'sauce:job-result=failed'
);
}
await driver.quit();
}
const capabilities1 = {
browserName: 'safari',
browserVersion: '15',
platformName: 'macOS 12',
'sauce:options': {
build: "sauce-js",
name: "sauce on macOS",
}
}
runTestWithCaps(capabilities1);