Selenium Class Notes 14oct
Selenium Class Notes 14oct
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?
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.
Selenium components:-
The selenium is majorly built on below components.
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 jason huggins.
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 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 5 different 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
version
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
Describe the steps to record the scenario like open google.com type selenium4testing in the
test box then click on Google search.
Scenario: Describe the steps to execute multiple test cases by using play entire test suite
option
Open selenium IDE then record the first test scenario. Once the recording is completed
click on the red button to stop the recording.
Take a new test case by navigation to file then click on new test case. Then record the
scenario make sure that the selenium IDE is in recording. Once the recording is
completed click on the red button to stop the recording.
Use the option play entire test suite to execute all the test cases in sequential order.
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.
Eclipse
Selenium_server_standalone_2.53.0.jar
Eclipse:- It is a standalone file(normal file) or folder. It is an editor whare we can write the
scripts
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.
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
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.
Package: webdriver
Classname: Yahoo_Login
---------------------------------------------------------------------Add content
Package: webdriver
Classname: OpenURL_Selenium4Testing
Classname: facebook_login
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();
driver.findElement(By.name("name")).click();
driver.findElement(By.Xpath("Xpath")).click();
//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(//).
Classname: HMS_PR_REG_para.java
Scenario 8:- write a program to login in to HMS and click on ADT then enter all the
values in new admition fields
Classname: HMS_newadmin
Scenario 9:- write a program to test the login functionality of gmail by using the
credentials testingse2 password selenium@345
Classname: GmailLogin
Synchronization:-
The process of providing wait to the tool to main the insync between 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.
Classname: GmailLogin
Scenario11:- Write a program to verify the one way search from Hyd to banglore in
spicejet
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 variables locally with in any block/ method then the scope of that
reference variable is limited to that block only. Local variables cant be used outside of the
block.
Global declaration:-
If ypu 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
2) Static
Classname:
Parameterization:
The process of sending/passing the values(parameters) to the method from the main
method is known as parameterization.
Syntax:-
Scenario 13:-Write a program to click on the links like Manual FAQs, seleniumFAQs,and
corejavaFAQs by passing parameters to the method in selenium4testing.com?
Classname: Selenium4Links_parameter
Scenario 14:-write a program to verify the oneway search with multiple different
passingers by using parameterization?
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.
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.
String str;
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.
Syntax:-
Driver.switchTo( ).window(window name);
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.
Classname:
Chrome
IE
Safari
Opera
http://docs.seleniumhq.org/download/
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.
Classname: AllBrowsers
Estimations:-
The number of days which we are going to take to automate the identified test cases is known
as automation estimations
on and average we can able to automate around 6 to 7 test cases. It means per one testcase
you are taking around 1 to 1.5 hours.
Because ,
Locators:- we are having the below locators to identify the element in webdriver
id,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.
http://addons.mozilla.org/en_us/firefox/addon/firebug/
http://addons.mozilla.org/en_us/firefox/addon/firepath/
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.
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.
Framework: -
The structural way to implement the scripts for better maintenance is known
as framework.
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 divided 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.
Advantages:
1. If any change in the application, we can update the change in the external file. So,
the maintenance is easy.
2. The driver script will be implemented based on the common fields available in the
application. So it is reusable for 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.
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 different test data then we
can prefer data driven framework.
Precondition Before
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
Hybrid framework:-
Junit:
Junit is nothing but java unit testing framework. It is to implement and execute the
scripts in java running language.
Scenario18:
Write a program to click on manual FAQS and selenium FAQS by using web driver
with Junit.
Package: junit
Classname: Selenium4Links_Junit
Step1: Take a 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.
Once the execution is completed it will provide the result under the J unit section of
eclipse. If any exception/error identify it will be displayed under the failure phase.
Scenario19:
Write a program to perform the oneway search in spicejet.com by using webdriver with
Junit.
Package: junit
Classname: SpicejetSearch_junit
Scenario20:
Write a program to perform permenant registration in HMS by using webdriver with
Junit.
Package: junit
Classname: HMS_Reg_Junit
Scenario:-
Implement few scenarios at perform both execution .
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
eclipse but not if 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 doesnt 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-----------------------------------------
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.
Browser commands:-
Get( ):-
It is to open the URL of the application.
Quit( ):-
It is to close the main window.
Syntax:-
Driver.quit( );
Close( ):-
It is close the pop up or child window.
Iterative commands:-
Sendkeys:-
It is to enter the same value in the text box.
Clear( ):-
It is to remove or clear the value from the text box.
Syntax( ):-
Driver.findelement( by.name(locater)).clear( );
Click( ):-
By using the command we can click on a button, radio button, check box, image, and link.
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.
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.
write a program to check on links like Hindi, Bengali, Telugu by passing parameters to
the method in TestNG with Web driver.
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?
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.
String comparisons:-
we can compare the string with another string by using the below commands.
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.
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.
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.