Selenium
How to Find All/Broken links using Selenium Webdriver
What are Broken Links? Broken links are links or URLs that are not reachable. They may be down or...
Jenkins is the leading open-source continuous integration tool developed by Hudson lab. It is cross-platform and can be used on Windows, Linux, Mac OS and Solaris environments. Jenkins is written in Java. Jenkin's chief usage is to monitor any job which can be SVN checkout, cron or any application states. It fires pre-configured actions when a particular step occurs in jobs.
In this tutorial, we will learn
Selenium WebDriver is great for browser automation. But, when using it for testing and building a test framework, it feels underpowered. Integrating Maven with Selenium provides following benefits
Apache Maven provides support for managing the full lifecycle of a test project.
For this tutorial, we will use Eclipse (Juno) IDE for Java Developers to set up Selenium WebDriver Project. Additionally, we need add m2eclipse plugin to Eclipse to facilitate the build process and create pom.xml file.
Let's add m2eclipse plugin to Eclipse with following steps:
Step1) In Eclipse IDE, select Help | Install New Software from Eclipse Main Menu.
Step 2) On the Install dialog, Enter the URL http://download.eclipse.org/technology/m2e/releases/. Select Work with and m2e plugin as shown in the following screenshot:
Step 3)Click on Next button and finish installation.
Configure Eclipse with Maven
With m2e plugin is installed, we now need create Maven project.
Step 1) In Eclipse IDE, create a new project by selecting File | New | Other from Eclipse menu.
Step 2) On the New dialog, select Maven | Maven Project and click Next
Step 3) On the New Maven Project dialog select the Create a simple project and click Next
Step 4) Enter WebdriverTest in Group Id: and Artifact Id: and click finish
Step 5) Eclipse will create WebdriverTest with following structure:
Step 6) Right-click on JRE System Library and select the Properties option from the menu.
On the Properties for JRE System Library dialog box, make sure Workspace default JRE is selected and click OK
Step 7). Select pom.xml from Project Explorer..
pom.xml file will Open in Editor section
Step 8) Add the Selenium, Maven, TestNG, Junit dependencies to pom.xml in the <project> node:
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.45.0</version> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.8.8</version> <scope>test</scope> </dependency> </dependencies>
Step 9) Create a New TestNG Class. Enter Package name as "example" and "NewTest" in the Name: textbox and click on the Finish button as shown in the following screenshot:
Step 10). Eclipse will create the NewTest class as shown in the following screenshot:
Step 11) Add the following code to the NewTest class:
This code will verify the title of Guru99 Selenium Page
package example; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.Assert; import org.testng.annotations.Test; import org.testng.annotations.BeforeTest; import org.testng.annotations.AfterTest; public class NewTest { private WebDriver driver; @Test public void testEasy() { driver.get("http://demo.guru99.com/test/guru99home/"); String title = driver.getTitle(); Assert.assertTrue(title.contains("Demo Guru99 Page")); } @BeforeTest public void beforeTest() { driver = new FirefoxDriver(); } @AfterTest public void afterTest() { driver.quit(); } }
Step 12) Right-click on the WebdriverTest and select TestNG | Convert to TestNG.
Eclipse will create testng.xml which says that you need to run only one test with the name NewTest as shown in the following screenshot:
Update the project and make sure that file appears in the tree Package Explorer (right click on the project - Refresh).
Step 13) Now you need to run test through this testng.xml.
So, go to the Run Configurations and create a new launch TestNG, select the project and field Suite as testng.xml and click Run
Make sure that build finished successfully.
Step 14). Additionally, we need to add
to pom.xml.
The maven-surefire-plugin is used to configure and execute tests. Here plugin is used to configure the testing.xml for TestNG test and generate test reports.
The maven-compiler-plugin is used to help in compiling the code and using the particular JDK version for compilation. Add all dependencies in the following code snippet, to pom.xml in the <plugin> node:
Step 15) To run the tests in the Maven lifecycle, Right-click on the WebdriverTest and select Run As | Maven test. Maven will execute test from the project.
Make sure that build finished successfully.
Installation
Step 1) Go to http://jenkins-ci.org/and download correct package for your OS. Install Jenkins.
Step 2) Unzip Jenkins to specified folder. Run exe file as shown in following screenshot:
Step 3) In Jenkins 1.607 Setup window click on Next button.
Step 4) Click on Install button in the end.
Step 5) Once installation is done, navigate to the Jenkins Dashboard (http://localhost:8080 by default) in the browser window.
Step 6) Click on the New Item link to create a CI job.
Step 7) Select the Maven project radio button as shown in the following screenshot:
Using the Build a Maven Project option, Jenkins supports building and testing Maven projects.
Step 6) Click on OK button. A new job with name "WebdriverTest" is created in Jenkins Dashboard.
Step 7) Go to Manage Jenkins => Configure System as shown in the following screenshot.
Click on JDK installations and configure JDK as in the following screenshot:
Step 8) Go to the Build section of new job.
Step 9) Click on Apply button.
Step 10) On the WebdriverTest project page, click on the Build Now link.
Maven will build the project. It will then have TestNG execute the test cases.
Step 11) Once the build process is completed, in Jenkins Dashboard click on the WebdriverTest project
Step 12) The WebdriverTest project page displays the build history and links to the results as shown in the following screenshot:
Step 13) Click on the "Latest Test Result" link to view the test results as shown in the following screenshot:
Step 14). Select specific build, and you will see the current status by clicking on "console output".
Scheduling builds(Selenium Tests) is one of the important features of Jenkins where it automatically triggers the build, based on defined criteria. Jenkins provides multiple ways to trigger the build process under the Build Trigger configuration.
For example:
Enter 0 23 * * * in the Schedule textbox as shown in the following screenshot. This will trigger the build process every day at 11 p.m.
To run pure TestNg script in Jenkins, enter the following in build
D:>java -cp "Pathtolibfolder\lib\*;Pathtobinfolder\bin" org.testng.TestNG testng.xml
What are Broken Links? Broken links are links or URLs that are not reachable. They may be down or...
In this tutorial, we will learn, Store commands, Echo commands, Alerts and Popup handling. Storing...
Robot Class Robot Class in Selenium is used to enable automated testing for implementations of Java...
Selenium Webdriver is limited to Testing your applications using Browser. To use Selenium...
What is an Object Repository? An object repository is a common storage location for all objects. In...
iFrame in Selenium Webdriver iFrame in Selenium Webdriver is a web page or an inline frame which...