📜 ⬆️ ⬇️

If you don't have a dog ...

If your business needs BDD with live documentation in Russian, there is no dedicated tester position, or its level of knowledge is insufficient for self-automation and it is important to provide a single stack of technologies between scrum teams, then you definitely need to connect our Akita library at least once and check it in action.
Before embarking on stories about what the Akita library is, I would like to tell you how we got to the idea of ​​its implementation, what problems we wanted to solve and what we ended up with.

The article was prepared by Anna Anna -che , Alice Mutaliska and Xenia KseMish .

What did you want?


Like many companies that want to continuously deliver high-quality software to the user, we wanted to introduce Continuous Delivery, which could allow us to deliver ready-made functionality fully covered in tests and with up-to-date documentation in one sprint. But during the transition to the CD, we encountered a number of features of our development process.

What happened?


  1. A large number of scrum teams.
  2. High resource costs.
  3. Long regression.

After analyzing these features, we did not give up, but found for ourselves two options of actions that would allow us to embark on the Continuous Delivery path:
')
  1. In each team to attract one developer auto tests.
  2. Teach your team testers (and not only them) to write autotests.

The first option did not suit us because there are not so many free autotest developers on the market, and this is expensive. But the second interested us with its efficiency and scalability.

What should be done?



What happened?


Akita was born. Akita Library, named after the breed of the notorious dog from the movie “Hachiko”. We associate this name with a faithful friend who is always ready to come to the rescue and protect our systems from a large number of defects.

Currently, Akita consists of more than 60 implemented steps, using which, we can already assume that you are automating the testing of your web application.

How does it work?


Akita is a BDD-library of steps for test automation. BDD is a development methodology based on a description of user behavior. That is, there is a person (or people) who writes descriptions of the form “I, as a user, want to see a schedule of monthly expenses when I click on the 'for a month' button to plan my future expenses”. Such a description serves as an entry point to the development. To describe the script steps in the BDD framework, the keywords given are used, given, when, then (given, when, then respectively).

In the library, tests are written in Russian and represent user scripts that can act as user documentation for an application. Each user script consists of steps, which, in turn, are tied to specific java-methods, where the implementation is carried out.


The project template using the library is quite simple and looks like this:


The main components of the template using Akita are feature files, steps (hereinafter referred to as steps) and web pages (hereinafter referred to as pages). The feature files describe the list of scripts (tests) with which we cover our system, and they will be launched later. Steps stores the developed methods that are associated with the steps described in the feature-files. Description of web-pages with their elements are in the package pages.

In order to understand the principle of working with the library, we suggest to consider the following example.

Any member of the scrum team (in our case, an analyst or tester) creates a user scenario (user story), which, later, can act as a development task, as a set of tests for autotests, and also as user documentation.
For example, we have a user story: “The Alfa-Bank user logs in to the Alfa-Click system using a login / password to see his accounts.”

A tester (or other team member) needs to:

1. Create a java gradle project and add the following entities to the dependencies:


2. Transfer custom scripts to a .feature project file using ready-made steps from the Akita library. After this, our feature file will look like this:

:   - :    -        " "   "http://alfabank.ru"    ""   "login"    ""   "password"      ""   "-"  

3 Create a Page Object for the pages with elements you want to work with: the login page and the main Alpha Click page. Create a class for the Login page in the pages package:

 @Name(" ") public class LoginPage extends AkitaPage { @FindBy(id = "login") @Name("") private SelenideElement login; @FindBy(id = "password") @Name("") private SelenideElement password; @FindBy(id = "submit") @Name("") private SelenideElement submitButton; } 

Here it is important to inherit from AkitaPage and hang the @Name annotation over the class and page elements with their key description, which we use in the .feature file. Similarly, you need to describe all the pages that will be involved in the checks.

After we have described all the pages, the question arises: “But how can you understand that the page has loaded?”. In the step “Then the“ Alpha-Click ”page is loaded”, the “Alpha-Click” page is set as current and all SelenideElements are searched. If all items are found, then the page has loaded.

