You are on page 1of 30

SELENIUM

It is an open source functional automation tool.

Automation:-
The process of converting the manual test cases to test scripts with the help of some
automation tool is known as automation. These scripts can be executed on the targeted
application when ever needed.

Advantages:-
 We can save the test execution time( regression time). On and average to save around
50-60% of the test execution time.
 We can reduce CTC(Cost To The Company).
 The test scripts are repeatable on multiple builds.
 We can maintain accuracy by executing the same scripts in the same manner.
 Bugs can be identified.
 The tool will provide the test report to analyse the bugs and we can ensure for quality.
What is the difference between selenium and QTP? (Or) Why you
have selenium for your project?

Selenium features QTP features


 Open source Commercial tool & Costly
 Java,perl,php,python,ruby, VB script
C#,html.
 Firefox, IE, GChrome, IE, Firefox, GChrome.
Safari, opera.
 Windows, MAC, Linux. Windows.
 Flexible &Extendable. Flexible & Extendable less.
 Web apps & Mobile apps Desktop, Web, Mobile apps.

Note:-
Selenium is for web and mobile applications. If any desktop components or fields available in
the application cam handled with the help of SIKULI or AUTOIT.

When to start automation for a project?


 When the application is stable to save the regression testing time when can go for
automation.
 If you are using agile process (Scrum model) then we don’t wait until the build is stable.
The requirements/sprints/iterations are stable. Then we can go for automation
 We should have the budget and approval mail from the client or lead to start
automation.

What kind of application can be automated by using selenium?


 Selenium supports all kinds of web applications and mobile applications irrespective of
the language.
 We can use any supported language to automate all the applications.
What is automation strategy/ approach/ automation life cycle to automate
one project?
 Check that whether the application is compatible or not with the tools (Selenium).
 Execute or review all the test cases at least once, to get the functional knowledge on
the application and to identify the test cases which are feasible for automation.
 Provide the automation estimation for all the identified testcases.(The no of days
which we are taking to automate the test cases is known as Automation Estimations)
 Develop POC and deliver it to client (Automate 2 to 3 scenarios by using framework
and deliver to client)
 Prepare or identify the framework for the project.
 Develop the scripts for all the identified test cases.
 Once the scripts are stable then integrate in a hierarchical order to execute.
 If any new build released update the scripts as for the new build.
 Execute the scripts and capture the results in anew folder.
 Analyse the results and identify the bugs.
 Report the bugs manually to the developers by any reporting tool like bugzilla, QC,
Jira, etc.

Selenium components:-
The selenium is majorly built on below components.

1. Selenium IDE (Integration Development Environment)


2. Selenium RC
3. Selenium grid
4. Selenium web driver
5. Selendroid and appium
6. Winium

Selenium IDE:-
 IDE stands for Integrated Development Environment
 It is to record and run the script.
 It is an add-on for Firefox(we can install and record in Firefox browser only).
 It is accountable for user actions(for each and every action it will generate the script).
 By default it will generate the script in html language. If required we can convert to
other supported language like java, .net, etc.
 The recorded scripts can be run against other browsers also with the help of RC or
web driver.

Selenium RC:-
 RC stands for Remote Control.
 It is the selenium1 and introduced in 2004 by jasonhuggins.
 It is a server which is responsible to launch all the browsers but one browser at a time.
 We can able to automate the entire application by using selenium RC.

Selenium web driver:-


 It is the selenium2& 3 and it is an advanced version of RC.
 The limitations which are identified in RC are overcome in web driver and also given
the added advantages.

Selenium Grid:-
 It is for parallel execution. We can launch all the browsers parallel and the scripts can
be executed in all the browsers parallel at a time.
 Maximum of 5different browsers can be launched by using grid.

Selendroid:-
 It is to test the mobile apps on the android platform. it is to test on less than 4 android
versions

Appium:-
 It is to test the mobile applications on both android and iOS platforms. If the android
