Skip to content

Commit 686a0cd

Browse files
committed
Updated Tests with Asyn/Await style
1 parent 0485ac4 commit 686a0cd

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async function searchTextOnGoogle() {
3535
"w3c": true,
3636
"plugin": "node_js-node_js"
3737
}
38-
}
38+
};
3939

4040
// URL: https://{username}:{accessToken}@beta-hub.lambdatest.com/wd/hub
4141
const gridUrl = 'https://' + USERNAME + ':' + KEY + '@' + GRID_HOST;

test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const webdriver = require('selenium-webdriver');
2+
const By = webdriver.By;
3+
4+
// Setup LambdaTest authentication and grid URL
5+
const USERNAME = process.env.LT_USERNAME;
6+
const KEY = process.env.LT_ACCESS_KEY;
7+
const GRID_HOST = 'hub.lambdatest.com/wd/hub';
8+
9+
async function searchTextOnGoogle() {
10+
// Setup Input capabilities
11+
const capabilities = {
12+
"browserName": "Safari",
13+
// "browserVersion": "latest",
14+
"LT:Options": {
15+
// "platformName": "Windows 10",
16+
name: 'Test 1', // name of the test
17+
build: 'NodeJS build', // name of the build
18+
"project": "Untitled",
19+
"w3c": true,
20+
"plugin": "node_js-node_js"
21+
}
22+
};
23+
24+
25+
// URL: https://{username}:{accessToken}@beta-hub.lambdatest.com/wd/hub
26+
const gridUrl = 'https://' + USERNAME + ':' + KEY + '@' + GRID_HOST;
27+
28+
// Setup and build selenium driver object
29+
const driver = new webdriver.Builder()
30+
.usingServer(gridUrl)
31+
.withCapabilities(capabilities)
32+
.build();
33+
34+
try {
35+
await driver.get('https://pdfstandalone.com/#/');
36+
37+
// Get the elements with the specified XPath
38+
const elements = await driver.findElements(By.xpath('//span[@title="Language"]'));
39+
40+
// Click on the first element (index 0)
41+
if (elements.length > 0) {
42+
await elements[0].click();
43+
console.log("Successfully clicked first list item.");
44+
}
45+
46+
47+
// Close the browser
48+
await driver.quit();
49+
} catch (err) {
50+
console.log("test failed with reason " + err);
51+
driver.executeScript('lambda-status=failed');
52+
driver.quit();
53+
}
54+
}
55+
56+
searchTextOnGoogle();

0 commit comments

Comments
 (0)