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

GitLab and Jenkins configuration through SSH

In my previous post I have mentioned how to integrate GitLab with Jenkins using username and password. Now we will learn how to configure Jenkins and GitLab using SSH connection. Login as Jenkins user sudo su - jenkins Run the following command to generate SSH key,  ssh - keygen Now it will create  a directory named .ssh if it doesn't exist, Press enter and re-enter when you are prompted to enter passphrase. thuvvareka : ~ jenkins$ ssh - keygen Generating public / private rsa key pair . Enter file in which to save the key ( / Users / Shared / Jenkins / . ssh / id_rsa ) : Created directory ' /Users/Shared/Jenkins/.ssh ' . Enter passphrase ( empty for no passphrase ) : Enter same passphrase again : Your identification has been saved in / Users / Shared / Jenkins / . ssh / id_rsa . Your public key has been saved in / Users / Shared / Jenkins / . ssh / id_rsa . pub . The key fingerprint is : SHA256 : O9APiAETUYC87e9T6k18SPFQxEN4R2gJbKG6JLOID64 jenkins@thu...

Mobile Test Automation using Appium and Android studio

In this article we will discuss about how to automate Mobile application using Appium Server and Android Studio. Appium supports both iOS and Android. Appium is HTTP server. It receives the commands from client, executes the command on Mobile device and send a HTTP response representing the result of the command execution. I am going to use Android studio to create a virtual emulator. And Selenium WebDriver will be used to write the Client. I would prefer to use the virtual emulator instead of using real device. In actual devices you may find difficulties to connect/detect it. Pre-requisites .apk file is required to install in Mobile device (Virtual emulator). Android Studio, Appium desktop server and intelliJ IDEA have to be installed. Virtual emulator This post guides you to create the Virtual emulator using Android Studio. Once you launch the emulator now It's time to install the mobile application which is going to be automated. Drag and drop the apk file ...

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...