version is more than 4 we need to use Appium

Steps to install selenium IDE in Firefox/Chrome browser:-

 Open the url http://seleniumhq.org


 Click on Download
 Then click on chrome option under selenium ide section

 Then Add to Chrome
 Selenium IDE will be added to browser header

Describe the steps to record the scenario like open google.com type selenium4testing in the
test box then click on Google search

 Open Selenium IDE


 Click on Record a new test in new project option


 Give the project name as Google
 Give the URL as http://google.co.in
 Then click on Start Recording
 Perform actions on the browser
 Selenium ide will capture all the actions
 Click on Stop recording option to stop the recording
 Provide test name as Googlesearch
 To run click on the option play button

Test suite / batch execution:-


Combination of multiple test cases is known as test suite or batch.

 Select Tests


 Click on + icon to take new test case
 Provide test case name as Test2

 Click on Rec option to record


 Once the recording is completed then use the option “Run all tests” to execute all the
test cases

Limitations or disadvantages selenium IDE:-


 Its not possible to perform regression testing.
Ex:- The recorded scripts can't be executed on the new build if the application is
dynamically changing.

 We can't perform retesting of the application


Ex:- Test the login functionalitywith multiple sets of different credentials.
Test the one way search functionality with multiple sets of origin.
 Static testing like checking the availability of the fields (validation) is not possible to
perform.
 We cant perform database testing
 It is limited to firefox browser only.
 It won't provide the detailed test report or build status report for the analysis.
 The above all can be performed by using RC or Web driver.
Advantages of selenium IDE or when to use selenium IDE(recording):-
 To check whether the application is compatible or not can be identified by using
selenium IDE.
Ex:- Record few scenarios and check that whether the tool is generating the script or
not.
 If it is generating the scripts then we can conclude that the application is compatible
with selenium..
 If you are facing any problem to identify the locator/target then it can be overcome by
using selenium IDE.(We can take the locator from Selenium IDE)
 We can convert the recorded script to specific language and it can be used in the
scripting also.
 To convert the recorded scripts go to options then click on options then check the check
box Enable experimental features then click on ok.
 Now go to options, click on format and select the desired language.
NOTE:-

 When to go for scripting and when to go for recording for a project automation?
To automate any project we have to use the scripting by using webdriver while
scripting if you are facing any issues then it can be overcome by using selenium
IDE.

Note: If we are getting more than 50 version of firefox will get JS execution error. To overcome the
issue install the below add on in firefox

https://addons.mozilla.org/en-US/firefox/addon/flow-control/?src=dp-dl-othersby

How to configure or setup the selenium with java?


To configure selenium Webdriverwe need below files

Eclipse

JDK (8)

Selenium_server_standalone_3.*.*.jar

RC, Web driver2&3 and Grid

We can download from the below URLS,

http://www.eclipse.org/downloads/

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
http://docs.seleniumhq.org/download/

Eclipse:-It is a standalone file(normal file) or folder. It is an editor where we can write the
scripts

 It is not necessary to install it


 Based on the System type (32 bit or 64 bit)we need to download Eclipse

JDK/JRE:-JDk stands for java development kit.


JRE stands for java run time environment.

Both are nothing but java.

 To open eclipse java should be installed in your system.


 Go to the path C:\Program Files\Javaand check that JRE 8 is available or not. If it
is not available then install JDK 8 exe file based on the system type

Selenium-serve_ standalone jar file:-


 It is the selenium where it’s a combination of RC and web driver, grid.

Webdriver Setup
 Take the eclipse and extract the zip file.
 Copy to any desired drive.
 Check that JDK 8 is available in c:/programme file/java. If is not available then install
JDK.
 Create a folder with a name lib/library copy the selenium server standalone jar file and
paste it in the library folder.
 Go to eclipse then double click on blue icon (eclipse.exe) continue to open.
 By default if displays some path in the workspace if required we can update the path.
 Workspace is the folder where it contains the test scripts.Click ok on workspace launcher
