selenium4testing.comselenium4testing.com/wp-content/uploads/selenium-cl… · web viewselenium it...

43
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.

Upload: others

Post on 16-Apr-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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.

Page 2: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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.

Page 3: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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 RC3. Selenium grid4. Selenium web driver5. Selendroid and appium6. Winium

Selenium IDE:-

Page 4: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

IDE stands for Integrated Development Environment It is to record and run the script. It is an add-on for Firefox & Chrome(we can install and record in Firefox & Chrome

browser only). It is accountable for user actions(for each and every action it will generate the script). 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 web driver:-

It is the selenium2,3& 4 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.

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 or http://selenium.dev Click on Download at Selenium IDE Then click on for chrome option under selenium ide section

Page 5: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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

Page 6: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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

Page 7: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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 applicationEx:- Test the login functionality with 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 Chrome and firefox browser only. It won't provide the detailed test report or build status report for the analysis.

Page 8: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

The above all can be performed by using 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)

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.

How to configure or setup the selenium with java?

To configure selenium Webdriver, we need below files

Eclipse

JDK (8)

Selenium_server_standalone_4.*.*.jar ( 4contains 3 &2)

We can download from the below URLS,

https://www.eclipse.org/downloads/packages/release/oxygen/3a

https://selenium.dev/downloads/

Note: To open eclipse java should be installed in your system.

https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-

2133151.htm l

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:-JDk stands for java development kit.

Page 9: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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\Java and check that JDK1.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 web driver3, 2 and 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 Launch in workspace

launcher window. Click on workbench to navigate into eclipse

Create a project

Navigate to file, click on new and select Java-project. 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.

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 Apply and Apply&Close.

Write a programme to open the URL of Selenium4testing.com?

Take a class by right 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:-

Page 10: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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 or template. it contains objects. Object can be anything which should be physically available. In java, the object is nothing but the instance of the class.

Public static void main:-

It is the main method which is responsible for Execution- To launch chrome browser, we need chromedriver.exe file. We can download it

from the below url,- https://chromedriver.chromium.org/downloads .- package webdriver;-- import org.openqa.selenium.WebDriver;- import org.openqa.selenium.chrome.ChromeDriver;-- public class OpenGoogle {-- public static void main(String[] args) {- // TODO Auto-generated method stub- System.setProperty("webdriver.chrome.driver", "C:\\

Nagesh\\Library\\chromedriver.exe");- WebDriver driver = new ChromeDriver();- driver.get("http://google.co.in");-- }-- }

Refer all the Programs from selenium4testing.com/downloads

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 right clicking 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.

Page 11: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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 :-

Page 12: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

// To click on link

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

How to click on dropdown:-

//For drop downnewSelect(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

Page 13: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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

Page 14: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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. locally2. 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

Page 15: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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 stubCoreJavaBasicsc=newCoreJavaBasics();

//Object or Instancec.sample4("Rajesh");c.sample4("Suresh");c.sample4("Nagesh");

}

}Refer the Programs from selenium4testing.com/downloads

Page 16: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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:-

Page 17: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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/downloadsPackage: webdriver newClassname:

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.

Page 18: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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.

Page 19: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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.

Page 20: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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.

Page 21: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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.

Page 22: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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.

Page 23: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

Manual Testing Keyword Driven frameworkJunit & TestNG

Precondition

Testscenario with Testscripts

Postcondition

Before

Test

After

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 executioncompleted the frame work will provide

report (results) in HTML Format.8. Hybrid framework is structured as below:

Page 24: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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.

Page 25: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

@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).

Page 26: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

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.

Page 27: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

Scenario:-

Login into bugzilla by using the credentials. Jan 30 [email protected] password is selenium. Then click on search, then click on advance search, then select ERP, HMS, Speicejet

in the product list box.

TESTNG:

It is the advanced and enhanced version of Junit.

The limitations which are identified in Junit are overcomed in testNG & also given added advantages.

TestNG is an add on to Eclipse.

How to Install TestNG:

Click on Help in Eclipse then click on Install new software then click on add then Name: testNG

Location: http://beust.com/eclipse

then click on OK then expand TestNG & click on TestNG then click Next & again click on Next & then click on radio button to accept the license & then click on finish.

Take a testNG class by right clicking on the project ,click on testNg, create TestNg class, click on Browser at source folder, expand selenium automation project, select src then click on OK.

Give the package name as testNG & give class name as Selenium4Links, check the check boxes @Before test, @After test & click on Finish.

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 console2. 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:-

Page 28: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

Tocapture screenshot we need to use common.io Jar file.

We can download it from below site

https://commons.apache.org/proper/commons.io/download

commons.io.2.6.bin.zip---we need to download file.

All the jar files should be added to eclipse.

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?

For this scenario we can use parameterisation.

publicvoid Click(String str){driver.findelement(By.xpath(str)).click();

Scenario:

Write a program to check the login functionality of Gmail by using TestNg with Webdriver.

(Note: We can provide the description to the method as below:

@Test (description=”Verify the login functionality”)

Once the execution completed it will show the description in result file.

[NOTE:- driver.navigate().back();----It is to go back page

driver.navigate().forward(); ----It is to go front page]

How to capture the screen shot with time stamp?

public void takeScreenShot(String str) throws Exception{

SimpleDateFormat df= new SimpleDateFormat("yyyy MMM dd hh mm ss a");

Page 29: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

Date d =new Date();

String time = df.format(d);

System.out.println(time);

File f= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

FileUtils.copyFile(f, new File("C:\\Nagesh\Lib\\"+str+time+".png"));

}

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. XML file:- <suitename="webdriver">

<testname="Bugzilla">

<classes>

<classname="testNG.Bugzilla"></class>

</classes>

</test>

</suite>

NOTE: class name=package.public class

Write a programme to navigate to advanced search in Bugzilla then select multiple values from the fields like product,component,status,resolution then click on search.

XPATH:

Page 30: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

By using xpath we can identify the field with available attributes & text along with tag name.

It is of 2 types 1) Relative xpath 2) Absolute xpath

Relative xpath:

In relative xpath we can provide parent tag with available attributes.

Syntax: //tagname[@id=’test’]

//tagname[@id=’name’ and @name=’text’]

//tagname[@value=’text’or @class=’name’]

If duplication is there then (//tagname[@button=’text’])[1]

For text //tagname[text()=’text’]

NOTE: Due to the duplication if the relative xpath is not working then we can use absolute xpath.

Absolute xpath contains the complete highrarity of tag.

If any new update in the tags(source code) the existing absolute xpath may not work.

Always we need to prefer Relative xpath.

Exception Handle:

While we execute the script if any any line of code is failed,then the script execution will be braek/skip.

The process of continuing the execution while exceptions/errors is known as Exception handling.

We can acheie by using try,catch,block. Syntax: try { Driver.find element(); } catch (IOException e) { System.out.println("you have given wrong input"); }For Alert:

public void alert_OK(){ driver.switchTo().alert().accept(); //To click ok } public void alert_Cancel(){ driver.switchTo().alert().dismiss(); // To click Cancel

Page 31: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

} To print the text in alert:-

String str=null; str=driver.switchTo().alert().getText(); System.out.println(str);

To handle alert we need to navigate the switch to the alert then we can perform the actions like OK/CANCEL.Inheritance:-

It is from OOPS. The process of extending / reusing the objects from the parent class to child class is known as

inhertance After inheritance the child class becomes combination of both parent and child.

Syntax:

public class HMSRegistration_Alert extends BaseClass{

Information Commands: It is to take the information from the application. get Text();_____Text means which is avaliable outside of the tag. get Attribute();_____Which is avaliable inside the tag. get All Options(); ______Take all the values from the dropdown/list box. get All Selected Options();______Take only selected values from the list box. getFirstSelectedOptios();________Take only selected values from dropdown.

Scenario:Write a program to print gmail link displayname,Google search display name & tool tip off.Package import org.testng.annotations.Test;import org.testng.annotations.BeforeTest;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;import org.testng.annotations.AfterTest;

public class InformationCommands {WebDriver driver;

@Test public void f() {

String str = driver.findElement(By.linkText("Gmail")).getText(); System.out.println(str); String

str1=driver.findElement(By.name("btnK")).getAttribute("value"); System.out.println(str1); String str2 =

driver.findElement(By.xpath("//*[@id='hplogo']/a/img")).getAttribute("title");

System.out.println(str2); } @BeforeTest public void beforeTest() {

driver=new ChromeDriver();

Page 32: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

driver.manage().window().maximize();driver.manage().timeouts().implicitlyWait(30,

TimeUnit.SECONDS); //Global waitdriver.get("http://google.co.in");

}

@AfterTest public void afterTest() {

driver.quit(); }

}

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

one0

1

2

3

Page 33: selenium4testing.comselenium4testing.com/wp-content/uploads/Selenium-Cl… · Web viewSELENIUM It is an open source functional automation tool. Automation:-The process of converting

two

three

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.