-
Notifications
You must be signed in to change notification settings - Fork 0
/
open_browser.js
131 lines (123 loc) · 4.01 KB
/
open_browser.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Include the chrome driver
require("chromedriver");
// Include selenium webdriver
const { Builder, By, Key, util } = require("selenium-webdriver");
let driver = new Builder().forBrowser("chrome").build();
async function example() {
let tabToOpen = driver.get("http://localhost:3000/login");
tabToOpen
.then(function () {
// Timeout to wait if connection is slow
let findTimeOutP = driver.manage().setTimeouts({
implicit: 10000, // 10 seconds
});
return findTimeOutP;
})
.then(function () {
// Step 2 - Finding the username input
let promiseUsernameBox = driver.findElement(By.name("email"));
return promiseUsernameBox;
})
.then(function (usernameBox) {
// Step 3 - Entering the username
let promiseFillUsername = usernameBox.sendKeys(
Key.RETURN
);
return promiseFillUsername;
})
.then(function () {
console.log(
"Username entered successfully in" +
"'login demonstration' for Recruitment Application"
);
// Step 4 - Finding the password input
let promisePasswordBox = driver.findElement(By.name("password"));
return promisePasswordBox;
})
.then(function (passwordBox) {
// Step 5 - Entering the password
let promiseFillPassword = passwordBox.sendKeys("Tomas", Key.RETURN);
return promiseFillPassword;
})
.then(function () {
console.log(
"Password entered successfully in" +
" 'login demonstration' for Recruitment Application"
);
// Step 6 - Finding the Sign In button
let promiseSignInBtn = driver.findElement(By.name("Login"));
return promiseSignInBtn;
})
.then(function (signInBtn) {
// Step 7 - Clicking the Sign In button
let promiseClickSignIn = signInBtn.click();
return promiseClickSignIn;
})
.then(function () {
console.log("Successfully signed in Recruitment Application!");
})
.then(function () {
// Step 8 - Finding the Logout nav link
let promiseLogOutLink = driver.findElement(By.name("logoutBtn"));
return promiseLogOutLink;
})
.then(function (logoutLink) {
// Step 9 - Clicking the Logout nav link
let promiseClickLogoutLink = logoutLink.click();
return promiseClickLogoutLink;
})
.then(function () {
console.log("Successfully clicked on the Logout link page!");
})
.then(function () {
// Step 10 - Finding the Logout button
let promiseLogoutBtn = driver.findElement(By.name("Logout"));
return promiseLogoutBtn;
})
.then(function (logoutBtn) {
// Step 11 - Clicking the Logout button
let promiseClickLogout = logoutBtn.click();
return promiseClickLogout;
})
.then(function () {
console.log("Successfully logged out of the Recruitment Application!");
})
.catch(function (err) {
console.log("Error ", err, " occurred!");
});
/*let textPromise = driver.findElement(By.className("hello")).getText();
textPromise.then((text) => {
console.log("THIS IS THE TEXT: ", text);
});*/
}
example();
/*async function example2() {
// Step 1 - Opening the geeksforgeeks sign in page
let tabToOpen2 = await driver.get("http://localhost:3000/logout");
tabToOpen2
.then(function () {
// Timeout to wait if connection is slow
let findTimeOutP = driver.manage().setTimeouts({
implicit: 10000, // 10 seconds
});
return findTimeOutP;
})
.then(function () {
// Step 6 - Finding the Sign In button
let promiseSignInBtn = driver.findElement(By.name("Logout"));
return promiseSignInBtn;
})
.then(function (signInBtn) {
// Step 7 - Clicking the Sign In button
let promiseClickSignIn = signInBtn.click();
return promiseClickSignIn;
})
.then(function () {
console.log("Successfully logged out of the Recruitment Application!");
})
.catch(function (err) {
console.log("Error ", err, " occurred!");
});
}
example2();*/