Introduction to Junit in Selenium
It is a java unit testing framework
The purpose of J unit is to write the test scripts in java programming language and scripts can be executed by default
** write a program to register and login into mail.in.com by using j unit ?
Right-click on the project àclick on new àselect J unit test cases
Give the package name as “ j unit “ & class name as “mail tag,x-right”
check the checkboxes setup() & teardown()à click on finish
Any import statements are activations
J-Unit life cycle [execution flow]:-
it contains animations like @before,@after,@test, etc.
It contains a setup method which acts as a precondition
It contains a teardown (or)shut down a method that acts as a postcondition.
It is responsible to develop the test scenario where it acts as the main method
For each and every scenario we need to develop with test animation.
when we run the script initially it invokes @before, @after, @test methods.
- The same process will be continued for all the @ test methods.
- once the execution is done it provides the results under the J-unit section.
Inclined to build a profession as Selenium Developer? Then here is the blog post on
Selenium Training Videos.
Batch execution/suite execution:
combination of multiple test cases [scenarios]is known as a batch or test suite
- Take how classes and execute both the classes methods in sequential order.
- Right-click on project àclick Newà select J unit test caseà implement the class
- Take one more class and follow the above steps
- To run all the classes right click à click on run as à select run configuration
- Select the radio button “run all test in the…” à click on apply à click on run
Limitations of J-unit:-
It is having very limited annotations like @before class, @before, @test, @after ,after class
- Each and every test @before will be applicable
- It is having the option to run either a single test or all classes
- Not having the option to run the specific classes
- Once the execution is completed it is providing the result in the j-unit section of explain but not in any external field execute for the reporting.
- All the above limitations can be overcome by using test NG.
- It is a testing framework inspired by and advanced version of J-unit.
- The limitation which is in J-unit is overcome and added new features that mode test NG more power here and easier to use.
- Test NG is an add-on for the eclipse.
Steps to install testing in Eclipse: Go to eclipse à click on help select install new software click on add give the name on ”Test NG” à provide URL as http://best.com/eclipse -- >click ok à check the checkbox “Test NG” click on next again next click on the radio button “I accept the license” click on finish click ok on security warning manage to click yes in restart message
Write a program to handle the pop –up in spice jet.com by using web driver with testing *
Take a Test NG class by right click on the project à click on test NG select create Test NG class Click on browse folder on the source folder expand the project and select “SRC” then click on ok Give the package name on “spice jet _ Test NG” Give the class name on “spice jet _ popup” Check the checkboxes @ before test and @ After test Click on finish
Learn more about Selenium Interview Questions in this blog post.
Test NG life cycle[execution flow] :-
It contains multiple animations like @before test, @after test, @test e.t.c
when we run the scripts initially it invokes the @before test method then executes and the @test methods in an alphabetical order finally it executes the @after test method.
once the execution is done it provides the results in two formats.
- In console
- MISSING LAST LINE PG:43
E: workspace loan selenium test. output default suite default test. Home Result o/p file [external file] XML:-
To perform the test scripts execution we are planning to use XML files.
we can run the test methods in user-defined order [we can avoid alphabetical order issue]
we can perform batch execution
we can provide user-defined names to the default suite folder and default test HTML file.
How to create on XML file:
Go to file click on new select other à expand XML folder select XML file click on next select the project
Xml file Format:-
<suite name =”spicejet suite” >
<test name=”spicejet test results” >
<include name=”verifyone way search”> </include>
For an Indepth knowledge on Selenium, click on below
- Io streams /external files in Selenium
- Selenium Grid
- Conditional statements in Selenium
- Different flavors of Selenium
- Selenium WebDriver Features