-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathexample_tests.js
More file actions
149 lines (131 loc) · 4.36 KB
/
example_tests.js
File metadata and controls
149 lines (131 loc) · 4.36 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"use strict";
/* jshint node: true */
/* global describe, it, before, after, afterEach, context */ //Mocha globals
var
setup = require("./setup-device"),
wd = require("wd"),
LogCatcher = require("./itest-niacin/device_logs/log-catcher.js");
var
platform = process.env.APPIUM_PLATFORM;
var waitByLinkOrName = function (text, timeout){
if(process.env.APPIUM_AUTOMATION == "Selendroid"){
return this.waitForElementByLinkText(text, timeout);
} else {
return this.waitForElementByName(text, timeout);
}
};
wd.addPromiseChainMethod('waitByLinkOrName', waitByLinkOrName);
describe("Unity example automation tests " + platform + " Native", function () {
this.timeout(15000);
var driver;
var allPassed = true;
var logType = "adbworkaround";
var logFilterStr = new RegExp("^.\/" + process.env.APPIUM_APP_ACTIVITY);
var logCatcher = new LogCatcher(logType, logFilterStr, driver);
before(function () {
require("./itest-niacin/appium-helpers.js").configureWd(wd);
driver = wd.promiseChainRemote(setup.serverConfig);
return driver
.init(setup.desired)
.setImplicitWaitTimeout(3000);
});
after(function () {
return driver.quit();
});
afterEach(function () {
allPassed = allPassed && this.currentTest.state === 'passed';
if(this.currentTest.state == 'failed'){
var screenshotFileName = this.currentTest.title.replace(/[^a-zA-Z0-9]/g, '_');
return driver.saveScreenshot("screenshots/" + screenshotFileName);
} else {
return driver;
}
});
context("Main menu", function () {
var coordinateObjects,
birdObject;
it("gets the message that game was started", function (done) {
logCatcher
.waitForMessage(/Game Started/, 25000, 100, function(entry){
console.log("Got message '" + entry.message + "'");
done();
});
});
it("waits for items to populate", function(){
return driver.sleep(3000);
});
it("gets the element coordinates", function(done){
logCatcher
.getJSONobjects(/Automation-coordinate/, function(coordObjects){
coordinateObjects = coordObjects;
coordObjects.length.should.be.above(10);
done();
});
});
it("stores coordinates of the bird-object", function(done){
logCatcher.getJSONobject(/Automation-coordinate/, "Bird", function(birdObj){
birdObject = birdObj;
birdObject.name.should.be.equal("Bird");
birdObject.x.should.be.above(0);
birdObject.y.should.be.above(0);
done();
});
});
it("gets coordinates for start-button", function(done){
logCatcher.getJSONobject(/Automation-coordinate/, "Start", function(startButton){
try{
startButton.name.should.be.equal("Start");
startButton.x.should.be.above(0);
startButton.y.should.be.above(0);
done();
} catch(e) {
done(e);
}
});
});
it("Still sees the bird at original position after 3 seconds", function(done){
return driver
.sleep(3000)
.then(function(){
logCatcher.getJSONobject(/Automation-coordinate/, "Bird", function(birdObj){
try{
birdObj.time.should.be.above(birdObject.time);
birdObj.x.should.be.equal(birdObject.x);
birdObj.y.should.be.equal(birdObject.y);
done();
} catch(e) {
done(e);
}
});
});
});
it("clicks the start-button", function(done){
logCatcher.getJSONobject(/Automation-coordinate/, "Start", function(startButton){
return driver
.tapCoordLong(startButton.x, startButton.deviceY)
.then(function(){
console.log("Tapped at (" + startButton.x + ", " + startButton.deviceY + ")" );
done();
});
});
});
it("reached the game", function(){
return driver.sleep(3000);
});
it("gravity pulls the bird downwards", function(done){
return driver
.sleep(3000)
.then(function(){
logCatcher.getJSONobject(/Automation-coordinate/, "Bird", function(object){
try{
object.time.should.be.above(birdObject.time);
object.y.should.be.below(birdObject.y);
done();
} catch(e) {
done(e);
}
});
})
});
});
});