window.
 Click on workbench to navigate into eclipse
Create a project
 Navigate to a file,click on new and select project.
 Select the java project then click on next.
 Give the project name as selenium automation.
 Check that java SE 1.8. From the field use an execution environment JRE then click on
finish.
 Click on Open Perspective to continue the setup.
Expand the selenium automation project
 Right click on JRE system library click on build path then select configure build path.
 Click on add external Jars and select selenium server standalone jar file from the library
folder.
 Click on open and ok.

Write a programme to verify the search in google.co.in?


 Take a class by write click on the project click on new and select class.
 Give the package name as selenium WebDriver.
 Give the class name as OpenUrl_HMS
 check the checkbox public static void main then click on finish.

Package:-
Package is nothing but a folder where it contains the classes .The package will be created
under the SRC folder of the selenium project.

Class:-
 Class is a blue print of templates it contains object.
 Object can be anything which should be physically available.
 In java the object is nothing but the data type or method or instance.

Public static void main:-


 It is the main method which is responsible for Execution
Program1: Write a program to open the URL
Sample program by using webDriver
Refer the Programs from selenium4testing.com/downloads

Package: webdriver

Classname: HMSLogin.java

Webdriver commands:

Webdriver methods:

Scenario2:-write a program to test the login functionality of hms by using the credentials
user1 and user1

Refer the Programs from selenium4testing.com/downloads

Package: webdriver
Classname: HMS_Login:-

 Take a new class by rightclicking on the project ,click on new and select class.
 Give the pacage name as Webdriver, And give the class name as HMS_logn
,thencheck the checkbox public static void main then click on finish
 To perform action on any field we need the locator.we can To take the locators for
every browser we are having the below addon.
 To take thelocator,right click on the field click on inspect element(Q),then use either
ID or Name or any locator.

Browser Addon
 Fire fox inspect element
 IE developer tools
 Google chrome inspect element
 Safari inspect element
 Opera inspect element

Scenario3:-write a program to test the login functionality of yahoo by using the


credentials.

Refer the Programs from selenium4testing.com/downloads

Package: webdriver

Classname: Yahoo_Login

---------------------------------------------------------------------Add content

Scenario4:-write a program search for “selenium4testing in google.co.in


Refer the Programs from selenium4testing.com/downloads

Package: webdriver

Classname: OpenURL_Selenium4Testing

Scenario 5:-write a program to test the login functionality of facebook.com


Refer the Programs from selenium4testing.com/downloads

Package: webdriver new

Classname: facebook_login

Scenario 6:write a program to verify the password registration in HMS


Refer the Programs from selenium4testing.com/downloads
Package: webdriver new

Classname: HMS_PR_REG_para.java

 How to click on link :-

// To click on link

driver.findElement(By.linkText(“manualFAQs”)).click();
driver.findElement(By.linkText(“seleniumFAQs”)).click();

 How to click on dropdown:-

//For drop down


