forked from GektorGrom/frontend-testing
-
Notifications
You must be signed in to change notification settings - Fork 17
/
test-app.js
92 lines (71 loc) · 2.68 KB
/
test-app.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
const {describe, it, before, after} = require('mocha')
const {Eyes} = require('eyes.selenium')
const path = require('path')
const express = require('express')
const webdriver = require('selenium-webdriver')
require('chromedriver')
const {By, until} = webdriver
describe('calculator app', function () {
let driver
let server
this.timeout(60000)
before((done) => {
const app = express()
app.use('/', express.static(path.resolve(__dirname, '../../dist')))
server = app.listen(8080, done)
})
after(() => {
server.close()
})
before(async () => {
driver = new webdriver.Builder()
.forBrowser('chrome')
.build()
})
after(async () => await driver.quit())
it('should work', async function () {
await driver.get('http://localhost:8080')
await driver.wait(until.titleIs('Calculator'))
await driver.wait(until.elementTextIs(await driver.findElement(By.css('.display')), '0'))
const digit4Element = await driver.findElement(By.css('.digit-4'))
const digit2Element = await driver.findElement(By.css('.digit-2'))
const operatorMultiply = await driver.findElement(By.css('.operator-multiply'))
const operatorEquals = await driver.findElement(By.css('.operator-equals'))
await digit4Element.click()
await digit2Element.click()
await operatorMultiply.click()
await digit2Element.click()
await operatorEquals.click()
await driver.wait(until.elementTextIs(await driver.findElement(By.css('.display')), '84'))
})
if (!process.env.APPLITOOLS_API_KEY) {
console.warn('******** Skipping visual tests ************\n' +
'To run them, set the APPLITOOLS_API_KEY environment variable with your Applitools API Key.')
return
}
describe('visual testing', () => {
let eyes
before(async () => {
eyes = new Eyes()
eyes.setApiKey(process.env.APPLITOOLS_API_KEY)
await eyes.open(driver, 'Calculator App', 'Tests', {width: 800, height: 600})
})
after(async () => {
await eyes.close()
})
it('should look good', async function () {
await driver.get('http://localhost:8080')
await eyes.checkWindow('Initial Page')
const digit4Element = await driver.findElement(By.css('.digit-4'))
const digit2Element = await driver.findElement(By.css('.digit-2'))
const operatorMultiply = await driver.findElement(By.css('.operator-multiply'))
const operatorEquals = await driver.findElement(By.css('.operator-equals'))
await digit4Element.click()
await digit2Element.click()
await operatorMultiply.click()
await digit2Element.click()
await operatorEquals.click()
await eyes.checkWindow('After calculating 42 * 2 =')
})
})
})