-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestMocha.js
More file actions
70 lines (61 loc) · 2.34 KB
/
testMocha.js
File metadata and controls
70 lines (61 loc) · 2.34 KB
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
const {Builder, By, until} = require('selenium-webdriver');
describe('Test electron app', function() {
let driver;
before(function() {
return new Builder()
.usingServer('http://localhost:9515')
.withCapabilities({
chromeOptions: {
// Here is the path to your Electron binary.
binary: 'c:\application.exe'
}
})
.forBrowser('electron')
.build()
.then(d => {
driver = d;
});
});
it('Get app title', function theTestFunction() {
return driver.getTitle().then(function(title) {
console.log('Page title is: ' + title);
});
});
it('Wait for Page load with wait of until condition', function theTestFunction() {
return driver.wait(until.elementLocated(By.xpath("//*[@aid='host']")), 10000)
.then(x=> console.log(x), x=> console.log(x)); //Catch here will not fail the case
});
it('Wait for Page load with wait of function', function theTestFunction() {
return driver.wait(function(resolve, reject){ //here defind a function for when element is found!
return driver.findElements(By.xpath("//*[@aid='host']")).then(x=> {
console.log("found element length is " + x.length);
if(x.length!=0){
console.log("Element found");
return true;
}
else{
return false;
}
});
}, 10000);
});
it('authentication', function theTestFunction() {
return driver.getCurrentUrl().then(
_=> driver.findElement(By.xpath("//*[@aid='host']")).sendKeys('16.186.77.33:8080')
).then(_ =>
driver.findElement(By.xpath("//*[@aid='user']")).sendKeys('xxx')
)
.then(_ =>
driver.findElement(By.xpath("//*[@aid='password']")).sendKeys('xxx')
)
.then(_ =>
driver.findElement(By.xpath("//*[@aid='authentication']")).click())
});
it('Wait for login page', function theTestFunction() {
return driver.wait(until.elementLocated(By.xpath("//*[@aid='login']")), 10000)
.then(x=> console.log(x), x=> console.log(x)); //Catch here will not fail the case
});
after(function() {
return driver.quit();
});
});