The implementation of this step in the library looks like this:

 /** *  ,   ,        @Name,    @Optional    *   WAITING_APPEAR_TIMEOUT,     "waitingAppearTimeout"  application.properties.    ,    8  */ @("^(?:|||) \"([^\"]*)\" (?:|)$") public void loadPage(String nameOfPage) { akitaScenario.setCurrentPage(akitaScenario.getPage(nameOfPage)); akitaScenario.getCurrentPage().appeared(); } 

If an element belongs to a page, but may not be displayed immediately upon loading (for example, a message about incorrectly entered data), then it should not be involved in the decision to load and is annotated with @Optional, i.e. It is not required.

4. Run the test.

You can run tests in different ways:


> gradlew clean test -i
> gradlew clean test -Pbrowse=chrome -Pprofile=local -PremoteHub=http://remote/wd/hub
> gradlew clean test -Dbrowser=chrome -Ptag=@test


For projects there is a parallel launch of all feature files (a separate runner is created for each feature file), running tests on a remote machine (-PremoteHub), changing browser (-Pbrowser = chrome), running tests according to scripted tags (-Ptag) .

To get a report after running the tests, you need to run the following commands in the terminal:

> gradlew generateCucumberReport
> gradlew gCR


As a result, a standard Cucumber report (build / reports) is generated:


And that's all. Our user story is covered with tests, user documentation is generated and a test report is generated.

To try to work with Akita, you can download a ready-made template project on github (Akita-testing-template) .

After analyzing the main problems faced by test automation, we have included the following features in Akita:

1. Work with REST requests


In the library, you can send REST requests and save responses to a variable. Akita supports the following types of requests:

GET | POST | PUT | DELETE

And in the table of variables you can use the types: header, Parameter, body.

For the body-parameter, the work is organized with the request body, stored in the requestBodies folder, and with the body text in the step in the corresponding cell. The values ​​of the parameters of the table and the parts of the url can be specified in the application.properties . Example step with REST:


2. Using variables


Sometimes there is a need to use values ​​from one step in subsequent ones. To do this, implemented a variable store in AkitaScenario. To save / remove variables, use the setVar / getVar methods.

Saving variable in storage:

akitaScenario.setVar(< >, < >);

Getting variable value from storage:

akitaScenario.getVar(< >)

3. Storage of test data


To specify additional parameters or test data, you need to create an application.properties file in your project in main / java / resources.

What did you do?


Having studied all the technologies used and their analogues, we came to the following stack: Java + Gradle + Selenide + Cucumber.

We use Java and Gradle at Alfa-Bank, so there wasn’t any special choice here.

Cucumber has replaced JBehave, since Cucumber is easier to work with and has a large enough community, which makes it much easier to use.

The Selenide library makes it easy to work with the browser, timeouts, dynamic pages and Ajax requests. Andrei Solntsev, the author of Selenide, noted our library in his LiveJournal and gave some valuable advice on reviewing the original code.

What are the benefits?


Using the Akita library brought the following results:

  1. The entry threshold for a new employee has decreased (at present, the initial onboarding takes 1-2 days, free orientation in the tool is reached in 2 weeks, since knowledge of the programming language should be minimal to use the basic features of the library).
  2. A single tool has been installed to automate the testing of web applications (currently, more than 20 teams in Alfa-Bank use the library).
  3. Acceptance + regress takes no more than an hour (due to the fact that most of the functionality - about 80% is covered by autotests, the regression is much faster).

Akita every day, from sprint to sprint helps us to inform users of all the better product. So we can say with confidence that if you have our library, then automating testing will be much more interesting and easier.

Already say


Akita was the subject of conversation at the Heisenbug conferences (December 8-9, 2017, Moscow) and Delex (February 17, 2018, Minsk). Already on March 2 and 3, Selenium Camp will take place in Kiev, where we will once again tell and demonstrate how to work with Akita.

We consider our big victory to be that thanks to the Akita library, the guys from our “alfalab” team won first place at the international testing automation Hackathon (October 20, 2017, Vilnius), having managed to demonstrate how much you can speed up and simplify the test automation implementation.

If you don't have a dog ... you can download it on github: Akita library, and also download the akita-testing-template template for a quick start.

In addition, Akita has its own community in Telegram . Join us!

If you want to become one of Alfa-Bank testers (or not just a tester), we have open vacancies .

Source: https://habr.com/ru/post/350238/


All Articles