Sunteți pe pagina 1din 3

Selenium IDE

Selenium is an open source tool for web application testing. This tool is primarily developed in Java Script and browser technologies and hence supports all the major browsers on all the platforms. For example, you can have your automation scripts written for Firefox on Windows and run them on Firefox in Mac. Most of the time, you will not need to change your scripts for them to work on Mac. In terms of coverage for platform and browser, Selenium is probably one of the best tool available in the market for web applications. There are three variants of Selenium, which can be used in isolation or in combination to create complete automation suite for your web applications.

Selenium IDE Selenium Core Selenium Remote Control

In this article, we will discuss Selenium IDE. Subsequent articles in the series will cover Selenium Remote Control and Selenium Core as well. Selenium IDE Selenium IDE is the easiest way to use Selenium and most of the time it also serves as a starting point for your automation. Selenium IDE comes as an extension to the Firefox web browser. This can be installed from either openqa or mozilla distribution site. Selenium extension will be downloaded as XPI file. If you open this file using File -> open in Mozilla, it should get installed. Biggest drawback of Selenium IDE is its limitation in terms of browser support. Though Selenium scripts can be used for most of the browser and operating system, Scripts written using Selenium IDE can be used for only Firefox browser if it is not used with Selenium RC or Selenium Core. Selenium IDE is the only flavor of Selenium which allows you to record user action on browser window. It can also record user actions in most of the popular languages like Java, C#, Perl, Ruby etc. This eliminates the need of learning new vendor scripting language. For executing scripts created in these languages, you will need to use Selenium Remote Control. If you do not want to use Remote Control than you will need to create your test scripts in HTML format. So if you are excited about the tool, Lets start playing with Selenium IDE now. If installed properly, Selenium can be accessed from tool --> Selenium IDE in your browser toolbar. As compared to most of the test automation tools it is very simple and lightweight. The small red button on the right hand side gives you an indication on whether Selenium is in recording mode or not. Also, Selenium IDE will not record any operation that you do on your computer apart from the events on Firefox browser window. So go ahead read your mail, open a word doc or do anything else, Selenium will record only your actions on browser. If you are curious to know about other options present on the Selenium IDE, there are not much :) . Other options present on the Selenium IDE toolbar are related to test execution. Run will execute the tests with the maximum possible speed, Walk will execute them with relatively slow speed and in step mode you will need to tell Selenium to take small steps. Final button present on the Selenium IDE toolbar is the Selenium TestRunner. Test Runner gives you nice browser interface to execute your tests and also gives summary of how many tests were executed, how many passed and failed. It also gives similar information on commands which were passed or failed. TestRunner is also available to tests developed in HTML Only. If you open the option window by going to Option , you will see there are some self explanatory options available. For example, encoding of test files, timeout etc. You can also specify Selenium Core and Selenium IDE extensions on this page. Selenium extensions can be used to enhance the functionality provided by Selenium. Selenium extensions are not covered in this article, there will be a separate article for specifying and developing extensions for Selenium. Selenium IDE Commands & Steps >>>

Selenium IDE Contd..


Another tab in the Selenium Options window is Format, As mentioned earlier,

Selenium IDE can generate code in variety of languages, this page gives you an option of specifying what kind of formatting you would like in the generated code. For example, what should be the header, how it should be indented etc. Lets start some action now, In the options, select format and specify HTML as your language choice for your automation. Notice that, when you select HTML as your choice of language, additional tab appears on the Selenium IDE called Table. There are three columns under this Table - Command, Target and Value. This Table is the crux of how Selenium works. For any element present on the browser, Selenium maps its action in command, target and value. For example, if you want to type user name in the user name text box Selenium would translate it as command=type , Target=username text box and value=your username For commands related to asserts, value can be used to compare the value. For example command=assertText ,Target=Label and Value=somethingtocompare. In this case Selenium will compare value of the target with the specified value in subsequent execution. Selenium gives you enough functionality in terms of identifying Target. You can locate or identify target using DOM, ID, Name, XPath etc. This helps you in making a robust automation framework. You might find it useful to try Firefox extensions like DOM Inspector or XPath Viewer to get information about the XPath or DOM information of the GUI element under test. This information should be sufficient for you to explore Selenium IDE and get started with the tool. Lets summarize all the steps involved -

