Using Selenium WebDriver to automatically test Yandex.Mail web interface

  • Tutorial
Without quality testing, it is impossible to develop and maintain a large web service. In the early stages of its development, it is often possible to do only manual testing according to a given test plan, but with the advent of new features and an increase in the number of test cases it becomes more and more difficult to be content with it. In this article, we will talk about how we automate functional testing of the Yandex.Mail web interface using Selenium WebDriver and Node.js.


In addition to Selenium WebDriver, there are several solutions for automatic testing of web interfaces, including Watir , Zombie.js , PhantomJS. But it was he who became practically the standard. Firstly, it has good functionality. And secondly, there are drivers for it for all common browsers - including mobile ones - and platforms, which can not be said about headless-tools (Zombie.js, PhantomJS).

And why exactly Node.js? Because all Yandex.Mail front-end developers know JavaScript, namely they develop the interface and understand where and what changes in it from release to release.

Installation and setup

To install and configure Selenium WebDriver on a local machine, you will need:

  1. Java ( ).
  2. Selenium server (download the standalone version here - ).
  3. Node.js + npm ( ).
  4. ChromeDriver (for testing in Google Chrome). It sways from here: .

After installing all the dependencies you need:

  1. Install selenium-webdriver for Node.js:
    npm install selenium-webdriver -g

  2. Launch selenium server:
    java -jar selenium-server-standalone-{VERSION}.jar

First test

For an example, we will write a simple test (test.js):

var wd = require('selenium-webdriver');
var assert = require('assert');
var SELENIUM_HOST = 'http://localhost:4444/wd/hub';
var URL = '';
var client = new wd.Builder()
   .withCapabilities({ browserName: 'firefox' })
client.get(URL).then(function() {
    client.findElement({ name: 'text' }).sendKeys('test');
    client.findElement({ css: '.b-form-button__input' }).click();
    client.getTitle().then(function(title) {
        assert.ok(title.indexOf('test — Яндекс: нашлось') > -1, 'Ничего не нашлось :(');

The code is pretty simple:

  1. We connect selenium-webdriver;
  2. We initialize the client with the desired browser and transfer the host on which we have selenium-server;
  3. We open;
  4. After loading, enter in the search line ( ) посимвольно “test” и кликаем на кнопку (она будет найдена по CSS-селектору ‘.b-form-button__input');
    We get the title of the page of search results and look for the substring 'test - Yandex: found' in it.

  5. - Selenium documentation. - WebDriver.js documentation. is a draft of the WebDriver API specification.

Also popular now: