SlideShare a Scribd company logo
1 of 11
Download to read offline
www.codediesel.com
           Author : Sameer Borate




Selenium IDE
      Tutorial




                     January 2009
PART 1

Selenium IDE is an integrated development environment for performing Selenium tests.
Selenium tests can be written as HTML tables or coded in various languages like C#, PHP, Perl,
Python and can be run directly in most modern browsers. The IDE can help you to record, edit
and debug tests. Currently the IDE is only available for Firefox (as if we developers will use
any other) as a add-on.

Here is a possible scenario for using Selenium. Imagine you have created a HTML form with
about twenty fields and you have to repeatedly test the form. Filling the form every time can
quickly become tedious. With Selenium you can automate the whole process and run the test
as required. In this part we will see how to create a simple test in Selenium. So let’s get
started.

STEP 1 - installation :

You can download Selenium IDE from this locations.
http://selenium-ide.openqa.org/download.jsp
https://addons.mozilla.org/en-US/firefox/addon/2079
Once the add-on is installed make sure you do not forget to restart Firefox.

STEP 2 - running a simple test :

a. Start Selenium IDE in Firefox: Tools->Selenium IDE. You will see the following popup.
b. Click on the red record button on the right.
c. Browse to Google.com and enter ’selenium’ in the search box and click enter.
d. Click on the first result, which is that of selenium.openqa.org.
e. Stop the recording by clicking on the record button.

You should see something like below. If you click on the ‘ Source’ tab you can see the test
html generated by selenium.




The ‘table’ tab shows the commands recorded by Selenium.

f. Open a new tab in Firefox and click on the Selenium IDE’s play button to run the recorded
test.
The IDE should play your recorded test. After the test is complete you should have landed on
the selenium page (http://selenium.openqa.org/). The IDE after the test run is shown below.
In the ‘Log section’ you can see the various events run by the test. In the table tab you can
see that all the rows are green, which means that the test ran successfully.




Now lets add a small assertion to the above test.

a. Click on the blank line below after the last ‘clickAndWait’ command and insert
‘assertTextPresent’ command from the drop down box as shown below. You should see
something like this.
This test checks to see if the text ‘Selenium News’ is present in the last rendered page. Run
the test again and you should see that the test has run successfully. No try replacing the text
with something that is not present on the page, take for example ‘elvis’ and run the test again.
Now the test fails and you should get the screen below.




You have just completed your first test run. And it was so simple.
PART 2
In part 1 of this tutorial you have seen how to write a simple web test using Selenium. In this
part we will see how to use the test generated using the IDE with Selenium RC and PHPUnit.

In this part we will use Delicious as our test target. I’ve already created a small Selenium test
that you can use.

Starting up.
Restart the Selenium IDE. In the source tab replace the default HTML with the one from the
above file. Set the Base URL to http://delicious.com/. After doing this your IDE should like
below.




If you are on a slow internet connection than it may help to slow the test speed.
So what exactly does this test do? Simple:

1. First it opens the delicious home page
2. Then it searches by the keyword ’selenium’
3. Reads the total number of bookmarks from the results page as shown below




Now this may not look like a test for you , but it is just an exercise in using Selenium, you will
surely apply it to a good test case. Onwards…

Before running this test make sure that you are logged out of Delicious.
Now run the selenium IDE test. After the test is successfully completed this is what you should
see in the log pane.




Is that all?
If this was all there was I wouldn’t be really writing this post. The interesting part comes now -
running the same test from PHP. From the file menu select ‘Export Test Case As…’ and as we
are using PHP, select ‘PHP - Selenium RC’. Save the file by the name ‘Example.php’.
This is what we will get in the ‘Example.php’ file.
A short notice.
Before we proceed a few points to consider. Make sure that the file name and the class name
are the same, here ‘Example’. Say if you change the class name to ‘Delicious’ make sure that
you also change the file name to ‘Delicious.php’.

What the code basically does is it initializes the browser to ‘chrome’ (you can set the browser
to your preference by changing to ‘*iexplore’ or ‘*firefox’); sets the baseurl to ‘http://
delicious.com/’ and runs the test.

What's the complex looking line!?
Everything may look fine to you except maybe the last line - ‘$this->getText…’. The function
‘getText’ returns the text found at the element specified in the expression. The complex
looking line is an xpath expression to the results element:




You don’t have to rake your brains to find an xpath to an element. An easy way is to use the
XPather Firefox addon to get the xpath of any element on a page. After you download and in-
stall the addon, restart Firefox, right-click on any element and from the context menu select
‘Show in XPather’. XPather retrieves the xpath to the specified element, which you can than
use in your test code.


Downloading and installing Selenium RC
Selenium RC is a Java based command line server that starts browsers and runs commands
you pass from your tests.

1. First make sure you have a Java runtime installed on your machine.
2. Download Selenium RC from here.
3. After extracting the files from the archive copy the ’selenium-server.jar’ file to any directory
you feel appropriate. I copied it to my PHP installations bin directory.
4. Start the Selenium RC server from the command-line by issuing the following command:

java -jar selenium-server.jar

This will start the server on port 4444.
5. Now the server is ready to accept test commands from your PHP script. Make sure you keep
this server running till you finish testing.


Installing PHPUnit
1. An easy way to install PHPUnit is to use the PEAR installer. The PEAR channel
(pear.phpunit.de) is used to distribute PHPUnit so make sure that it is registered with your lo-
cal PEAR environment:

pear channel-discover pear.phpunit.de

After the channel is registered install PHPUnit:

pear install phpunit/PHPUnit
Actual testing
Now that PHPUnit is installed and the Selenium RC server is up and running, its time to run our
test we saved before in our ‘Example.php’ file. Type the following on your command-line:


phpunit Example

This will start the test. The PHPUnit Selenium driver will execute each test command from your
file and send it to the Selenium server, which does the job of launching the appropriate
browser, opening web pages, and performing various specified actions; and closing the
browser after the test completes.

Now the above test does basically nothing important. So we will add some simple conditional
statements to the code.




This is what PHPUnit has to say about the above test.




Or we can use an assertion as below, deliberately rigged to fail the test:
Now PHPUnit will shout failure:




You can look at more functions to implement in your tests here:
1. http://www.phpunit.de/wiki/Documentation
2. http://selenium-core.seleniumhq.org/reference.html

This concludes the tutorial on selenium.




   ORIGINAL POST
http://www.codediesel.com/php/selenium-ide-tutorial-part-1/

More Related Content

What's hot

Web application testing with Selenium
Web application testing with SeleniumWeb application testing with Selenium
Web application testing with SeleniumKerry Buckley
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using SeleniumNaresh Chintalcheru
 
Selenium Ide Tutorials
Selenium Ide TutorialsSelenium Ide Tutorials
Selenium Ide Tutorialsgueste1e4db
 
Selenium ide material (1)
Selenium ide material (1)Selenium ide material (1)
Selenium ide material (1)Sriram Angajala
 
Selenium introduction
Selenium introductionSelenium introduction
Selenium introductionPankaj Dubey
 
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011Yuriy Gerasimov
 
Selenium test automation
Selenium test automationSelenium test automation
Selenium test automationSrikanth Vuriti
 
#ATAGTR2021 Presentation - "Selenium 4 Observability – a 90 Min Hands on Lab"
#ATAGTR2021 Presentation - "Selenium 4 Observability – a 90 Min Hands on Lab"#ATAGTR2021 Presentation - "Selenium 4 Observability – a 90 Min Hands on Lab"
#ATAGTR2021 Presentation - "Selenium 4 Observability – a 90 Min Hands on Lab"Agile Testing Alliance
 
Test Automation and Selenium
Test Automation and SeleniumTest Automation and Selenium
Test Automation and SeleniumKarapet Sarkisyan
 
Get Started With Selenium 3 and Selenium 3 Grid
Get Started With Selenium 3 and Selenium 3 GridGet Started With Selenium 3 and Selenium 3 Grid
Get Started With Selenium 3 and Selenium 3 GridDaniel Herken
 
Selenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesSelenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesVijay Rangaiah
 
Selenium IDE Introduction, Installation and Working
Selenium IDE Introduction, Installation and WorkingSelenium IDE Introduction, Installation and Working
Selenium IDE Introduction, Installation and WorkingDisha Srivastava
 

What's hot (20)

Web application testing with Selenium
Web application testing with SeleniumWeb application testing with Selenium
Web application testing with Selenium
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
 
Selenium IDE
Selenium IDESelenium IDE
Selenium IDE
 
Selenium Ide Tutorials
Selenium Ide TutorialsSelenium Ide Tutorials
Selenium Ide Tutorials
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Selenium ide material (1)
Selenium ide material (1)Selenium ide material (1)
Selenium ide material (1)
 
Selenium introduction
Selenium introductionSelenium introduction
Selenium introduction
 
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011Automated UI testing. Selenium. DrupalCamp Kyiv 2011
Automated UI testing. Selenium. DrupalCamp Kyiv 2011
 
Selenium test automation
Selenium test automationSelenium test automation
Selenium test automation
 
Selenium (1)
Selenium (1)Selenium (1)
Selenium (1)
 
Selenium
SeleniumSelenium
Selenium
 
#ATAGTR2021 Presentation - "Selenium 4 Observability – a 90 Min Hands on Lab"
#ATAGTR2021 Presentation - "Selenium 4 Observability – a 90 Min Hands on Lab"#ATAGTR2021 Presentation - "Selenium 4 Observability – a 90 Min Hands on Lab"
#ATAGTR2021 Presentation - "Selenium 4 Observability – a 90 Min Hands on Lab"
 
Test Automation and Selenium
Test Automation and SeleniumTest Automation and Selenium
Test Automation and Selenium
 
Selenium ide made easy
Selenium ide made easySelenium ide made easy
Selenium ide made easy
 
Introduction to selenium
Introduction to seleniumIntroduction to selenium
Introduction to selenium
 
Get Started With Selenium 3 and Selenium 3 Grid
Get Started With Selenium 3 and Selenium 3 GridGet Started With Selenium 3 and Selenium 3 Grid
Get Started With Selenium 3 and Selenium 3 Grid
 
Selenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesSelenium Presentation at Engineering Colleges
Selenium Presentation at Engineering Colleges
 
Selenium
SeleniumSelenium
Selenium
 
Selenium IDE Introduction, Installation and Working
Selenium IDE Introduction, Installation and WorkingSelenium IDE Introduction, Installation and Working
Selenium IDE Introduction, Installation and Working
 

Similar to Selenium Ide Tutorial

Similar to Selenium Ide Tutorial (20)

Selenium Testing
Selenium Testing Selenium Testing
Selenium Testing
 
Selenium
SeleniumSelenium
Selenium
 
Selenium by using JAVA
Selenium by using JAVASelenium by using JAVA
Selenium by using JAVA
 
Selenium introduction and some feautures
Selenium introduction and some feauturesSelenium introduction and some feautures
Selenium introduction and some feautures
 
Selenium Tutorial
Selenium TutorialSelenium Tutorial
Selenium Tutorial
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Selenium with testng and eclipse ide
Selenium with testng and eclipse ideSelenium with testng and eclipse ide
Selenium with testng and eclipse ide
 
Selenium
SeleniumSelenium
Selenium
 
Testing Guide
Testing GuideTesting Guide
Testing Guide
 
First steps with selenium rc
First steps with selenium rcFirst steps with selenium rc
First steps with selenium rc
 
Selenium IDE
Selenium IDESelenium IDE
Selenium IDE
 
Creating selenium remote control tests
Creating selenium remote control testsCreating selenium remote control tests
Creating selenium remote control tests
 
Steps to write Selenium
Steps to write Selenium  Steps to write Selenium
Steps to write Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Selenium testing IDE 101
Selenium testing IDE 101Selenium testing IDE 101
Selenium testing IDE 101
 
Sel
SelSel
Sel
 
Selenium By Pravin Mishra
Selenium By Pravin MishraSelenium By Pravin Mishra
Selenium By Pravin Mishra
 
Selenium training
Selenium trainingSelenium training
Selenium training
 
Selenium
SeleniumSelenium
Selenium
 
Selenium Installation
Selenium  InstallationSelenium  Installation
Selenium Installation
 

Recently uploaded

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 

Recently uploaded (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 

Selenium Ide Tutorial

  • 1. www.codediesel.com Author : Sameer Borate Selenium IDE Tutorial January 2009
  • 2. PART 1 Selenium IDE is an integrated development environment for performing Selenium tests. Selenium tests can be written as HTML tables or coded in various languages like C#, PHP, Perl, Python and can be run directly in most modern browsers. The IDE can help you to record, edit and debug tests. Currently the IDE is only available for Firefox (as if we developers will use any other) as a add-on. Here is a possible scenario for using Selenium. Imagine you have created a HTML form with about twenty fields and you have to repeatedly test the form. Filling the form every time can quickly become tedious. With Selenium you can automate the whole process and run the test as required. In this part we will see how to create a simple test in Selenium. So let’s get started. STEP 1 - installation : You can download Selenium IDE from this locations. http://selenium-ide.openqa.org/download.jsp https://addons.mozilla.org/en-US/firefox/addon/2079 Once the add-on is installed make sure you do not forget to restart Firefox. STEP 2 - running a simple test : a. Start Selenium IDE in Firefox: Tools->Selenium IDE. You will see the following popup.
  • 3. b. Click on the red record button on the right. c. Browse to Google.com and enter ’selenium’ in the search box and click enter. d. Click on the first result, which is that of selenium.openqa.org. e. Stop the recording by clicking on the record button. You should see something like below. If you click on the ‘ Source’ tab you can see the test html generated by selenium. The ‘table’ tab shows the commands recorded by Selenium. f. Open a new tab in Firefox and click on the Selenium IDE’s play button to run the recorded test.
  • 4. The IDE should play your recorded test. After the test is complete you should have landed on the selenium page (http://selenium.openqa.org/). The IDE after the test run is shown below. In the ‘Log section’ you can see the various events run by the test. In the table tab you can see that all the rows are green, which means that the test ran successfully. Now lets add a small assertion to the above test. a. Click on the blank line below after the last ‘clickAndWait’ command and insert ‘assertTextPresent’ command from the drop down box as shown below. You should see something like this.
  • 5. This test checks to see if the text ‘Selenium News’ is present in the last rendered page. Run the test again and you should see that the test has run successfully. No try replacing the text with something that is not present on the page, take for example ‘elvis’ and run the test again. Now the test fails and you should get the screen below. You have just completed your first test run. And it was so simple.
  • 6. PART 2 In part 1 of this tutorial you have seen how to write a simple web test using Selenium. In this part we will see how to use the test generated using the IDE with Selenium RC and PHPUnit. In this part we will use Delicious as our test target. I’ve already created a small Selenium test that you can use. Starting up. Restart the Selenium IDE. In the source tab replace the default HTML with the one from the above file. Set the Base URL to http://delicious.com/. After doing this your IDE should like below. If you are on a slow internet connection than it may help to slow the test speed.
  • 7. So what exactly does this test do? Simple: 1. First it opens the delicious home page 2. Then it searches by the keyword ’selenium’ 3. Reads the total number of bookmarks from the results page as shown below Now this may not look like a test for you , but it is just an exercise in using Selenium, you will surely apply it to a good test case. Onwards… Before running this test make sure that you are logged out of Delicious. Now run the selenium IDE test. After the test is successfully completed this is what you should see in the log pane. Is that all? If this was all there was I wouldn’t be really writing this post. The interesting part comes now - running the same test from PHP. From the file menu select ‘Export Test Case As…’ and as we are using PHP, select ‘PHP - Selenium RC’. Save the file by the name ‘Example.php’.
  • 8. This is what we will get in the ‘Example.php’ file.
  • 9. A short notice. Before we proceed a few points to consider. Make sure that the file name and the class name are the same, here ‘Example’. Say if you change the class name to ‘Delicious’ make sure that you also change the file name to ‘Delicious.php’. What the code basically does is it initializes the browser to ‘chrome’ (you can set the browser to your preference by changing to ‘*iexplore’ or ‘*firefox’); sets the baseurl to ‘http:// delicious.com/’ and runs the test. What's the complex looking line!? Everything may look fine to you except maybe the last line - ‘$this->getText…’. The function ‘getText’ returns the text found at the element specified in the expression. The complex looking line is an xpath expression to the results element: You don’t have to rake your brains to find an xpath to an element. An easy way is to use the XPather Firefox addon to get the xpath of any element on a page. After you download and in- stall the addon, restart Firefox, right-click on any element and from the context menu select ‘Show in XPather’. XPather retrieves the xpath to the specified element, which you can than use in your test code. Downloading and installing Selenium RC Selenium RC is a Java based command line server that starts browsers and runs commands you pass from your tests. 1. First make sure you have a Java runtime installed on your machine. 2. Download Selenium RC from here. 3. After extracting the files from the archive copy the ’selenium-server.jar’ file to any directory you feel appropriate. I copied it to my PHP installations bin directory. 4. Start the Selenium RC server from the command-line by issuing the following command: java -jar selenium-server.jar This will start the server on port 4444. 5. Now the server is ready to accept test commands from your PHP script. Make sure you keep this server running till you finish testing. Installing PHPUnit 1. An easy way to install PHPUnit is to use the PEAR installer. The PEAR channel (pear.phpunit.de) is used to distribute PHPUnit so make sure that it is registered with your lo- cal PEAR environment: pear channel-discover pear.phpunit.de After the channel is registered install PHPUnit: pear install phpunit/PHPUnit
  • 10. Actual testing Now that PHPUnit is installed and the Selenium RC server is up and running, its time to run our test we saved before in our ‘Example.php’ file. Type the following on your command-line: phpunit Example This will start the test. The PHPUnit Selenium driver will execute each test command from your file and send it to the Selenium server, which does the job of launching the appropriate browser, opening web pages, and performing various specified actions; and closing the browser after the test completes. Now the above test does basically nothing important. So we will add some simple conditional statements to the code. This is what PHPUnit has to say about the above test. Or we can use an assertion as below, deliberately rigged to fail the test:
  • 11. Now PHPUnit will shout failure: You can look at more functions to implement in your tests here: 1. http://www.phpunit.de/wiki/Documentation 2. http://selenium-core.seleniumhq.org/reference.html This concludes the tutorial on selenium. ORIGINAL POST http://www.codediesel.com/php/selenium-ide-tutorial-part-1/