Welcome back! Today we will make some tests using Selenium WebDriver. All you need is to download Eclipse IDE For
Java EE Developers and Selenium from our previous post.
First step: Installation and configuration
First step: Installation and configuration
Once you
have downloaded Selenium you have to decompress the downloaded file. You will find two different files .jar with
the name of selenium -java-2.35.0.jar and selenium-java-2.35.0-srcs.jar. The
name can change depending of the downloaded version of the tools, these files
have to be copied on the libs folder of selenium.
Now that
you have copied the files in the libs folder, you can create a new project
in eclipse in which you can make some basic tests with the help of selenium.
First you go to eclipse then you go to File->New->Java Project.
The next
window will be displayed. Here you are going to write the project’s name. In
this example the name of the project is “Tests”.
Then,
you click on the Next button and you go to libraries.
You will see the next window, here
you click on the button that says Add External JARs, a window will appear in
which you have to select all the files .jar that are in the libs folder of
selenium.
Once you have selected all the .jar
files of selenium, you have to click on the finish button. The new project will
appear at the left side of the screen.
In the left side of the screen you will find a section that says
Referenced Libraries that contains all the files that you have selected
previously.
The configuration is done :)
We can start to write the tests, hooray!
Second step: Writing the test cases
Now we will do two simple tests:
We can start to write the tests, hooray!
Second step: Writing the test cases
Now we will do two simple tests:
- search a text in google
- obtain the title of the Google page.
To do the tests go to
File->New->JUnit Test Case.
You will see a new window in which you will have to
write the name of the JUnit Test Case, in this
case the name is “prueba” (it means test in our native language ;) ).
Once you have created the file, you
will be able to make the test, first you create the test that opens firefox,
goes to the google page and search ‘Selenium WebDriver’. To do this you have to
import the following libraries:
import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver;
To do the test you can use the following
code, this test after searching
‘selenium WebDriver’ obtains the title of the page and compare if the
title of the page is ‘Selenium
WebDriver - Buscar con Google’, if the title is different the test will fail:
@Test public void test() throws InterruptedException { WebDriver firefox_driver = new FirefoxDriver(); firefox_driver.get("https://www.google.com.gt"); WebElement search = firefox_driver.findElement(By.name("q")); search.sendKeys("Selenium WebDriver"); WebElement search_button = firefox_driver.findElement(By.id("gbqfb")); search_button.click(); Thread.sleep(2000); System.out.println(firefox_driver.getTitle()); if(!firefox_driver.getTitle().equals("Selenium WebDriver - Buscar con Google")){ fail("Test Fail"); } }
Now to do the test that obtains the title
of the page and prints it in the console you can use the following code, this
test will fail if the title of the page is not Google:
@Test public void title() { WebDriver firefox_driver = new FirefoxDriver(); firefox_driver.get("https://www.google.com.gt"); System.out.println(firefox_driver.getTitle()); if(!firefox_driver.getTitle().equals("Google")){ fail("Test Fail"); } }So that´s it for writing the tests, in the following post we will use ANT to execute them and then we will automatize the execution of our testcases using Hudson.
See you soon!
The blog gave me an idea to develop test cases using selenium Thanks for sharing it
ReplyDeleteSelenium Training in Chennai
Great Article
DeleteJava Project Ideas for Final Year Students
FInal Year Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai
DeleteGreat Article
Final Year Projects for CSE in Python
FInal Year Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai
Great post and i have one doubt. How to develop a template for test cases?. Please can anyone explain. Software Testing Training in Chennai
ReplyDeleteGreat sharing about test cases. keep sharing. want to learn selenium training with best placement support reach us Selenium Training in Chennai
ReplyDeleteThank you very much for the sharing! COOL.. Search Bar Firefox 57 Quantum addon
ReplyDeleteGood Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging
ReplyDeletesoftware testing course in chennai
Nice post.Thank you so much for sharing.Yiioverflow is a web development company.We have well expert team in Angular JS, Ionic, Yii Framework, Node JS, Laravel, PHP, MySQL, and WordPress.If you want a developer visit.. https://yiioverflow.com/
ReplyDeleteThis concept is a good way to enhance the knowledge.thanks for sharing. please keep it up selenium Online Training
ReplyDeleteVisit us at BGAOC and good luck will smile at you a casino online top Win now or never.
ReplyDeleteIt has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.
ReplyDeleteData Science Training in Chennai | Data Science Course in Chennai
Python Course in Chennai | Python Training Course Institutes in Chennai
RPA Training in Chennai | RPA Training in Chennai
Digital Marketing Course in Chennai | Best Digital Marketing Training in Chennai
Well done! Your explanation way is very attractive for me and I like more tips from your great post. Surely I will share your great post for my friends and this is very useful for freshers. Keeping the great work!
ReplyDeleteOracle Training in Chennai
Oracle Training institute in chennai
Social Media Marketing Courses in Chennai
Tableau Training in Chennai
Primavera Training in Chennai
Unix Training in Chennai
Oracle DBA Training in Chennai
Power BI Training in Chennai
Oracle Training in Chennai
Oracle Training institute in chennai
I am obliged to you for sharing this piece of information here and updating us with your resourceful guidance. Hope this might benefit many learners. Keep sharing this gainful articles and continue updating us.
ReplyDeleteBlue Prism Training in Chennai
Blue Prism Course in Chennai
German Classes in Chennai
Cloud Computing Training in Chennai
Data Science Course in Chennai
Devops Training in Chennai
Blue Prism Training in Porur
Blue Prism Training in Adyar
Thank you for sharing this Information.
ReplyDeleteCheck out the best
furniture sale
Dog Cages
bedroom furniture nz
entertainment unit