Professional Documents
Culture Documents
www.qaitive.rs
Content
Table of Contents
WHAT IS AUTOMATION TESTING? 3
SELENIUM 5
WHAT IS WEBDRIVER? 5
Selenium Commands 22
Instantiating Web Elements 22
Select tag 27
CUCUMBER 28
WHAT IS A "FEATURE FILE"? 28
www.qaitive.rs
GHERKIN 29
Feature file in detail 30
Scenario 30
Steps 31
Given 31
When 31
Then 31
Scenario Outline 31
Step Definitions 32
Steps Definitions 33
Example of Step Definition File 34
Excercise 34
JENKINS 39
What is Jenkins? 39
Example for Jenkins job 39
Automation Testing means using an automation tool to execute your test case suite.
The automation software can also enter test data into the System Under Test , compare expected and
actual results and generate detailed test reports.
Successive development cycles will require execution of same test suite repeatedly.
Using a test automation tool it's possible to record this test suite and re-play it as required.
Goal of Automation is to reduce number of test cases to be run manually and not eliminate Manual Testing
all together.
www.qaitive.rs
Manual Testing of all work flows, all fields , all negative scenarios is time and cost consuming
It is difficult to test for multi lingual sites manually
Automation does not require Human intervention. You can run automated test unattended
(overnight)
Automation increases speed of test execution
Automation helps increase Test Coverage
Manual Testing can become boring and hence error prone.
Test cases to be automated can be selected using the following criterion to increase the automation
ROI
The following category of test cases are not suitable for automation:
Test Cases that are newly designed and not executed manually atleast once
Test Cases for which the requirements are changing frequently
Test cases which are executed on ad-hoc basis.
www.qaitive.rs
Scope of automation is the area of your Application Under Test which will be automated. Following
points help determine scope:
SELENIUM
Selenium is a free (open source) automated testing suite for web applications across different
browsers and platforms.
WHAT IS WEBDRIVER?
WebDriver is a web automation framework that allows you to execute your tests against different
browsers, not just Firefox.
WebDriver also enables you to use a programming language in creating your test scripts.
Java
.Net
PHP
www.qaitive.rs
Python
Perl
Ruby
You do not have to know all of them. You just need to be knowledgeable in one. However, in this
tutorial, we will be using Java with IntelliJ IDEA as our IDE.
Selenium Grid uses a hub-node concept where you only run the test on a single machine called a
hub, but the execution will be done by different machines called nodes.
You should use Selenium Grid when you want to do either one or both of following:
Run your tests against different browsers, operating systems, and machines all at the same
time. This will ensure that the application you are Testing is fully compatible with a wide
range of browser-OS combinations.
Save time in the execution of your test suites. If you set up Selenium Grid to run, say, 4 tests
at a time, then you would be able to finish the whole suite around 4 times faster.
www.qaitive.rs
The Hub
The hub is the central point where you load your tests into.
There should only be one hub in a grid.
The hub is launched only on a single machine, for example, a computer whose OS is
Windows 7 and whose browser is IE.
The machine containing the hub is where the tests will be run, but you will see the browser
being automated on the node.
The Nodes
Nodes are the Selenium instances that will execute the tests that you loaded on the hub.
There can be one or more nodes in a grid.
Nodes can be launched on multiple machines with different platforms and browsers.
The machines running the nodes need not be the same platform as that of the hub.
1. MAVEN
2. JDK
Maven - http://www-us.apache.org/dist/maven/maven-3/3.5.2/source/apache-maven-3.5.2-src.zip
JDK - http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
When you do that, first you need to unzip maven file that you download in C root on your windows
operating system like on pictures below.
www.qaitive.rs
Next you need to install JDK file, there is no need for additional settings during installation.
If you've successfully done these steps, we need to setup windows path to them.
Go through the Control panel, enter the System option. Follow the pictures below.
www.qaitive.rs
When you open Environment Variables click on New button, follow the pictures below.
www.qaitive.rs
www.qaitive.rs
www.qaitive.rs
If you get a result from an image, this means that you have successfully created the path.
During the Firewall selection process your Windows will ask you for IDEAS privileges, there will be
two checks.
www.qaitive.rs
In the next window that opens you must enter the name of the project, ie. Groupid and Artifacid
names must be the same without spaces. See the picture below.
www.qaitive.rs
www.qaitive.rs
Do Next and the window you need to confirm will open again.
You will start the Idea and open a pom.xml file in which you need to enter Dependency, and before
that, in the lower right corner, you will receive a message to approve the enable auto imoport and
you must allow it.
See the image below where you need to enter the next Dependency.
You must find on left side panel file with name POM, you open this file and input Dependency.
www.qaitive.rs
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.12.0</version>
<scope>test</scope>
</dependency>
</dependencies>
When you do, the Idea will start retrieving selenium files that will last for a few minutes, no more
than 5 minutes, you can follow the process at the bottom right of the application.
Go to https://www.seleniumhq.org/download/
Find and click Google Chrome Driver
Click latest release, again one more time
Click version for your operating system
Put it into root folder of your project
Instantiating objects and variables
This is how a driver object is instantiated.
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver = new ChromeDriver();
www.qaitive.rs
A ChromeDriver class with no parameters means that the default Chrome profile will be launched
by our Java program. The default Chrome profile is similar to launching Chrome in safe mode (no
extensions are loaded).
www.qaitive.rs
https://www.w3schools.com/tags/
https://www.w3schools.com/tags/ref_attributes.asp
Some are general, meaning that those can be applied to any element:
https://www.w3schools.com/tags/ref_standardattributes.asp
https://www.w3schools.com/tags/tag_input.asp
Types of locators
There are 8 types of locators available in Selenium:
www.qaitive.rs
xpath
driver.findElement(By.xpath("value"));
name
driver.findElement(By.name("value"));
class name
driver.findElement(By.className("value"));
tag name
driver.findElement(By.tagName("value"));
link text
driver.findElement(By.linkText("value"));
partial link text
driver.findElement(By.partialLinkText("value"));
Inspect
Element inspector exists in any browser. Just right-click an element and select Inspect. New pane will give us
the info we need, however we do not know number of results and can‘t check locator using it.
Ranorex Selocity
Best tool available at the moment. Before we had FirePath and FireBug in Firefox, but those are deprecated
and will not work in FireFox version 48 and later.
https://www.ranorex.com/selocity/browser-extension/
Install this extension in Chrome and there will be a new tab in Element console. Easiest way to activate it is
by right clicking an element and selecting ‘Inspect’.
CSS locators
For this exercise we will use google.com
To get an element or a list by the tag name we just use that tag. Open Selocity and enter ‘input’.
There will be multiple results that we can scroll by clicking left and right arrows. It is a rare that we
www.qaitive.rs
can successfully locate an element just by using tag names and we usually need to use other
properties as well.
Notice that elements also have different attributes. Those are all other values besides tag name.
This one has: ‘class’, ‘id’, ‘dir’ and ‘style’ that we can use. We create locator by using:
[attributeName='attributeValue']
For example: [class='gsst_b sbib_c']
Enter it into Selocity and it will find the element.
Note that all other element attributes can be selected using this way. For example:
[id='gs_st0']
Special cases are ID and Class attributes. For ID instead of [id='gs_st0'] we can use #gs_st0
And for Class [class='gsst_b'] we use .gsst_b sbib_c
Note the dot (.) in front of the class name. For class names that have spaces we replace spaces with
dots, too. For example [class='gsst_b sbib_c'] can be .gsst_b.sbib_c
Chaining
Sometimes it is not enough to use just one attribute. In that case we chain locators. We can chain a
tag name with one or more attributes and we can chain multiple attributes. Chaining is performed
by entering 2 or more values and their respective values by the following formula:
tagName[attributeName='attributeValue'][attributeName='attributeValue']
Note that there is no space beetween brackets.
www.qaitive.rs
XPath
Xpath is short for XML Path Language and is similar to the CSS as we will use it to locate elements but it
works very differently. It has relative and absolute nomenclature. One slash (/) is beginning from the root of
the DOM and double slash (//) works anywhere in the document. Remember that double slash can also be
used anywhere in the locator. One of the issues with XPath is that can be fragile.
- absolute XPath:
/html[1]/body[1]/div[1]/div[3]/form[1]/div[2]/div[2]/div[1]/div[1]/div[2]/div[1]/div[1]/div[2]/div[1]/i
nput[1]
- relative XPath
format: //tagName[@attributeName='attributeValue']
example: //input[@id='lst-ib']
- contains
format: //tagName[contains(@attributeName, 'attributeValue')]
example: //input[contains(@id,'t-i')]
www.qaitive.rs
- starts with
format: //tagName[starts-with(@attributeName, 'attributeValue')]
example: //input[starts-with(@id,'lst')]
- * for tagname
format: //*[@attributeName='attributeValue']
example: //*[@id='lst-ib']
- * for attribute
format: //tagName[@*='attributeValue']
example: //input[@*='lst-ib']
- text
format: //tagName[text()='elementText']
example: //*[text()='Images']
- contains text
format: //tagName[contains(text(), 'partialElementText')]
example: //*[contains(text(),'Abou')]
- nth of element
format: //tagName[@attributeName='attributeValue'][number]
example: //span[@id='fsl']/a[1]
Selenium Commands
Instantiating Web Elements
Instead of using the long "driver.findElement(By.locator())" syntax every time you will access a
particular element, we can instantiate a WebElement object for it. The WebElement class is
contained in the "org.openqa.selenium.*" package.
Clicking on an Element
www.qaitive.rs
Clicking is perhaps the most common way of interacting with web elements. The click() method is
used to simulate the clicking of any element. The following example shows how click() was used to
click on Mercury Tours' "Sign-In" button.
Entering text
driver.findElement(By.id("locator")).sendKeys(“textToEnter”);
Get Commands
Get commands fetch various important information about the page/element. Here are some
important "get" commands you must be familiar with.
Implicit Wait
www.qaitive.rs
To start using an implicit wait, you would have to import this package into your code.
Explicit Wait
Explicit waits are done using the WebDriverWait and ExpectedCondition classes. For the following
example, we shall wait up to 10 seconds for an element whose id is "username" to become visible
before proceeding to the next command. Here are the steps.
Step 1
Import these two packages:
Step 2
Declare a WebDriverWait variable. In this example, we will use "myWaitVar" as the name of the
variable.
www.qaitive.rs
Step 3
Use myWaitVar with ExpectedConditions on portions where you need the explicit wait to occur. In
this case, we will use explicit wait on the "username" (Mercury Tours HomePage) input before we
type the text "tutorial" onto it.
Conditions
isEnabled() is used when you want to verify whether a certain element is enabled or not
before executing a command.
isDisplayed() is used when you want to verify whether a certain element is displayed or not
before executing a command.
isSelected() is used when you want to verify whether a certain checkbox, radio button, or
option in a drop-down box is selected. It does not work on other elements.
Using ExpectedConditions
www.qaitive.rs
The ExpectedConditions class offers a wider set of conditions that you can use in conjunction with
WebDriverWait until() method.
elementToBeClickable() - Waits until an element is visible and, at the same time, enabled.
The sample code below will wait until the element with id="username" to become visible
and enabled first before assigning that element as a WebElement variable named
"txtUserName".
Catching Exceptions
When using isEnabled(), isDisplayed(), and isSelected(), WebDriver assumes that the element
already exists on the page. Otherwise, it will throw a NoSuchElementException. To avoid this, we
should use a try-catch block so that the program will not be interrupted.
www.qaitive.rs
If you use explicit waits, the type of exception that you should catch is the "TimeoutException".
Select tag
Select class is used for select tagname and has a special treatment in Selenium. First we initialize it:
select.selectByVisibleText("text");
select.selectByIndex(number);
select.selectByValue("value");
select.deselectAll;
select.deselectByVisibleText("text");
select.deselectByIndex(number);
select.deselectByValue("value");
www.qaitive.rs
Excercises:
http://the-internet.herokuapp.com/forgot_password
http://the-internet.herokuapp.com/login
http://toolsqa.com/automation-practice-form/
CUCUMBER
Before we learn about Cucumber, lets understand BDD
What is Behaviour Driven Development?
The general tendency of developers is to develop features and write test code later. As, evident in
above case, Test Case development for this case is complex and developer will put off Testing till
release , at which point he will do quick but ineffective testing.
To overcome this issue (Behavior Driven Development) BDD was conceived. It makes the entire
testing process easy for a developer.
In BDD, whatever you write must go into Given-When-Then steps. Let's consider the same example
above in BDD.
Given that a fund transfer module in net banking application has been developed
And I am accessing it with proper authentication
When I shall transfer with enough balance in my source account
Or I shall transfer on a Bank Holiday
Or I shall transfer on a future date
And destination a/c details are correct
And transaction password/rsa code / security authentication for the transaction is correct
And press or click send button
Then amount must be transferred
And the event will be logged in log file
Isn't it easy to write and read and understand? It covers all possible test cases for the fund transfer
module and can be easily modified to accommodate more. Also, it more like writing documentation
for the fund transfer module.
www.qaitive.rs
Feature: A feature would describe the current test script which has to be executed.
Scenario: Scenario describes the steps and expected outcome for a particular test case.
Scenario Outline: Same scenario can be executed for multiple sets of data using scenario
outline. The data is provided by a tabular structure separated by (I I).
Given: It specifies the context of the text to be executed. By using datatables "Given", step
can also be parameterized.
When: "When" specifies the test action that has to performed
Then: The expected outcome of the test can be represented by "Then"
GHERKIN
Cucumber executes your .feature files, and those files contain executable specifications written in a
language called Gherkin.
Gherkin is plain-text English (or one of 60+ other languages) with a little extra structure. Gherkin is
designed to be easy to learn by non-programmers, yet structured enough to allow concise
description of examples to illustrate business rules in most real-world domains.
In Gherkin, each line that isn't blank has to start with a Gherkin keyword, followed by any text you
like. The main keywords are:
Feature
Scenario
Given, When, Then, And, But (Steps)
Background
Scenario Outline
Examples
www.qaitive.rs
A .feature file is supposed to describe a single feature of the system, or a particular aspect of a
feature. It's just a way to provide a high-level description of a software feature, and to group
related scenarios.
A feature has three basic elements---the Feature: keyword, a name (on the same line) and an
optional (but highly recommended) description that can span multiple lines.
Cucumber does not care about the name or the description---the purpose is simply to provide a
place where you can document important aspects of the feature, such as a brief explanation and a
list of business rules (general acceptance criteria).
Here is an example:
Scenario
A scenario is a concrete example that illustrates a business rule. It consists of a list of steps.
You can have as many steps as you like, but we recommend you keep the number at 3-5 per
scenario. If they become longer than that they lose their expressive power as specification and
documentation.
www.qaitive.rs
In addition to being a specification and documentation, a scenario is also a test. As a whole, your
scenarios are an executable specification of the system.
Steps
A step typically starts with Given, When or Then. If there are multiple Given or When steps
underneath each other, you can use And or But. Cucumber does not differentiate between the
keywords, but choosing the right one is important for the readability of the scenario as a whole.
Given
Given steps are used to describe the initial context of the system---the scene of the scenario. It is
typically something that happened in the past.
When Cucumber executes a Given step it will configure the system to be in a well-defined state,
such as creating and configuring objects or adding data to the test database.
It's ok to have several Given steps (just use And or But for number 2 and upwards to make it more
readable).
When
When steps are used to describe an event, or an action. This can be a person interacting with the
system, or it can be an event triggered by another system.
It's strongly recommended you only have a single When step per scenario. If you feel compelled to
add more it's usually a sign that you should split the scenario up in multiple scenarios.
Then
Then steps are used to describe an expected outcome, or result.
The step definition of a Then step should use an assertion to compare the actual outcome (what
the system actually does) to the expected outcome (what the step says the system is supposed to
do).
Scenario Outline
When you have a complex business rule with severable variable inputs or outputs you might end up creating
several scenarios that only differ by their values.
www.qaitive.rs
Let's take an example from feed planning for cattle and sheep:
If there are many examples, this becomes tedious. We can simplify it with a Scenario Outline:
Step Definitions
Cucumber doesn't know how to execute your scenarios out-of-the-box. It needs Step Definitions to
translate plain text Gherkin steps into actions that will interact with the system.
When Cucumber executes a Step in a Scenario it will look for a matching Step Definition to execute.
A Step Definition is a small piece of code with a pattern attached to it. The pattern is used to link
the step definition to all the matching Steps, and the code is what Cucumber will execute when it
sees a Gherkin Step.
www.qaitive.rs
The I have 48 cukes in my belly part of the step (the text following the Given keyword) will match
the Step Definition below:
Example:
Steps Definitions
We have got our feature file ready with the test scenarios defined. However, this is not the
complete job done. Cucumber doesn’t really know which piece of code is to be executed for any
specific scenario outlined in a feature file.
This calls the need of an intermediate – Step Definition file. Steps definition file stores the mapping
between each step of the scenario defined in the feature file with a code of function to be
executed.
www.qaitive.rs
So, now when Cucumber executes a step of the scenario mentioned in the feature file, it scans the
step definition file and figures out which function is to be called.
Example of Step Definition File
public void goToFacebook() {
driver = new FirefoxDriver();
driver.navigate().to("https://www.facebook.com/");
}
Excercise
In this exercise we’ll create a whole new project with cucumber. Also, we’ll create one standard Scenario and
one Scenario Outline. Scenario Outline takes data from example table and uses it a test data. Number of
rows determines how many times test will run with different inputs.
Test steps for Scenario will be to go to http://the-internet.herokuapp.com/login, login and assert page URL.
For Scenario Outline, just enter username and password from the row and stop, without closing the browser.
This way we will see how Scenario Outline works.
● First, install Cucumber plugin for InterlliJ IDEA. Go to File > Settings. Search for ‘plugins’. When plugin
option is selected on the right enter ‘cucumber’ into plugins search.
● Choose ‘Cucumber for Java’ and click Install. Confirm when asked to install Gherkin plugin, too.
● Create a new Maven project and check that directory test > java is colored green, if not right click it,
choose ‘Mark Directory as’ and select ‘Test Sources Root’
● Copy Chrome driver executable in project root
www.qaitive.rs
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
x si:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>QAserbia</groupId>
<artifactId>cucumber</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
www.qaitive.rs
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.12.0</version>
</dependency>
</dependencies>
</project>
● Create a new file in test > java named ‘login.feature’. Notice that file icon looks like a cucumber slice.
This means that file has been recognized as a cucumber feature file.
● Copy the following code into the file:
Feature: Login
www.qaitive.rs
| email2@gmail.com | pass1234 |
● This will be our Feature with 2 scenarios. First Scenario contains 4 steps and second just 2.
● Notice that our steps are highlighted yellow as we haven't implemented step definitions yet. To
create step definitions, right click any of the highlighted steps and select ‘Create all step definition’.
In the new window choose a file name (you can leave it default), make sure that Java and not Java 8
is selected in the dropdown and click OK.
● Step definition file will be created but when opened notice that it has Pending exception. If we try to
run feature file now, first step will fail and others will be skipped.
● Create a directory under test > java named ‘steps’ and move step definition file into it
● To fill the step definition file, overwrite the whole file with the following:
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
driver.get("http://the-internet.herokuapp.com/login");
}
www.qaitive.rs
driver.findElement(By.id("username")).sendKeys("tomsmith");
driver.findElement(By.id("password")).sendKeys("SuperSecretPassword!");
}
driver.findElement(By.cssSelector(".radius")).click();
}
Assert.assertEquals(driver.getCurrentUrl(), "http://the-internet.herokuapp.com/secure");
driver.quit();
}
driver.findElement(By.id("username")).sendKeys(email);
driver.findElement(By.id("password")).sendKeys(password);
}
● Notice that driver config is set to ‘chromedriver.exe’ if using Mac or Linux just delete ‘.exe’
● Got back to feature file. Right click Feature keyword and select Create Feature login
● In the new window check that under Glue option is filled ‘steps’. If not, enter manually
● Click OK
● Run the test config (green arrow in top left corner)
● Result summary should be similar to following:
3 Scenarios (3 passed)
www.qaitive.rs
8 Steps (8 passed)
0m10.786s
Process finished with exit code 0
DataTables
This is a specific data provider in Cucumber as it passes the whole table (hence the name):
Note: in Java counting lists starts from 0, not 1, so the first row/column is numbered 0, second is numbered
1, and so on.
JENKINS
What is Jenkins?
www.qaitive.rs
Download Jenkins WAR file from the https://jenkins.io/download/. There are 2 columns: Long-term
Support (LTS) and Weekly. Scroll LTS column all the way down and download the file using Generic
Java package (.war) link.
Open command prompt (or terminal) and navigate to the location that WAR package is saved. Run
the following command to start Jenkins server:
java -jar jenkins.jar
Note: do not close the command prompt until whole example is finished. Otherwise Jenkins
server will be stopped.
After a couple of second you’ll see ‘INFO: Jenkins is fully up and running’ in your command prompt.
Open your browser and go to http://localhost:8080/. That is a start page for Jenkins.
There will be a file path painted in red. Go to that location, open the file with any text editor and
copy the code. Go back to browser and paste that code into input field named ‘Administrative
password’. Click Continue.
On the next screen there will be a choice what plugins to install. Just click on ‘Install suggested
plugins’. This will take a few minutes to complete. This is the screen that you will see during the
plugin installation:
www.qaitive.rs
After couple of minutes plugin installation will be complete and you will be prompted with the
following screen:
Enter desired username, password, full name and email. Click ‘Save and Continue’
If you get the following screen, just click ‘Save and Finish’:
www.qaitive.rs
On the Welcome screen click Manage Jenkins on the right, then Manage plugins in the middle of
the screen. On the new screen click tab called Avaliable. Enter Analylzer in the Filter field. Find Test
Results Analyzer and mark checkbox next to it. Click button Download now and install after restart.
Next screen is called Installing Plugins/Upgrades. Just mark the checkbox next to text Restart
Jenkins when installation is complete and no jobs are running. Refresh the page after about 10
seconds and login screen should appear. This means that Jenkins has been restarted. Login with
your credentials.
On the next screen click Create new jobs in the middle of the screen. In the Enter an item name
type name of the Jenkins job, for example Selenium01. Click Freestyle project option and click OK.
New job will be created.
Next screen is our job configuration. Scroll down to the heading called Build and click the button
called Add build step. If you are using a Windows operating system select option: Execute Windows
batch command and if you are using a Linux or a Mac choose: Execute shell from dropdown.
New windows called Command will be shown. Enter the following command:
mvn clean test
www.qaitive.rs
Next, scroll down to Post-build Actions and click Add Post-build Action dropdown. Choose Publish
JUnit test result report. In the Test report XMLs field just add:
target/surefire-reports/*.xml
Click Apply and Save and our Jenkins project is configured.
Next screen is the main screen of our project. Run job once for the workspace by clicking Build Now
button from the left hand menu. This is used to create job workspace.
Now, we will create a project and copy it into Jenkins workspace folder. Create Maven project with
the GroupID and ArtifactID of your choice. Copy driver executable for your operating system into
the project root folder.
Copy the following code into your pom.xml over the existing code:
<groupId>komocija</groupId>
<artifactId>jenkins</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
www.qaitive.rs
<artifactId>selenium-java</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Then, create new java class called JenkinsTest and copy the following code into it:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
www.qaitive.rs
WebDriver driver;
@Test
public void jenkinsOne() {
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.google.com/");
Assert.assertEquals(1, 1);
driver.quit();
}
}
Note: for Mac and Linux systems use chromedriver instead of chromedriver.exe
Open the location that the project is in and copy all files inside the main folder.
Then open your Jenkins installation path (your home directory/.jenkins) and note that folder is
hidden. There will be a folder called Jenkins then a folder named after your Jenkins job name. Open
it and copy the files that you copied from project folder.
www.qaitive.rs
After than just go to Jenkins again and run build again. When finished click Test Results Analyzer link
on the left hand menu to display test results.
Note: Use annotations sparingly and with a purpose. If used incorrectly, annotations provide more harm
than good.
Uploading files
This a very simple operation. We just perform sendKeys command on an element that is used to upload file
(usually a some kind of button). Then, in the sendKeys parameters we specify absolute path to the file. For
example:
www.qaitive.rs
No software is bug free or perfect and the same goes for IDEs. Sometimes the cache of the IDE is stuck and
can’t be used. In that case just perform File > Invalidate caches/Restart > Invalidate and Restart. After caches
are deleted, IDE will restart and rebuild cache.
Browser versions are upgraded frequently and we need to provide appropriate driver in order to use those
new browser versions. Sometimes we don’t but sometimes we do need to update our Selenium driver and
appropriate dependencies. To do that, just go to mvnrepository.com and search for needed dependency.
After dependency is found, we can check if newer version has been published. Please note that we also need
to update linked dependencies.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.12.0</version>
</dependency>
www.qaitive.rs