2018-01-17 16:39:17 +01:00
|
|
|
var artifacts = require("../../artifacts");
|
|
|
|
var fs = require("fs");
|
|
|
|
var path = require("path");
|
|
|
|
|
|
|
|
|
2019-06-08 07:19:18 +02:00
|
|
|
browser.setTimeout({ 'script': 20*1000 });
|
|
|
|
browser.setTimeout({ 'implicit': 20*1000 });
|
2018-01-10 14:19:34 +01:00
|
|
|
|
2018-01-17 16:39:17 +01:00
|
|
|
var SCREENSHOTS_PATH = artifacts.pathSync("/screenshots");
|
|
|
|
|
2018-01-10 14:19:34 +01:00
|
|
|
/**
|
|
|
|
* Sometimes chrome driver can result in the wrong text.
|
|
|
|
*
|
|
|
|
* See <https://github.com/webdriverio/webdriverio/issues/1886>
|
|
|
|
*/
|
|
|
|
try {
|
|
|
|
browser.addCommand('setValueSafe', function(selector, text) {
|
|
|
|
for(var i=0; i<10; i++) {
|
2019-06-08 07:19:18 +02:00
|
|
|
const elem = $(selector);
|
|
|
|
elem.waitForDisplayed(500);
|
2018-01-10 14:19:34 +01:00
|
|
|
|
2019-06-08 07:19:18 +02:00
|
|
|
var elements = browser.findElements("css selector", selector);
|
2018-01-10 14:19:34 +01:00
|
|
|
if(elements.length > 1) {
|
|
|
|
throw "Too many elements found";
|
|
|
|
}
|
|
|
|
|
2019-06-08 07:19:18 +02:00
|
|
|
const elem2 = $(selector);
|
|
|
|
elem2.setValue(text);
|
|
|
|
|
|
|
|
var browserText = elem2.getValue();
|
2018-01-10 14:19:34 +01:00
|
|
|
|
|
|
|
if(browserText == text) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.error("Warning: setValue failed, trying again");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for change events to fire and state updated
|
|
|
|
browser.flushReactUpdates();
|
|
|
|
})
|
|
|
|
|
|
|
|
browser.addCommand('takeScreenShot', function(filepath) {
|
2020-05-24 12:13:16 +02:00
|
|
|
var savepath = path.join(SCREENSHOTS_PATH, filepath);
|
|
|
|
browser.saveScreenshot(savepath);
|
2018-01-10 14:19:34 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
browser.addCommand('flushReactUpdates', function() {
|
|
|
|
browser.executeAsync(function(done) {
|
|
|
|
// For any events to propogate
|
2018-09-10 16:09:34 +02:00
|
|
|
setTimeout(function() {
|
2018-01-10 14:19:34 +01:00
|
|
|
// For the DOM to be updated.
|
2018-09-10 16:09:34 +02:00
|
|
|
setTimeout(done, 0);
|
|
|
|
}, 0)
|
2018-01-10 14:19:34 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
} catch(err) {
|
|
|
|
console.error(">>> Ignored error: "+err);
|
|
|
|
}
|