Skip to content

Commit

Permalink
Log steps
Browse files Browse the repository at this point in the history
  • Loading branch information
schipiga committed Mar 23, 2018
1 parent 112a312 commit 0f7a1e6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
42 changes: 36 additions & 6 deletions lib/steps/browser.js
Expand Up @@ -48,14 +48,18 @@ var BrowserSteps = {
var opts = {
logger: LOG.debug.bind(LOG),
};

LOG.info("Installing selenium drivers...");

await new Promise((resolve, reject) => {

selenium.install(opts, err => {
if (err) reject(err);
LOG.debug("Selenium drivers are installed");
if (err) return reject(err);
resolve();
});
});

LOG.info("Selenium drivers are installed");
},

startSeleniumServer: async function () {
Expand All @@ -77,15 +81,18 @@ var BrowserSteps = {
};

var opts = {};
this._seleniumProc = await new Promise((resolve, reject) => {

LOG.info("Starting selenium server...");

this._seleniumProc = await new Promise((resolve, reject) => {
selenium.start(opts, (err, child) => {
if (err) reject(err);
LOG.debug(
`Selenium server starts with PID ${child.pid}`);
if (err) return reject(err);
resolve(child);
});
});

LOG.info(`Selenium server is started with PID ${this._seleniumProc.pid}`);

return true;
},

Expand All @@ -107,6 +114,8 @@ var BrowserSteps = {
return false;
};

LOG.info("Stopping selenium server...");

await new Promise((resolve, reject) => {

this._seleniumProc.on("exit", (code, signal) => {
Expand All @@ -119,6 +128,9 @@ var BrowserSteps = {
var result = this._seleniumProc.kill("SIGINT");
if (!result) reject("Oops! Can't kill selenium server");
});

LOG.info("Selenium server is stopped");

return true;
},

Expand Down Expand Up @@ -148,6 +160,8 @@ var BrowserSteps = {
var check = U.defVal(opts.check, true);
var opt;

LOG.info("Launching browser via selenium...");

if (CONF.web.platform === "pc" &&
this.webdriver.desiredCapabilities.browserName === "chrome") {

Expand Down Expand Up @@ -188,6 +202,9 @@ var BrowserSteps = {
};

this._isBrowserLaunched = true;

LOG.info("Browser is launched");

return true;
},

Expand Down Expand Up @@ -216,6 +233,8 @@ var BrowserSteps = {
expect(width, "Invalid browser viewport width").to.be.a("number");
expect(height, "Invalid browser viewport height").to.be.a("number");

LOG.info(`Setting browser viewport to [width=${width}, height=${height}]...`);

await this
.webdriver
.setViewportSize({ width: width, height: height });
Expand All @@ -231,6 +250,8 @@ var BrowserSteps = {
.to.be.equal(height);
};

LOG.info("Browser viewport size is set");

return true;
},

Expand All @@ -257,6 +278,8 @@ var BrowserSteps = {
opts = U.defVal(opts, {});
opts.check = U.defVal(opts.check, true);

LOG.info("Closing browser...");

await this.webdriver.end();
await this.pause(1, "webdriver process will be stopped");

Expand All @@ -265,6 +288,9 @@ var BrowserSteps = {
"Browser wasn't closed").to.not.exist;
};
this._isBrowserLaunched = false;

LOG.info("Browser is closed");

return true;
},

Expand Down Expand Up @@ -305,6 +331,8 @@ var BrowserSteps = {
var check = U.defVal(opts.check, true);
var timeout = U.defVal(opts.timeout, CONF.timeouts.pageLoad);

LOG.info(`Openning URL ${webUrl} in browser...`);

await this.webdriver.url(webUrl);

if (check) {
Expand All @@ -318,6 +346,8 @@ var BrowserSteps = {
return curUrl.startsWith(webUrl);
}, timeout, errMsg);
};

LOG.info("URL is opened");
},

openApp: async function (opts) {
Expand Down
5 changes: 5 additions & 0 deletions lib/steps/page.js
Expand Up @@ -67,9 +67,14 @@ var PageSteps = {

expect(this.webUrl,
"Web URL isn't defined").to.exist;

LOG.info(`Openning page '${pageName}' in browser...`);

var page = this._pages()[pageName];
var webUrl = url.resolve(this.webUrl, page.url);
await this.openUrl(webUrl);

LOG.info("Page is opened");
},

getCurrentPage: async function () {
Expand Down

0 comments on commit 0f7a1e6

Please sign in to comment.