Skip to content

Feature -> Develop | Helper File Integrations & Updates #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions Assert.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
const env = require('./../../../wdio.env');
import env from '../../../wdio.env.js'
const envObj = new env();
const params = envObj.getParams();

class Assert{
export default class Asserts{

pause()
async pauseIfHuman(seconds = params.is_human_pause)
{
if(env.is_human)
{
browser.pause(env.is_human_pause*1000);
if(params.is_human) {
await browser.pause(seconds);
}
}

pageTitle(text)
async pageUrl(text)
{
return expect(browser).toHaveTitleContaining(text);
return expect(browser).toHaveUrl(text);
}

async pageTitle(text)
{
return expect(browser).toHaveTitle(expect.stringContaining(text));
}

text(selector, text)
async text(selector, text)
{
return expect(selector).toHaveTextContaining(text);
return expect(selector).toHaveText(expect.stringContaining(text));
}

async isDisplayed(selector)
{
return expect(selector).toBeDisplayed();
}

};
async isClickable(selector)
{
return expect(selector).toBeClickable();
}

module.exports = new Assert()
async hasAttributeValue(selector, attribute, value)
{
return expect(selector).toHaveAttribute(attribute, expect.stringContaining(value));
}
};
67 changes: 67 additions & 0 deletions Helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
export default class Helper{

async checkBaseUrlResponse(base_url){ // Method to check wether the base_url reponse is 200 or not
const response = await fetch(base_url);
expect(response.status).toBe(200);
}

async waitForDisplayed(element, millisecond = 1000){
try {
await element.waitForDisplayed({ timeout: millisecond })
} catch (error) {
throw `Timeout: Element '${element.selector}' was not displayed after ${millisecond}ms. Original error: ${error.message}`
}
}

async waitForAbsent(element, millisecond = 2000){
await element.waitForDisplayed({ reverse: true, timeout: millisecond});
}

async scrollIntoView(element){
await element.scrollIntoView({ block: 'center', inline: 'center' });
}

async scroll(x, y){ // Here the parameters 'x' & 'y' denotes the horizontal & vertical scroll values
await browser.scroll(x, y);
}

async waitForClickable(element, millisecond = 2000){
await element.waitForClickable({ timeout: millisecond });
}

async waitForEnabled(element, millisecond = 2000){
await element.waitForEnabled({ timeout: millisecond });
}

async waitForDisabled(element, millisecond = 2000){
await element.waitForEnabled({ reverse: true, timeout: millisecond })
}

async waitForExist(element, millisecond = 2000){
await element.waitForExist({ timeout: millisecond });
}

async elementScreenshot(element, filename){
await element.saveScreenshot(filename);
}

async browserScreenshot(filename){
await browser.saveScreenshot(filename);
}

async switchFrame(iframe){ // Here the parameter 'iframe' is a valid selector for the iframe element
try {
await browser.switchToFrame(iframe);
} catch (error) {
throw `Failed to switch to the specified iframe (selector: '${iframe}'). Original error: ${error.message}`
}
}

async switchWindow(handle){ // Here the parameter 'handle' can be a URL handle or page title
try {
await browser.switchToWindow(handle);
} catch (error) {
throw `Failed to switch to the specified window (handle: '${handle}'). Original error: ${error.message}`
}
}
}
42 changes: 29 additions & 13 deletions Page.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
const chalk = require('chalk');
const env = require('./../../../wdio.env');
import chalk from 'chalk';
import color from 'cli-color'
import env from '../../../wdio.env.js'

chalk.enabled = true
chalk.level = 3

const envObj = new env();
const params = envObj.getParams();


/**
* main page object containing all methods, selectors and functionality
* that is shared across all page objects
*/
module.exports = class Page {
* main page object containing all methods, selectors and functionality
* that is shared across all page objects
*/
export default class Page {

constructor() {
this.base_url = env.base_url;
this.base_url = params.base_url;
this.is_human_pause = params.is_human_pause;
this.small_pause = params.small_pause;
this.medium_pause = params.medium_pause;
this.long_pause = params.long_pause;
this.params = {
page: {
id: null,
Expand All @@ -35,22 +47,26 @@ module.exports = class Page {
return browser.url(url);
}
//-------------------------------------------------
bold(str)
{
return chalk.bold(str);
}
//-------------------------------------------------
highlight(str)
{
return chalk.magenta(str);
}
//-------------------------------------------------
pageId(params)
{

return `
[PAGE ID: ${this.highlight(params.page.id)}] Page: `+params.page.name+` URL: `+params.page.url;
return this.bold(`
[PAGE ID: ${this.highlight(params.page.id)}] Page: `+params.page.name+` URL: `+params.page.url);
}
//-------------------------------------------------
groupId(params)
{
let id = chalk.red(`
---------------------------------------------------------------`);
--------------------------------------------------------------------------------------------------------`);
id += this.pageId(params);
id += `
[GROUP ID: `+this.highlight(params.page.id+"_"+params.group.count)+"] "+params.group.name;
Expand All @@ -64,12 +80,12 @@ module.exports = class Page {
if(params.test.expect)
{
id += `
${chalk.blue('Expect:')} ${params.test.expect}`;
${color.blue('Expect:')} ${params.test.expect}`;
}


return id;
}
//-------------------------------------------------
//-------------------------------------------------
}
}
Loading