Skip to main content

WebdriverIO Introduction in PHPStorm


Hi folks,
Trying various frameworks is fun and interesting and will ultimately lead to improve yourself as a Test Automation Engineer by enabling you to have a better idea regarding the available options when it comes to frameworks. This will in fact help you to choose the ideal automation framework for your corporate project as a Test Automation Engineer. Few days back, I had the opportunity to automate a React app using WebdriverIO. Let's have a look at it !!

Setting up WebdriverIO project on PHPStorm
Pre-requisites
- Create React app package has to be installed, it simply sets up the tools you need to start your React project on PhpStorm.
 npm install -g create-react-app
- Node.js has to be installed, Refer the link
1. Create a new project -> React App


2. WebdriverIO client has to be installed
npm i --save-dev @wdio/cli
3. Next, we have to generate a configuration file that stores all of our WebdriverIO settings. To do that just run the configuration utility. It will install the relevant packages and create a config file with the name wdio.conf.js
./node_modules/.bin/wdio config

 At the moment I have gone with the default settings, which can be changed later too

Note : Each time when you create a new project you need to generate the config file

4. Node.js run configuration
Since we cannot run wdio specs using mocha test runner




JavaScript file : node_modules/@wdio/cli/bin/wdio.js
Application parameters : wdio.conf.js

Sample code

Pre-requisites

I have written the automation scripts for asana web application, since it is written in React. For that I have created an account in asana.

Covered areas in code
1. Page object pattern
2. Get data from JSON file
3. Scenarios what I tried out
  • File upload (eg : jpeg)
  • Search field using ENTER keyword
  • Drop down selection
  • Checkbox selection/deselection
Page object pattern
I have created 2 javascript classes for page, 1st Javascript class includes the URL what we are going to use, 2nd Javascript class extends the super class (1st Javascript)

Directory structure

Main page class
var data = require('../pages/data.json');

function Pages() {
    this.title = 'My page';
}
Pages.prototype.open = function () {
    browser.url(data.url)

};
module.exports = Pages;

Login page

var Pages = require('../pages/Pages.js');

class LoginPage extends Pages {
    get tryNowButton() {
        return $('.horizontalNavigation-item.hidden-logged-in');
    }

    get email() {
        return $('input[name="e"]');
    }

    get password() {
        return $('input[name="p"]');
    }

    get submit() {
        return $('#login-submit-modal-login');
    }

    login(email1, password1) {

        browser.execute("arguments[0].click();", this.tryNowButton);

       // this.tryNowButton.click();
        this.email.setValue(email1);
        browser.waitUntil(() => {
            return this.password
        }, 5000, 'timed out in password');
        this.password.setValue(password1);
        this.submit.click();
    }

    open() {
        super.open('login');
    }
}

module.exports = LoginPage;


Activity page

class ActivityPage {

    get newButton() {
        return $('div.Button.Button--small.Button--primary.Omnibutton.Omnibutton--withoutSpreadsheetGrid.TopbarPageHeaderGlobalActions-omnibutton')
    }

    get taskButton() {
        return $('a.Omnibutton-dropdownButton.Omnibutton-addTask')
    }

    get taskName() {
        return $('.QuickAddTaskContents-nameInput')
    }

    get createTaskButton() {
        return $('.Button.Button--small.Button--primary.QuickAddTaskToolbar-createButton')
    }

    get searchField() {
        return $('#topbar_search_input')
    }

    get userProfile() {
        return $('.AvatarPhoto.AvatarPhoto--small.TopbarPageHeaderGlobalActions-settingsMenuAvatar.Avatar--color5')
    }

    get profile() {
        return $('span=My Profile Settings…')
    }

    get saveChange() {
        return $('div.Button.Button--medium.Button--primary')
    }

    get removeLink() {
        return $('button.PhotoUpload-removeButton.LinkButton')
    }

    get toggleButtonOn() {
        return $('label.Switch-label')
    }

    get setLastDay() {
        return $('input.ValidatedTextInput-input.textInput.textInput--large.DateInput-textInput')
    }

    get setFirstDay() {
        return $('input.textInput.textInput--large.DateInput-textInput')
    }

    get tabClick() {
        return $$('a.tabView-tabName')
    }

    get ddlClick() {
        return $('#profile_settings_weekstartday_select')
    }

    get weekSelection() {
        return $$('span.MenuItem-label')
    }

    get checkboxSelection() {
        return $$('label.Checkbox-box.Checkbox-box--unchecked.Checkbox-box--enabled.Checkbox-box--primary')
    }

    taskCreation(taskname1) {
        this.newButton.click();
        this.taskButton.click();
        this.taskName.setValue(taskname1);
        browser.pause(3000);
        this.createTaskButton.click()
    }

    search(searchValue) {
        this.searchField.setValue(searchValue);
        browser.keys("\uE007");
        browser.pause(20000);
    }

