Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function runJsUnitTestsInBrowser() {
var options = {
capabilities: {
browserName: 'chrome'
}
};
var url = 'file://' + __dirname + '/index.html';
console.log('Starting webdriverio...');
const browser = await webdriverio.remote(options);
console.log('Initialized.\nLoading url: ' + url);
await browser.url(url);
const elem = await browser.$('#closureTestRunnerLog')
const result = await elem.getHTML();
// call js to parse html
var regex = /[\d]+\spassed,\s([\d]+)\sfailed./i;
var numOfFailure = regex.exec(result)[1];
var regex2 = /Unit Tests for Blockly .*]/;
var testStatus = regex2.exec(result)[0];
console.log('============Blockly Unit Test Summary=================');
console.log(testStatus);
var regex3 = /\d+ passed,\s\d+ failed/;
var detail = regex3.exec(result)[0];
console.log(detail);
function startWorker (device, done) {
var client = webdriverio.remote(device);
// report result
var reportResultRegEx = /^\d+ specs, (\d+) failure/;
var reportResult;
var ignoreMsgRegEx = /ConsoleReporter/;
/**
* 桥循环
*
* @param {number} timeout 超时时间
* @param {string} timeoutMsg 超时信息
* @param {number} interval 循环间隔
* @return {client} webdrive client
*/
function bridgeLoop(timeout, timeoutMsg, interval) {
var kakuPath;
// Note
// we only support Mac & linux platform for uitest for now.
switch (process.platform) {
case 'darwin':
kakuPath = './build/Kaku-darwin-x64/Kaku.app/Contents/MacOS/Electron';
break;
default:
kakuPath = './build/app/Kaku';
break;
}
var client = webdriverio.remote({
host: 'localhost',
port: 9515,
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
binary: kakuPath
}
}
});
var assert = require('assert');
var chai = require('chai');
// Note
// we will create a child process for chromeDriver when running tests
beforeEach((done) => {
data;
if(env == 'vg1' || env == 'vg2') {
spec = JSON.parse(fs.readFileSync('spec/'+env+'/'+spec+'.json'));
var data = spec.data[0];
if(data.url) {
data.values = JSON.parse(fs.readFileSync(data.url));
delete data.url;
}
} else {
spec = require('./spec/d3/'+spec);
if(spec.data) data = JSON.parse(fs.readFileSync(spec.data));
}
var client = webdriverio.remote({
desiredCapabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--enable-precise-memory-info']
}
}
})
.init()
.url('http://localhost:8000/benchmarks/'+env+'.html')
.timeoutsAsyncScript(3000000)
.execute(function(env, specName, spec, data, N, C) {
this.N = N;
this.C = C;
// Inject data generation into the browser because Selenium throws an error
// if we send in a large pre-injected spec
public async launch(desiredCapabilities?: WebDriver.DesiredCapabilities) {
logger.debug("Browser: launch");
this._browser = await remote({
// default to chrome
capabilities: desiredCapabilities || this.getChromeCapabilities(),
logLevel: "warn",
port: CONFIG.seleniumPort
});
this._browser!.setTimeout({ script: 300 * 1000 });
}
capabilities: config,
coloredLogs: true,
screenshotPath: './errorShots/',
baseUrl: '',
waitforTimeout: 10000,
connectionRetryTimeout: 90000,
connectionRetryCount: 3,
host: 'hub.browserstack.com'
};
const extendedOptions = Object.assign(defaults, options);
if (config.logLevel) {
// OPTIONS: verbose | silent | command | data | result
extendedOptions.logLevel = config.logLevel;
}
global.browser = await wdio.remote(extendedOptions);
return browser;
};
phantomjs.run('--webdriver=4444').then(function (p) {
webdriverio.remote(wdOpts).init()
.url('https://developer.mozilla.org/en-US/')
.getTitle().then(function (title) {
test.equals(title, 'Mozilla Developer Network', 'Page title')
})
.then(function () {
p.kill()
test.done()
})
})
}
'use strict'
const WebdriverIO = require('webdriverio')
const cucumber = require('cucumber')
const client = WebdriverIO.remote({
host: 'localhost',
desiredCapabilities: {
browserName: 'firefox'
}
})
const promised = client.init()
cucumber.defineSupportCode(function (support) {
support.Before(function () {
this.browser = client
return promised
})
support.registerHandler('AfterFeatures', function (event, callback) {
client.end().then(() => callback()).catch(callback)
showsSniperStatus: function(statusText, itemId, lastPrice, lastBid) {
function assertElement(description, selector, expected) {
if (expected) {
return client.getText(selector)
.catch(e => { throw new Error(`failed locating element matching selector [${selector}]; ${e}`)})
.then(text => expect(text).to.equal(expected.toString(), description))
} else {
return Promise.resolve();
}
}
const rowId = "auction-" + itemId;
const client = webdriverio.remote(options).init();
return client.url("http://localhost:3000/")
.then(() => assertElement("Item Status", `#${rowId} td.status`, statusText))
.then(() => assertElement("Item Id", `#${rowId} td.itemId`, itemId))
.then(() => assertElement("Last Price", `#${rowId} td.lastPrice`, lastPrice))
.then(() => assertElement("Last Bid", `#${rowId} td.lastBid`, lastBid))
.call(() => client.end())
;
},
before(async () => {
client = webdriverIO.remote({
user: process.env.SAUCE_USERNAME,
key: process.env.SAUCE_ACCESS_KEY,
host: 'ondemand.saucelabs.com',
desiredCapabilities: {
browserName: browserName,
},
});
});