📜 ⬆️ ⬇️

Automation of acceptance testing of Selenium + .NET Web Api + AngularJs


I will tell you how we in the company work with acceptance tests. In the article you will find a link to the repository with the code and video with the example of work.

Not all tests are equally useful.


Some time ago, the dispute was relevant - “Should a developer test his code?”. Yes, the developer should test what he creates. I think that now with this statement very few people will argue.

The next question was - “How should a developer test his code?”. The answer to this question was found - TDD. In an ideal world, the developer develops most of the functionality through tests. As a result, we get a good design of the code, which is convenient to maintain and modify, plus a set of test cases that allow the developer to calmly make changes to the existing code.

It happens in a perfect world. In fact, it does not always work out all the development through testing. Even if all development is done using TDD, we still can’t say that the system being developed will start to work properly at the customer.
')
Unit tests do not affect the environment - if you need to test a service that appeals to the database for data, the developer writes a stub for the database. If you need to check the service that accesses the external service, the developer writes a stub that emulates the work of this service.

The next step is the configuration and integration tests, which bring into the virtual test environment the physical elements of the system - the database server, hardware firewalls, third-party software. The implementation of such tests allows us to say that the system “correctly” interacts with the environment. But even the “right” interaction with the environment does not guarantee us that the system will eventually work as expected - according to the scenarios that are described in the specification.

As my practice shows, acceptance testing is the most useful test. By acceptance testing, I understand the following:


If you manage to raise such a platform (which is often difficult to do), and check all test cases according to specification scenarios, then with high probability we can say that the system is working as expected and as a result does not contain errors.

Of course, there will be errors, but performing acceptance testing makes it more likely (compared to unit testing and integration testing) to detect errors.

Automate acceptance testing


Automation of acceptance testing is reduced to the following steps:


Acceptance Test Scenarios


We write acceptance test scripts in the form of use case scripts in specifications. The specification is developed by the analyst based on functional, user, non-functional and other requirements.

To maintain specifications, we use Atlassian Confluence in conjunction with the Balsamiq Mockups .

Development of tests based on Selenium


To develop tests, we created our own solution, which allows:


The development of new tests is reduced to the description of the test pages - PageObject and the development of test case steps.

The project with acceptance tests looks like this:


Main components:


The test consists of steps - Step (). A step can perform an action and check the execution of some statement. The following is an example test:


Test code:


The video shows the test.


If an error occurred during the test - the authorization failed, the report did not open, etc., then a screenshot of the page, browser name, test name and html error page will be saved to the directory specified in app.config.

Determining the completion of all $ http requests for an AngularJS application


Client SPA application performs server requests using the $ http service. For example, when you open the “Daily report” report, an asynchronous call to the server is performed. In response, the client receives report data from the server.

In test scenarios, you must be able to wait for the completion of all requests. For example, after the transition to a report, the client application takes time to download data from the server. After the data is loaded and displayed on the page should be tested this page.

To track the completion of all $ http requests, I use the following approach:


Running Acceptance Tests with TeamCity


As a continuous integration server, we use TeamCity.

After the developer has sent the code to the repository - TeamCity deploys the test site and runs acceptance tests on it. Thus, after each code change, the project is installed and tested from scratch. This solution is a great time saver plus allows us not to think about regression testing.

Basic steps:


Who writes acceptance tests


Acceptance tests can be written either by the developer, upon completion of the script implementation, or by a testing engineer specifically assigned to these tasks.

Source


The source code of the test application is available on github .

Conclusion


Automate acceptance testing can and should be. Advantages of this approach:


At the end of the article I will say that for large and long projects that last half a year or more - the presence of automated acceptance tests is a necessary condition for ensuring the required quality of the product.

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


All Articles