Make sure you have installed Selenium IDE in Firefox. Open Firefox and application you want to test Launch Selenium IDE using tools-Selenium IDE By default, you should be in the recording mode, but confirm it by observing the Red button. Select HTML Format. Record some actions and make sure that these are coming on Selenium IDE. During recording if you right click on any element it will show all the selenium commands available. You can also edit existing command, by selecting it and editing on the boxes available. You can also insert/delete commands by choosing appropriate option after right clicking. Choose appropriate run option - i.e walk, run or test runner and review your results.

Hope this article was helpful for you in next article we will discuss how Selenium IDE can be used with Selenium Remote Control to write scripts in different languages. As always, your feedback about this article are welcome.

Selenium Remote Control


In the previous Selenium article, we discussed what is Selenium and how Selenium IDE can be used to automate your web applications. We also learnt about the limitations of Selenium IDE in terms of language support (Only Selenese ) and browser support (Firefox only) . These limitations can be diminished by using Selenium Remote Control. Selenium RC can be used for automating web applications for different web browsers on different platforms using your favorite language like JAVA, C#, Perl, Python, Ruby etc. You can use Selenium RC with or without Selenium IDE. Though, You might find it easier to start with Selenium IDE and than move to Selenium RC for customization and making your automation more robust. Selenium RC is a java server which allows you to interact with the web application using any language. Your script ( If not hosted along with your application on the server) can not talk to your web application directly because of the security restrictions enforced by browser ( Same origin policy ). Using selenium server, you can bypass this restriction and have your automation scripts running against any web application. There are still some limitations, for example crossing domain boundaries, using it for https etc., but you can find solutions for most of them. Selenium RC server is written in Java and in order to use Selenium RC you should have java runtime environment (newer than 1.5) installed on your machine. Assuming that you have downloaded and unzipped Selenium Remote Control from openqa.org and also have java runtime on your system, you can launch Selenium Remote Control server using

following command ( Make sure that you are into directory where selenium-server.jar is located or this directory is in your path variable ) java -jar selenium-server.jar This command should start Selenium Server on your machine and your automation scripts are ready to interact with your web application using this server. You can leave this server up and running while you are developing and executing your automation scripts. If you wish, you can also start Selenium Remote Control in interactive mode and start playing with its various commands on command prompt itself. In order to do that, you need to supply a command line option called interactive. java -jar selenium-server.jar -interactive There are many command line options that you can specify while starting selenium RC. Some of the interesting options are multiWindow , forcedBrowserMode, userExtensions, browserSessionReuse and many more. For now lets move on to client drivers for Selenium, so that you can start using it. In the above paragraphs, we discussed that using Selenium RC you can automate your web application in most of the popular languages. This support is provided by the mechanism of client drivers. These client drivers provide the functionality to write automation script in any language and interaction with the Selenium Remote Control Server. Client drivers for most of the languages are already available and since it is open source you can create your own client driver if it is not available for your language. Details of extending existing client drivers or creating your own client driver can be found on openqa's website. Once these client drivers are available, you can create a Selenium object in your automation script by specifying host name and port of the Selenium server. Using this Selenium object you can handle all the browser specific tasks for your web application. Some of the well known and popularly known client drivers are distributed along with the selenium RC itself. If you notice the directories where you unzipped the Selenium RC, you will find folders for various languages like Java, Perl, Python etc. Detailed instructions of using these client drivers are available on the respective section in openqa, we will summarize them here very briefly.

Java - selenium-java-client--driver.jar should be in the classpath, you can use this with JUnit or TestNG .NET - add the ThoughtWorks.Selenium.Core.dll assembly as a reference to your VS project, use it with NUnit Perl - Install Test::WWW::Selenium . You will need make (on unix) or nmake (on windows) in order to use it. You will also find it useful to use Test::more Ruby - To use the Ruby Client Driver, just "require" or "load" selenium.rb in your Ruby script and create a new Selenium::SeleneseInterpreter object

Similarly, for any client driver steps are more or less same. i.e, install or use driver so that Selenium object can be created in your automation scripts which can interact with the browser. If you have followed along, at this point you should have Selenium RC server up and running and you have also installed Selenium client drivers. You can now create your automation scripts and run them as you would run any program in the language of your choice. For example java YourAutomationClass perl AutomationScript.pl ruby AutomationScript.rb And so on.. Though you can write your automation scripts using Selenium RC alone, we have found it very easy to start with Seleinum IDE and export test cases in specific language. Once you have basic test case, you can use language specific features to customize them and making them more robust. Hope you have found this article on Selenium RC useful. In the Next article, we will touch upon Selenium Extensions and Selenium core in more detail.

S-ar putea să vă placă și