The WDIO team works hard to make everything easy to install, as described in the documentation. WDIO can be set up intwo ways:
- Custom configuration while answering a seriesof questions
- Cloned from an existing projecton GitHub
For this project, we will show the questions and the selected answers. The second option, cloning the boilerplate project approach, is described in thefollowing section.
Option 1 – required steps to start installing WebdriverIO 8.0for TypeScript
Navigate from theTERMINAL window to the\repos\wdio
folder. The quickest way to set up a WDIO project quickly from Yarn is to typeyarn create wdio
, ending with adot (.
):
> yarn create wdio .
The WDIO robot will appear, and a list of configuration questions willbe presented:
Figure 2.3 – WDIO initialization from the code TERMINAL window
The initialization will ask how to configure WDIO from scratch. Here is the list of settings for WebDriver 8.0. There are several options, and many will use the default. Each item with a star (*
) shows the choice selectedat setup:
Note
WebdriverIO is always being updated. These questions themselves should be similar for both Mac and Windows users. However, the order, phrasing, and selection details do change slightly as new featuresare added.
Figure 2.4 – Settings
? What type of testing would you like to do? (Usearrow keys)
- > (*) E2E Testing - of Web orMobile Applications
- ( ) Component or Unit Testing - inthe browser
- >https://webdriver.io/docs/component-testing
- ( ) Desktop Testing - ofElectron Applications
- >https://webdriver.io/docs/desktop-testing/electron
- ( ) Desktop Testing - ofMacOS Applications
- >https://webdriver.io/docs/desktop-testing/macos
? Where is your automation backend located? (Usearrow keys)
- > (*) On my localmachine (default)
- ( ) In the cloudusing Experitest
- ( ) In the cloud usingSauce Labs
- ( ) In the cloud using Browserstack or Testingbot or LambdaTest or adifferent service
- ( ) I have my ownSelenium cloud
Today, there are many cloud options, includingExperitest
,Sauce Labs
,BrowserStack
,Testingbot
, andLambdaTest
. For this book, we will install the automation backend on our local Mac orWindows machine.
Next is the environment type. For these purposes, we willuseWeb
:
? Which environment would you like to automate? (Usearrow keys)
- (*) Web - web applications inthe browser
- ( ) Mobile - native, hybrid, and mobile web apps, on Androidor iOS
Then, select the browser(s) wewill be using. Select the default of Chrome. Note that we can addothers later:
? With which browser should we start? (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter>to proceed)
- (*)Chrome
- ( )Firefox
- ( )Safari
- ( )Microsoft Edge
Next is the reporting framework type. For this book, we will be using Jasmine. However, much of the code that’s supplied will apply to alllisted frameworks:
? Which framework do you want to use? (Usearrow keys)
- ( )Mocha (https://mochajs.org/)
- ( ) Mocha withSerenity/JS (https://serenity-js.org/)
- (*)Jasmine (https://jasmine.github.io/)
- ( ) Jasmine withSerenity/JS (https://serenity-js.org/)
- ( )Cucumber (https://cucumber.io/)
- ( ) Cucumber withSerenity/JS (https://serenity-js.org/)
Out of the box, WebdriverIO uses Mocha by default. However, it also supports Jasmine and can be combined with Chai for advanced assertions. Cucumber is an extra layer of abstraction framework that hides the core code. This allows fewer technical resources to create tests from Feature files. Cucumber is outside the scope of this book, but the techniques described can be implemented in a Cucumber WDIO project. Next, we will tell WDIO this is aTypescript project:
? Do you want to use a compiler? (Usearrow keys
- ( )Babel (https://babeljs.io/)
- (*)TypeScript (https://www.typescriptlang.org/)
- ( )No!
Question: What is Babel and isit needed?
Babel (https://babeljs.io/) is aJavaScript transpiler. Because JavaScript is implemented differently in differentbrowsers, a transpiler is used to transform our code to an older JavaScript version. Some features are not implemented in certain browsers, such as async/await, depending on what browser version we are testing against. So, a transpiler allows us to have our framework be backward compatible. Although this is a TypeScript project, we do not need theTypeScript transpiler.
Question: How to know what features are available in different browsersand versions?
Thecaniuse.com website provides descriptive tables of the different ECMAScript features thatare supported:
We will be creating our tests in TypeScript, which is a superset of JavaScript. The Typescript transpiler will be used. Now to get a quick startupsample script.
? Do you want WebdriverIO to autogenerate sometest files?
(Y/n) Yes
This will automatically set up a sample test to run to ensure WebdriverIO is working. It is also where we will build a framework unit test to check features are working. Oh yes, we are developers, and our automation project has its own unit andintegration tests.
The following is the default path for the TypeScript sample test cases and should notbe changed:
? Where should be the location of yourspecs files?
./test/specs/**/*.ts
Tests can be organized into feature sub-folders and smoke tests under the specs folder. Notice that because we selected TypeScript in the prior question, the test extensions (.js) replacedwith .ts.
? Do you want to use pageobjects (https://martinfowler.com/bliki/PageObject.html)?
Yes
This sets up a Page Object Model folder structure forour project.
? Where are your page objectslocated? ./test/pageobjects/**/*.ts
Now, we want to configureour reporters.
Which reporter do you wantto use?
- (*)spec
- ( )dot
- ( )junit
- (*)allure
- ( )video
- ( )mochawesome
- ( )slack
WebdriverIO supports a wide variety of reporters. For this small sample, we will start with the spec and allure reporters. Note that WDIO even supports aVideo option. You may notice that Slack is included. In the final chapter of this book, we will be using Jenkins to send update messages to aSlack channel.
? Do you want to add a plugin to yourtest setup?
- ( ) wait-for: utilities that provide functionalities to wait for certain conditions till a defined taskis complete.
- >https://www.npmjs.com/package/wdio-wait-for
- ( ) angular-component-harnesses: support for Angular componenttest harnesses
- >https://www.npmjs.com/package/@badisi/wdio-harness
- ( ) Testing Library: utilities that encourage good testing practices laid downby dom-testing-library.
- >https://testing-library.com/docs/webdriverio-testing-library/intro
In our framework, we will have an advanced approach for waiting for page synchronization. This option will beleft as-is.
If the application under test (AUT) is an Angular project, it is recommended to use the Angular ComponentHarnesses configuration.
? Do you want to add a service to yourtest setup?
- ( )vscode
- ( )eslinter-service
- ( )lambdatest
- ( )crossbrowsertesting
- ( )vscode
- ( )docker
- ( )slack
Note
34 additional services are integrated into WDIO, including Slack, Cross Browser Testing (Selenium Standalone), and ES-Linter. Covering them all is beyond the scope ofthis book.
The WebdriverIOVisual Studio Code (VS Code) service allows us to seamlessly test extensions from end to end in the VS Code Desktop ID. By providing a path to your extension, the service does the rest,as follows:
- 🏗 Installs VS Code (either stable, insiders, or aspecified version).
- ⬇ Download Chromedriver specific to the given VSCode version.
- 🚀 Enables you to access the VS Code API fromyour tests.
- 🖥 Starts VS Code with custom user settings (including support for VS Code on Ubuntu, macOS,and Windows).
- 🌐 Serves VS Code from a server to be accessed by any browser for testingweb extensions.
- 📔 Bootstraps page objects with locators that match your VSCode version.
The nextquestion asks you to enter the landing page for the application under test. For this, we will use the default provided as the sample tests use this to navigate internally to a websitefor testing.
? What is thebase URL?
http://localhost
This is the base landingpage that our testswill launch.
A base landing page ensures we do not repeatedly add code to navigate to the same landing page. Later in this book, we will see how to customize this value. For the moment, we will use the internet sandboxfor testing.
The final installation step is to have npm download and install all the packages. While this part can be performed by the installer, we need to make one modification. Choose No for thefinal question.
? Do you want me to run `npminstall` (Y/n)
No
We will be using Yarn rather than npm as our package manager due to its speed. This completes the setup for installing and configuring WebdriverIO from the wizard. Another option is to clone an existing project, which will be covered next. Skip to theInstalling and configuring WebdriverIO section if you do not plan to clone from anexisting project.
Because weare using Yarn as our package manager instead of npm, we will need to remove the package-lock.json file and run the yarn install command to build the equivalentyarn.lock file.
> yarn install
Option 1 – cloning WebdriverIO from a boilerplate project
An alternate way toset up WDIO is to use a preconfiguredWDIO boilerplate project from the WDIO GitHub repo. This means that less troubleshooting might be needed. We can choose from many preconfigured boilerplate projects with all thenecessary components.
For this project, we will fork theJasmine TypeScript Boilerplate
projectfrom GitHub:
Figure 2.5 – The Jasmine TypeScript boilerplate project on GitHub
Click thejasmine-boilerplate link. This will allow us to create our own version via theCode button:
Figure 2.6 – Copying the project URL from GitHub
ClickCode. Multiple choices for cloning the project will bedisplayed. SelectOpen withGitHub Desktop:
Figure 2.7 – Cloning from the source path to the local destination
ClickClone; the project will be put in therepos
path.
Next, we will change theLocal path directory so that it points to where our project lives. We can do this by clickingChoose..., changing the directory torepo\wdio
, andclickingClone:
Figure 2.8 – The project’s Explorer icon in VS Code
Click theExplorer icon in the top-left corner of VS Code and open theWDIO
folder.
Then, clickOpen Folder, navigate to therepo\wdio
folder, andclickOpen:
Figure 2.9 – Trusting the authors of a project
If thisdialogue appears, check theTrust the authors of all files in the parent folder ‘repos’ option and clickYes, I trustthe authors.
With that, we have covered the clone installation approach. Next, we willinstall everything.