-
Notifications
You must be signed in to change notification settings - Fork 42
/
test.js
56 lines (45 loc) · 1.53 KB
/
test.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const webdriver = require('selenium-webdriver');
const By = webdriver.By;
// Setup LambdaTest authentication and grid URL
const USERNAME = process.env.LT_USERNAME;
const KEY = process.env.LT_ACCESS_KEY;
const GRID_HOST = 'hub.lambdatest.com/wd/hub';
async function searchTextOnGoogle() {
// Setup Input capabilities
const capabilities = {
"browserName": "Safari",
// "browserVersion": "latest",
"LT:Options": {
// "platformName": "Windows 10",
name: 'Test 1', // name of the test
build: 'NodeJS build', // name of the build
"project": "Untitled",
"w3c": true,
"plugin": "node_js-node_js"
}
};
// URL: https://{username}:{accessToken}@beta-hub.lambdatest.com/wd/hub
const gridUrl = 'https://' + USERNAME + ':' + KEY + '@' + GRID_HOST;
// Setup and build selenium driver object
const driver = new webdriver.Builder()
.usingServer(gridUrl)
.withCapabilities(capabilities)
.build();
try {
await driver.get('https://pdfstandalone.com/#/');
// Get the elements with the specified XPath
const elements = await driver.findElements(By.xpath('//span[@title="Language"]'));
// Click on the first element (index 0)
if (elements.length > 0) {
await elements[0].click();
console.log("Successfully clicked first list item.");
}
// Close the browser
await driver.quit();
} catch (err) {
console.log("test failed with reason " + err);
driver.executeScript('lambda-status=failed');
driver.quit();
}
}
searchTextOnGoogle();