330 likes | 369 Views
Testing With Selenium - Open source Test Automation Tool. By: Niranjan Limbachiya. Agenda. Selenium Origin What is Selenium? Platform and Browser compatibility Selenium IDE How to work with Selenium IDE? Selenium CORE How to work with Selenium IDE? Testing Application with IDE/CORE?
E N D
Testing With Selenium - Open source Test Automation Tool By: Niranjan Limbachiya
Agenda • Selenium Origin • What is Selenium? • Platform and Browser compatibility • Selenium IDE • How to work with Selenium IDE? • Selenium CORE • How to work with Selenium IDE? • Testing Application with IDE/CORE? • Selenium-RC • Way to Test Application in IE • Test IE application with PHPUnit • DATA-Driven • QMetry- Live Example
Selenium Origin • Selenium is a chemical element in the periodic table that has the symbol Se and atomic number 34 • Selenium was developed by team of Programmers and testers at ThoughtWorks to test their web based time and expenses system. • Javascript Functional Test Runner was written by Jason Huggins, Paul Gross and Jie Tina Wang, in 2004.
What is Selenium and whats it for? Selenium tests run directly in a browser, just as real users do A java Script Based Open Source Web Testing Tool That Support web 2.0 Application On Multiple Browser And multiple OS No other test tool covers such a wide array of platforms
Contd.. • Selenium is not meant for unit testing • Its used for Functional or systemTesting • But Not for Performance Testing
Platform and Browser compatibility • Supported Platforms: • Windows: • Internet Explorer 6.0 • Firefox 0.8 to 1.5 • Mozilla Suite 1.6+, 1.7+ • Seamonkey 1.0 • Opera 8 • Mac OS X: • Safari 1.3+ • Firefox 0.8 to 1.5 • Camino 1.0a1 • Mozilla Suite 1.6+, 1.7+ • Seamonkey 1.0 • Linux: • Firefox 0.8 to 1.5 • Mozilla Suite 1.6+, 1.7+ • Konqueror
Introduction Driven Mode. Test Case in different Language Selenium IDE RC CORE Bot Mode: HTML tables Record Mode
Selenium IDE • Selenium IDE is an integrated development environment for Selenium tests • It is implemented as a Firefox extension. (Note no IE Extension Available) • It allows us to record, edit, and debug tests • Selenium IDE includes the entire Selenium Core, allowing you to easily and quickly record and play back tests in the actual environment that they will run. • Selenium IDE is not only recording tool: it is a complete IDE • You can choose to use its recording capability, or you may edit your scripts by hand
How to Start work with Selenium IDE? • Download from http://www.openqa.org/selenium-ide/download.action • When you will download selenium IDE with firefox, it should automatically ask you to install the plugin. • In case if we downloaded the file with Opera or IE. No problem:
Contd.. • Open firefox • from the menu: Tools ->Add-ons--> Extensions • now drag-n-drop the xpi file to the extensions window • restart firefox • You can see a 'Selenium IDE' entry from your tools menu Note: First, Always we have to record test in IDE with Fire fox, then we could playback in IE using seleniumTest runner and also for Phpunit(RC)
Features: • Easy record and playback • Debug and set breakpoints • Autocomplete for all common Selenium commands • Save tests as HTML, PHP scripts, or any other format • Support for Selenium user-extensions.js file • Option to automatically assert the title of every page
Selenium-CORE Selenium core is a test tool for web For Web application Selenium core tests run directly In a browser Just as real users do !! Written in Pure JAVAScript And DHTML
How to Start work with Selenium CORE? • To use Selenium Core, you need to make it available from the same web server as the application you want to test • Normally, this is as simple as extracting the Selenium Core zip file into the Document Root, htdocs, or webroot of your webserver. • Then, try to open the TestRunner.html page on your website, which should be in the core/ directory.
Live Example • Testing Google/QMetry Application with IDE and Core
HTA Mode • Selenium Core provides an additional mechanism for running automated tests called "HTA mode.“ • An hta file is simply an html file but the extension “. hta” means that when we navigated to IE, it will apply same strict security measure • Window+Selenium core+IE • To run Selenium Core in HTA mode, just double-click on TestRunner.hta, in the /core directory of your Selenium installation.
Selenium RC Allow us to write automated web application in any programming language (Java, .NET, Perl, Python, Ruby, PHP) The Selenium Server communicates directly with browser using AJAX Selenium Server acts as a client-configured HTTP proxy, to stand in between the browser and your website. Selenium Remote Control provides a Selenium Server, which cans automatically start/stop/control, any supported browser
How to Start Selenium Server • The Selenium Server is written in Java, and requires the Java Runtime Environment (JRE) version 1.5.0 or higher in order to start. You may already have it installed. Try running this from the command line: • java –version • Once you've got Java installed and ready to go, you can start the Selenium Server from the command line like this: • Go to /selenium directory/server/ • java -jar selenium-server.jar -interactive
Contd.. • That will start the Selenium Server and allow you to type commands in the command window. After a number of log messages, you should see the following message: • Entering interactive mode... type Selenium commands here (e.g: cmd=open&1=http://www.yahoo.com) • Let's begin by using Selenium Server to open up a browser. If you're on Windows and want to run your Selenium commands using Internet Explorer, try typing this: • cmd=getNewBrowserSession&1=*iexplore&2=http://www.google.com
Contd.. • If all goes well, you should see a new browser window starting with the browser of your choice. Back in the Selenium Server command window, you should see the following message: • Got result: OK, 260113 on session 260113
How I Solved this Error?? • When I Test Remote Site through PHPUnit then I was getting following error • Error: Testing_Selenium_Exception: could not get response form RC • I have started My server through following command • Java –jar selenium-server.jar -proxyInjectionMode
ProxyInjectionMode • "Proxy injection" mode is a new highly experimental feature for 0.9.0 ProxyInjectionMode Mode Normal Mode They Keep two automated test windows 1.Selenium 2.Your Application
ProxyInjectionMode • They eliminate the separate Selenium window, in favor of "injecting" Selenium into every HTML page • By injecting ourselves into the HTML, They have increased control over our application • To use PI mode, you need to start the Selenium Server with a special command line argument, like this • java -jar selenium-server.jar –proxyInjectionMode • cmd=getNewBrowserSession&1=*pifirefox&2=http://www.google.com
Test Application in IE • Two way to Test Application in IE • Directly click on .hta file • Through PHPUnit • Elevated Security Privilege • The two experimental "elevated security privilege" browser launchers are: • *iehta: Launches Internet Explorer as an HTML Application (HTA). • *chrome: Launches Firefox using a chrome URL.
Test IE Application with PHPUnit • CASE I: If Selenium Server is in Proxy InjectionMode • Start server in Proxy Injection Mode • Run Selenium IDE and record step with firefox • Go to OptionsFormatPHP-selenium RC • Copy that PHP code and paste in PHPUnit Folder • PHPUnit will be in C:\Program Files\xampp\php\pear\PHPUnit • Make xyz.php file (you could give different Name) • Open that PHP file and change following line from • $this-Selenium= new Testing_Selenium (“*firefox”,http://localhost:4444/); • to • $this-Selenium= new Testing_Selenium(“*iexplore”,http://localhost:4444/); • Now type command phpunit xyz.php • It will open IE browser for you and Test the application
CASE II: If Selenium Server isn’t in Proxy InjectionMode • Start server in Proxy Injection Mode • Run Selenium IDE and record step with firefox • Go to OptionsFormatPHP-selenium RC • Copy that PHP code and paste in PHPUnit Folder • PHPUnit will be in C:\Program Files\xampp\php\pear\PHPUnit • Make xyz.php file (you could give different Name) • Open that PHP file and change following line from • $this-Selenium= new Testing_Selenium (“*firefox”,http://localhost:4444/); • to • $this-Selenium= new Testing_Selenium(“*iehta”,http://localhost:4444/);
DATA-Driven • Code to Fetch Data from Excel Sheet • //code added by Niranjan • $arr=array(1=>'a','b','c','d','e'); • $filename = "c:\Info1.xls"; • $sheet1 = "sheet1"; • $excel_app = new COM("Excel.application") or Die ("Did not connect"); • $Workbook = $excel_app->Workbooks->Open($filename) or Die("Did not open $filename $Workbook"); • $Worksheet = $Workbook->Worksheets($sheet1); • $Worksheet->activate; • //$excel_cell = $Worksheet->Range("A1"); • $excel_cell->activate; • for($i=1; $i<5;$i++) • { • for($j=1; $j<5;$j++) • { • $excel_cell = $Worksheet->Range($arr[$i].$j); • print "The value is $arr[$i].$j => \n" .$excel_cell->value; • } • }
QMetry- Live Example • Add User into Qmetry-UPM module without Repository • Add User with Repository
www.openqa.org/selenium • www.nealford.com • For more Information about Selenium Use my following Blog Address • http://seleniumtest.wordpress.com Thank You Niranjan Limbachiya niranjan.limbachiya@infostertch.com