    fileUpload1() {

        this.userProfile.click();
        this.profile.click();
        browser.pause(2000);

        const fileUpload = $('input[type="file"]');
        browser.execute(
            // assign style to elem in the browser
            (el) => el.style.display = 'block',
            // pass in element so we don't need to query it again in the browser
            fileUpload
        );
        browser.pause(3000);
        fileUpload.waitForDisplayed();
        const path = require('path');
        const filePath = path.join(__dirname, 'download.jpeg');
        fileUpload.setValue(filePath);
        browser.pause(5000);
        this.saveChange.click();
        browser.pause(5000);
    }

    fileRemove() {
        this.userProfile.click();
        this.profile.click();
        this.removeLink.click();
        this.saveChange.click();
        browser.pause(2000);
    }

    dateSet() {
        this.userProfile.click();
        this.profile.click();
        this.toggleButtonOn.click();
        this.setFirstDay.setValue('07/16/19');
        this.setLastDay.setValue('08/15/20');
        this.saveChange.click();
        browser.pause(5000);
    }

    dateSetRemove() {
        this.userProfile.click();
        this.profile.click();
        this.setFirstDay.clearValue();
        this.setLastDay.clearValue();
        this.toggleButtonOn.click();
        this.saveChange.click();
        browser.pause(5000);
    }

    dropdownSelection() {
        this.userProfile.click();
        this.profile.click();
        this.tabClick[4].click();
        this.ddlClick.click();
        this.weekSelection[2].click();
        this.checkboxSelection[0].click();
        browser.pause(5000);
    }
}

module.exports = ActivityPage;


Activity Test Case

var LoginPage = require('../pages/LoginPage.js');
var ActivityPage = require('../pages/Activity.js');
var data = require('../pages/data.json');

var login = new LoginPage();
var activity = new ActivityPage();
const assert = require('assert');


describe('Check asana login and other activities', function () {

    before(function () {
        login.open();
        login.login(data.username, data.password);
    });

    it('should upload the file', function () {
        activity.fileUpload1();
    });

    it('should remove the uploaded image', function () {
        activity.fileRemove();
        const title = browser.getTitle();
        assert.strictEqual(title, 'Home - Asana');
    });

    it('should set the date', function () {
        activity.dateSet();
        activity.dateSetRemove();
    });

    it('should select from ddl and the checkbox', function () {
        activity.dropdownSelection();
    });

    it('should create and search the task', function () {
        activity.taskCreation(data.taskname);
        activity.search(data.taskname);
    });
});


Hope you guys were able to get it working like a charm. You can get the source code from below repository.


GitHub link : https://github.com/thuvvashan20/WebdriverIO-Javascript

                                           Happy testing..!!!🐞🐞🐞🐞

Comments

Popular posts from this blog

Data Driven Protractor Testing

In this article I would like to share knowledge regarding Data driven testing. When using a Data driven automation test framework, we do not need to hard code the test data. Instead it enables to access the test data from a separate data file and use them in the automated test cases. First, let's take a look at a simple Protractor script without Data Driven framework describe('Angular home page', function () {       it('should add the String in todo list ', function () {          browser.get('https://angularjs.org/');          element.all(by.css("[placeholder='add new todo here']")).sendKeys("Add POM");          element(by.css('input.btn-primary')).click();          var getText = element.all(by.css('label.checkbox'));          getText.get(2).getText().then(function (results) {          expect(results).toEqua...

Katalon studio Execution Profiles

Hi Folks, I want to share my experience regarding the learning, My project manager asked me to find the best way to automate the web application for the regression/retest purpose. So I had a research on the tools and technologies regarding automation. So I found this :) In this post I would like to share my knowledge on Katalon Studio Profiles.  Let's have a quick idea regarding Katalon studio. Katalon studio is a free automation testing tool and supports the web and mobile environment, and built on top of the open-source automation frameworks Selenium, Appium with a specialized IDE. Pre requests - You can download Katalon studio from this link. I am using the latest version in order to avoid unnecessary errors. First, I will show how to record the Web application via Katalon studio. Find below mentioned test scenarios which are going to be recorded Launch the application (URL : http://demoaut.katalon.com/ ) Make an Appointment Login using provided credentials...

Protractor with Gitlab and Jenkins

Hi everyone.. welcome to the first article in my new series of articles on Automation Testing. For a change, let's start from the End. Let's assume you have written your automation code in protractor and your project is ready to be pushed in to the repository. So let's start with a brief introduction on how to push our automation code to a Git repository. In this lesson I will be using GitLab repository. First things first.. You can't just push the code to a repository. Yeah.... you have to install Gitlab and make sure you have configured it properly. Try following command to make sure Git have been installed in your machine. git --version Hope Git have been installed in your machine, Let's start with GitLab configuration. Sign up with GitLab account Go to GitLab account and get register with your email account To identify you as the author configure your Git username and email address in your machine git config -- global user.name git config -- g...