newSelect(driver.findElement(By.id("idname"))).selectByVisibleText("3
Adults");
new Select(driver.findElement(By.id("idname"))).selectByVisibleText("1 Child");

 How to click on Date& how to use x-path

driver.findElement(By.name("name")).click();
driver.findElement(By.Xpath("Xpath")).click();

 How to Upload a file:-

By using sendkeys command we can upload a file,whare we need to provide the


path of the file

//Upload a file

driver.findElement(By.name("image")).sendkeys(“path”);

 In java when we ever we are going to give path then we have to use double
slash(//).

Scenario7: complete the HMS permanent registration


Refer the Programs from selenium4testing.com/downloads

Package: webdriver new

Classname: HMS_PR_REG_para.java
Scenario8:- write a program to login in to HMS and click on ADT then enter all the
values in new admition fields

Refer the Programs from selenium4testing.com/downloads

Package: webdriver new

Classname:HMS_newadmin

Scenario9:-write a program to test the login functionality of gmail by using the


credentials testingse2 password selenium@345

Refer the Programs from selenium4testing.com/downloads

Package: webdriver new

Classname:GmailLogin

Synchronization:-
The process of providing wait to the tool to main the insyncbetween both application and
tool is known as synchronization. It is two types.

1. page load

2. page refresh

Page load:-
 If the application is taking time to load the page then the webdriver by default handles
it. Not necessary to add any command

Page refresh:-
 If the application taking time to refresh the page then we need to handle with the help
of below command.
Selenium thread.sleep(time);
(or)
Implicit/Explicit wait
 It is a standard wait its simply waits upto the given time..
 Thread.sleep is form of java command. Whenever we use it may through the
exception.
 To handle it add throws exception to the method as well as to the main method.

Scenario10:-Write a program to test the login functionalities of a gmail.?


Refer the Programs from selenium4testing.com/downloads

Package: webdriver new

Classname:GmailLogin

Scenario11:-Write a program to verify the one way search from Hyd to banglore in
spicejet

Refer the Programs from selenium4testing.com/downloads

Package: webdriver new

Classname:Spicejet_Search

Core java basics:-


Java is an object oriented programming language. It has multiple data types like int,
float, char, double, string, arrays, etc.

 We are also having class datatype as non primitive datatypes like Strings&arrays

String:-
It is a class data type where we can store multiple characters. We can declare the
string(object) in 2 ways.

1. locally
2. globally
(To comment multiple lines select multiple line ctrl+ shift+ backward slash )

Local declaration:-
If we declare the variableslocally with in any block/ method then the scope of that reference
variable is limited to thatblock only. Local variables cant be used outside of the block.

Global declaration:-
If you are planning to access the object(data types, methods and instances ) in multiple
classes and methods then we need to declare it globally by using access modifiers like
private, public, protected, default.

Private:-
These objects can be used with in the class only. Private objects cant be used outside of the
class.

Public:-
These objects can be used within the classes as well as outside of the class. Public object can
be used with in the project of multiple classes& packages

Methods (or) Functions:-

 Group (or) block of statements is known as Method


 Methods are reusable
 Method should have a unique name
 We can call the method with in the method also
 We can declare the method in two formats

1) Non Static

2) Static

Scenario12:-writea program to print 3 statements (welcome) messages

package basics;

