📜 ⬆️ ⬇️

The path to continuous integration. Selenium + TeamCity

Entry


Consider integrating Selenium IDE tests into the continuous integration process using TeamCity. In many places I met when QA creates tests (at best, it often happens when clickers simply click on the project and make reports on the document) and run them regularly, and usually it all happens locally on his own computer. As I am absolutely not a systematic approach, which (now, in 2014) is decided by a million solutions for the full automation of the process.
Well, since Continuous Integration is such a popular practice, why not introduce functional testing into the process of continuous integration, make life easier for testers and raise the level of product quality in general.

What is needed and what we want


What is?

What do you want?


How to install, configure and make the first build configuration in the open spaces is more than necessary, because I will not describe, and this is not about that.
I ask under the cat.

Preparation and configuration of the build agent


As a build of the agent, the Windows machine is installed, on which the TeamCity Agent is installed and hooked up to the TeamCity server.
We do the following steps to adjust among for performance:
')
All manipulations will occur in "C: \ Selenium" because we create a directory of the same name there.
On this machine, the selenium server standalone should be raised, which, for convenience, would be good to install in Windows as a service, since the manual call is not quite comme il faut. You can do this using the nssm utility (“Non-Sucking Service Manager”).
Download, unpack and put in "C: \ Selenium".
We download selenium-server-standalone and put it in the same place (at the time of this writing, you can download it from here ).
Install Selenium Server as a service

C:\Selenium\nssm-2.16\win64\nssm.exe install Selenium-Server "C:\Program Files (x86)\Java\jre7\bin\java.exe" "-jar C:\Selenium\selenium-server-standalone-2.42.2.jar" 


We use NUnit as the “performer” of the build step (we will export the tests from the Selenium IDE to .cs and then compile it into the dll of the library), because we also install the .NET Framework 4 on the machine (if not, you can take it from here ).
After installation, look for the path to csc.exe, which lies in
 "C:\Windows\Microsoft.NET\Framework\v4.0.<    >" 
and write it into variables among for the possibility of a global call.
Install Mozilla Firefox as it will be used to connect settings.
In order for csc to compile the export tests, you need to download and put a certain number of additional libraries and put in "C: \ Selenium" (the compilation process will occur automatically from this directory). Here you can take them.
We download and unpack in "C: \ Selenium".

This completes the agent build preparation, you can proceed to the build configuration to run the tests.

TeamCity Configuration


We go to the admin TimSiti, and zhmakaam create a project, enter the name, id, description and "Create"

image

Go to the settings page of the new project, and click “Create Build Configuration”, fill in the familiar three fields and again the blue button

image

After creating a build of configuration, we get to the screen for selecting an existing repository, or, as in our case, since there are no connected repositories to create a new one. A good practice would be to “pick up” the repository with a live project (from it, take spelling tests and later compile and run them) in order to monitor changes in the repository and trigger changes to the code (continuous integration), but here I show “demo” , then we will connect the "left" repository, and we will not check it out. Our goal is to run tests and get a report.

We hook up any repository (as an option to open a repository from github / bitbucket), test the connection, and again “Create”:

image

We fall into the window with configuring the build repositories (I installed VCS checkout mode: as Do not checkout files automatically, so as not to monitor the unnecessary repository):

image

Getting to the most interesting. Here I will take two steps, the first will start the compilation of tests from source (.cs) into libraries for NUnit, and the second will start the tests by NUnit.

Go to the next tabu of the build settings “Build Steps”, and finish the first step with the “Add build step” button, in the “Runner type” list, look for the “Command Line” and select it. Enter the name of the step, insert the following into the script field:

 csc /t:library /r:WebDriver.Support.dll /r:WebDriver.dll /r:ThoughtWorks.Selenium.Core.dll /r:Selenium.WebDriverBackedSelenium.dll /r:nunit.framework.dll /r:System.Data.dll /r:System.Data.Services.Client.dll /out:"C:\Selenium\compiled_test.dll" "C:\Selenium\reg.cs" 

And click "Save"

The script will start the compiler, start the compilation of the exported test with the Selenium IDE, which lies along the path “C: \ Selenium \ reg.cs” and put the compiled library into the file “C: \ Selenium \ compiled_test.dll”, which we will pass to NUnit in the next step 'y

image

We add one more build step, only as runner we select already NUnit.
Fill in the screenshot and in Run tests from: set the path that the first step will put the compiled test, in our case “C: \ Selenium \ compiled_test.dll” - and save.

As a result, we get the following:

image

Congratulations, the minimum configuration is complete, it remains only to write the first test and run its execution.

Creation of the first test


We ask QA to click a simple test in Selenium IDE and export it to “ # / NUnit / Remote Control”.



The only thing that had to be corrected was the settings for connecting to the web browser.

I give an example of the test.

 using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using Selenium; namespace SeleniumTests { [TestFixture] public class open_page { private IWebDriver driver; private ISelenium selenium; private StringBuilder verificationErrors; [SetUp] public void SetupTest() { verificationErrors = new StringBuilder(); //driver = new FirefoxDriver(); -     driver = new FirefoxDriver(new FirefoxBinary(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"), new FirefoxProfile(), TimeSpan.FromMinutes(10)); //     firefox selenium = new WebDriverBackedSelenium(driver, "http://habrahabr.ru/"); selenium.Start(); } [TearDown] public void TeardownTest() { try { driver.Close(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.AreEqual(string.Empty, verificationErrors.ToString()); } [Test] public void TheOpen_pageTest() { selenium.Open("/"); selenium.Click("link= "); selenium.WaitForPageToLoad("30000"); } } } 


See the result


We go to TimCity in the click Run opposite our build, wait for the test and enjoy the result. Build green, 1 test passed.

image

PS As mentioned above, we write tests, put in the project repository, trigger the project build for each commit, pick up the tests after build, compile and run and, if successful, do post comit hook to push to the repository and maybe even deployment to the staging environment. And all this is completely automatic.

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


All Articles