publicclassCoreJavaBasics {
private String str; // Global Declaration
// public String str;

publicvoid sample1(){
// String str; // Local Declaration
str="Mahesh";
System.out.println("Welcome "+str);
}
publicvoid sample2(){
//String str1="Rajesh";
str="Rajesh";
System.out.println("Welcome "+str);
}
publicvoid sample3(){
//String str2="Ramu";
str="Ramu";
System.out.println("Welcome "+str);
}

publicvoid sample4(String s){


//str="Srinivas";
System.out.println("Welcome "+s);
}
publicstaticvoidmain(String[] args) {
// TODO Auto-generated method stub
CoreJavaBasicsc=newCoreJavaBasics(); //Object or
Instance
c.sample4("Rajesh");
c.sample4("Suresh");
c.sample4("Nagesh");
}

Refer the Programs from selenium4testing.com/downloads

Package: webdriver new

Classname:

Parameterization:
The process of sending/passing the values(parameters) to the method from the main
method is known as parameterization.

Syntax:-

Scenario13:-Write a program to click on the links like Manual FAQs,


seleniumFAQs,andcorejavaFAQs by passing parameters to the method in
selenium4testing.com?

Refer the Programs from selenium4testing.com/downloads

Package: webdriver new


Classname:Selenium4Links_parameter

Scenario14:-write a program to verify the oneway search with multiple different


passingers by using parameterization?

Refer the Programs from selenium4testing.com/downloads

Package: webdriver new

Classname:SpicejetSEarch_Parameter

How to handle java scripts alerts messages and pop ups or child windows?
 Verify the one way search in spiecejet.com with more infont count then adults. Is
displays and java script alert messages click on it.
 Before clicking on the alert message print the message which is available on the alert.
 To handle the alert we need to navigate from the browser to the alert then we can
perform the actions either ok or cancel.

Accept( ):-
It is to click on dialogue alert and confirmation alert.

Driver.switchto( ).alert ( ).accept( ); // to click on ok.

Dismiss( ):-
It is to click cancel on thr conformation alert message.

Syntax:-
Driver.switchto( ).alert ( ).dismiss( ); // to click on ok.

Get text:-
It is to take the test or label from the application. Where the web driver is having the focus.

The written type of get text is string.

String str;

str = driver.switch to( ).alert( ).get text( );

System.out.println(str);

Scenario15:-
 Write a program to verify the one way search in speicejet.com.
 Then click on feild flights it will navigate to the select then click on currency
convertor.
 where it displays a pop up then navigate to the pop up perform actions on pop up then
close it.
 Select any value from the going to field.
 To handle the pop up we need to navigate from the main window to the pop up by
using below command where we have to pass the window name.

Refer the Programs from selenium4testing.com/downloads


Package: webdriver new
Classname:

Syntax:-
Driver.switchTo( ).window(“window name”);

Get window handle:-


 It is to take the one window name. It will return the window name where the web
driver is having the focus.by default the focus is on main window so,it will return the
main window name.
 The return type get window handle is string
 To handle the pop-up we need to navigate from the main window to the pop-up whare
we have to use pop-up name

Syntax:-

driver.SwitchTo().window(“windowname”);

 To navigate back from the pop-up to main window again we have to use the above
command whare we need to pass the main window name.

Syntax:-

String str;

Str=driver.getwindowHandle();

Driver.switchTo().window (str);

Scenario16:-
Write a program to login in to HMS,click on feedback,enter the valus in the pop-up,close the
pop-up by using driver.close() then click on Registration link on the main window.

Refer the Programs from selenium4testing.com/downloads

Package: webdriver new

Classname:
How to launch all browsers like

 Chrome
 IE
 Safari
 Opera

How to launc the googlechrome:-


 To launch the googlechrome we should have chrome driver exe file.
 We can download it from the below site.
 http://ChromeDriver.storage.googleapis.com/index.html
 Click on the folder 2.16 then download chrome driver win32 zip file.
 Extract the zip file then copy chrome driver exe file and paste in the library folder.
 It is for both 32-bit and 64-bit systems.

To launch IE we need IE driver server. We can download if from below.

http://docs.seleniumhq.org/download/

Based on the system type (32 bit/64 bit )

Download IE driver server.

Extract the zip file then paste the IE driver server to library folder.

Note:-
 If you are facing any problem in IE.
 To run the script IE. We have the use commands called “*iehta”.
 If IE is blocking the execution then do the below execution setting in IE.
Go to tools,
Then click on internet options,
Then click on security,
Then click on uncheck the check box enable protected mode in all the
4 sections like internet,trusted sites, restricted sites,
Then click on apply,
Then click on ok,
Then again click on ok.

Scenario17:-write a program to launchall browsers like chrome,IE,safari,opera


Refer the Programs from selenium4testing.com/downloads

Package: webdriver new

Classname:AllBrowsers
Estimations:-
The number of days which we are going to take to automate the identified test cases is known
as automation estimations

How many testcases we can automate in aday?


It all depends on the testcases and the number of steps which are available for the testcases

on and average we can able to automate around 2 to 3 test cases. It means per one testcase we
are taking around 3 to 4 hours.

Because ,

1. To analyze the testcase.


2. To develop the scripts with locators.
3. To execute the scripts.
4. To debug and stabilize the script.

Provide automation estimations for 200 testcases:-


1TC = 3 to 4 hours.

200TCs = 200*4=800 hours.

No.of days = 800/8= x days.

No.of months = x/22 = around Y months.

Locators:-we are having the below locators to identify the element in


webdriverid,name,css,linktext,xpath,tagname,classname

CSS:- (cascade style sheet)it will identify the element with the help of tagname.classname

 If the classname is having any space then replace the space with dot(.)

Syntax:-
Driver.findelement(by.cssselector(“locator”)).click();

Absolute X-path:-
If we are unable to identify the element by using relative X-path due to same code
duplication, then we can go for absolute X-path. It will identify the elements with the
hierarchical path of the logs. We can take the absolute X-path from the below tools.

1. Fire path.
2. Copy X-path.

Fire path:-
It is an add-on for firebug. So we need to install firebug then we able to use fire path.

Steps to install firebug:-


Launch fire fox and open the below URL.

http://addons.mozilla.org/en_us/firefox/addon/firebug/

Click on add to Firefox and click on install now,

Steps to install fire path:-


launch Firefox and open the below URL.

http://addons.mozilla.org/en_us/firefox/addon/firepath/

click on add to Firefox then click on install now.

Then click on restart now button to restart Firefox.

How to capture the X-path:-


Right click on field,

Then Click on inspect element with firebug,

Then right click on the highlighted section,

Then right click on the inspect in fire path panel.

By default it will the relative X-path. To get the absolute X-path click on the arrow mark at
fire path and select generate absolute X-path close fire bug and capture the X-path again to
get the absolute X-path.

Copy X-path:-
It is an add-on for the browsers like Firefox, googlechrome, safari and opera. It will be
available by default in the above browsers.

What is the difference between the double slash ( // ) and single slash ( / ) in
the X-path?
//- represents the parent tag.

/-represents chaild tag(subtag)

Debugging:-
 The process of running the scripts step by step mode is known as debugging.
 Debugging is to identify the errors in run time and also we can see the execution flow
of the scripts.

Steps to run the scripts in debug mode:-


 Go to script then add the break point by double clicking on the line number.
 From break point onwards the script will be executed line by line.
 Right click on the script click on debug as and select java application.
 Click on yes to continue thescript debug mode.
 Click on f6 to run the scripts line by line.
 Click on f5 to navigate into the method.
 Click in f8 to run the script without debug mode.
 To come back to the normal screen click on the terminate button in debug section then
click on java.
 Double click on the break point to remove.

Framework: -
The structural way to implement the scripts for better maintenance is known as framework.

 Maintenance means how we are implementing the scripts. Is it easy to analyse,


update, execute and getting the test report.
 We have the below frameworks

1. Modular framework.
2. Data driven framework.
3. Keyword driven framework.
4. Hybrid framework.

Modular framework:
 It is the basic framework and also known as linear framework.
 The application will be divide into multiple modules and sub modules.
 The automation engineer will implement the scripts for all the modules and sub
modules. once all the scripts are stable then they will integrate in a hierarchal order to
execute.

Data driven framework:


 From data driven onwards introducedexternal files like excel, text (note pad),
database, xml etc..
 The external files are to take the test data and to give the output results.
 It contains DriverScript which is responsible for execution. The driver script doesn’t
contain any of the test cases and test data.
 All will be available in the external file (Excel file)
 The driver script will take the data from external files and executes. Hence we will
call it as data driven framework.

Advantages:
1. If any change in the application,we can update the change in the external file. So,
the maintenance is easy.
2. The driverScript will be implemented based on the common fields available in the
application. So it is reusablefor all kinds of applications.
3. If the application contains more number of fields like 100 textboxes, 100 buttons
etc. Then not necessary to implement those many lines of code, we can prefer data
driven driver script, which works for all the fields.
4. We can perform effective retesting

Disadvantages: -
1. Developing the driver script is a challenging task.
2. Taking all the fields locators into the excel file is also a challenging task.

Note: If the application is stable, but we need to test with multiple sets of different data then
we can prefer data driven framework.

Keyword driven framework:

 Keyword means a step it is a step by step execution.


 It is very similar to manual testing.
 The way we are using to implement the test cases in manual testing the same can be
followed in keyword driven fw.
 We can implement the keywords with the help of Junit or TestNG as below.

Manual Testing Keyword Driven


framework
Junit & TestNG

Precondition Before

Testscenario with Test


Testscripts
After
Postcondition

Note: The test engg.. will implement all the test cases in the form of steps (units / Keyword /
steps) then these will be executed from the Excel or XML
Advantages:
1. The same manual testing format we are using in automation, so the maintenance is
easy.
2. Junit and TestNG are predefined frameworks not necessary to implement the
frameworks.
3. Once the execution is completed it will provide the results also.
4. We can prefer the keyword driven fw for unstable applications (Agile based
projects)

Hybrid framework:-

 The combination of two or more frameworks (TestNG, Data Driven, Framework


and Page Object Model) is nothing but hybrid framework.
 We can utilize the advantages of both the frameworks in hybrid framework.
 It contains multiple layers.

1. Base Class: Contains all reusable methods like sendkeys (), click ().
2. OR (Object Repository): Repository means storage place or
Storage Folder. It contains all the field Locators.
3. TestData: The data which we are using for testing is known as
TestData. We will use XL file to store test data.
4. Components: Test cases will be implemented in the form of methods
nothing but those are Components.
5. Test Scripts: The components or Testcases will be executed in the form
of end to end flows.
6. XML File: Will use XML file to execute one class or multiple classes
(Batch execution) and also we can perform parallel execution.
7. Test Report: Once the execution completed the frame work will provide
report (results) in HTML Format.
8. Hybrid framework is structured as below:
Junit:
Junit is nothing but java unit testing framework. It is to implement and execute the scripts in
java programming language.

Scenario18:
Write a program to click on manual FAQ’S and selenium FAQ’S by using web driver with
Junit.

Refer the Programs from selenium4testing.com/downloads

Package: junit

Classname:Selenium4Links_Junit

Step1:Takea Junit class by right clicking on the project, click on new and select Junit
test case.
Step2: Give the package name as Junit and give the class name as selenium4 links then
check the checkboxes setup and teardown .then click on finish.

Step3: Junit contains multiple annotations like @before, @test, @after etc.

@before:- It contains setup method where it acts as a precondition. When we run the script
it will be executes initially.

@test:It contains the test scenario with scripts.

@after: It is responsible to close the execution where it contains teardown method.


Junit lifecycle / Execution flow:-
When we run the script initially it invokes the @before method will be executed
then@test method will be executed then @after will be executed the same will be continued
for all the @test methods

Once the execution is completed it will provide the result under the Junit section of
eclipse. If any exception/error identify it will be displayed under the failure trace.

Scenario19:
Write a program to perform the oneway search in spicejet.com by using webdriver with Junit.

Refer the Programs from selenium4testing.com/downloads

Package: junit

Classname:SpicejetSearch_junit

Scenario20:
Write a program to perform permenant registration in HMS by using webdriver with Junit.

Refer the Programs from selenium4testing.com/downloads

Package: junit

Classname:HMS_Reg_Junit

Batch / Test suite Execution:-


Combination of multiple test cases is known as suite / batch.

Scenario:-
 Implement few scenarios and perform batchexecution .
 Once all the scenarios are implemented right click on any class then click on
run as and select run configurations.
 Click on the radio button run all test in the selected project then click on run
and click on run.
 It executes all the classes in the alphabetical order.

Limitations of Junit:
 For each and every test the before and after are applicable. So ,we need to implement
all the scenarios very independently.
 Once the execution is completed it will provide the results under the Junit section of
eclipse but not in any external file (Excel or HTML).
 To perform batch execution we are having the only one option like run/test in the
selected project. But it doesn’t have the option to run selected classes and selected
methods (scenarios).
 It is having very limited annotations like
@before class
@ Before
@Test
@After
@After class
 All the above limitations can be overcome by using “TestNG”.

--------------------------------------------------Julay 14-----------------------------------------

Web driver selenium2:-

What is the difference between the selenium RC and web driver?

Web driver features:-


 We can access all the latest browser like firefox-39, googlechrome -43, safari-5, IE-
11, opera-29/30.
 To run the web driver program not necessary to run the selenium server.
 By default web driver launchers the browser to maximize stage the it doesn’t launch
the command history browser.
 By default web driver maintains the page load synchronization, if it is a page refresh
then we need to handle by using thread sleep weight or implicit weight.
 Web driver is having the auto scroll down option into the application while executing
the script.
 We can implement both web driver commands and RC commands in a single class.
We can effectively take the information from the application fie validation.

Web driver commands:-

Note:-
 To upload a file we have 2 options with the help of send keys we can provide the path
of the image to upload.
 By using sikuli also we can upload the file.

Scenario:-
 Login into HMS then click on the feedback link then navigate to child
window(popup).
 Enter same values in popup then close the popup, then click on ADT in the main
window.

Scenario:-
 Login into bugzilla by using the credentials.
 Jan 30 selenium@gmail.com password is selenium.
 Then click on search, then click on advance search, then select ERP, HMS, Speicejet
in the product list box.

TestNG / Execution flow:


TestNG contains multiple annotations like @before test, @test, @after test etc. when
we can run the script initially it invokes the before test method then executes all the @test
methods in the alphabetical order then finally it executes @after test method.

once the execution is completed it will provide the results in two formats.

1. In console
2. It creates an html file under the project folder of bug space.

D:/workspace-1030/seleniumproject/test-output/Default suite/Default test.html

write a program to check on links like Hindi, Bengali, Telugu by passing parameters to
the method in TestNG with Web driver.

Here to copy the program.

How to capture the screen shots:-

Advantages:-
 If any test case failed to analyse the fail result we need a screen shot.
 Its not possible to automate GUI testcases because, there is (ROI) return on
investiment at the same time its possible to implement the scripts for look and feel.

Scenario:-

Write a program to capture the screen shot for manual FAQs, selenium
FAQs, general testing FAQs?

How to capture the screen shot with time stamp?

XML:-
Our plan is to use the XML file to perform the test execution.

Advantages:-
 We can execute the test methods in user defind order (we can avoid alphabetical order
issue).
 We can provide user defind name to default suite folder and default test html file.
 We can perform batch execution.
 We can perform parallel execution also.

How to create an XML file:-


 Right click on the project, click on new and select file.
 Give the file name testsuite.xml then click on finish.

String comparisons:-
we can compare the string with another string by using the below commands.

1. Equals: It looks for the exact match and it is case sensitive.


2. EqualsIgnoreCase: It also looks for the exact map but it’s not case sensitive.
3. Contains: It will check whether few characters are available in the string (or)
not.

Syntax:

String splits:
String contains one,two,three,four check that three is available or not. it available print it.

Splits:
Split is a method from the string we can divide the string to multiple values by using some
regular expression (some value). The value which we are using to divide the string it will be
removed from the string and the remaining values will be store in an array.

The return type of split is an array.

Array:
Array is a class data type where we can store multiple values with similar data types.
Array will store the values in a container format. So, for each value it will provide a
separate position.

Syntax: String S1[ ] = new String [9];

int k[ ];

char c[ ];

object o[ ];

Array
0 one

1 two

2 three

3 four

scenario:-
login into HMS then click on permanent registration. print all the mandatory
fields which are available in PR phase check that last name and age fields are
available (or) not.

scenario for Ajax control:-


 Ajax means dynamic based on the input field will dynamically displays the
values.
 Open google.com type selenium in the textbox. check that selenium web
driver is available in suggested list or not. if available type it.

You might also like