Hi all of you who are interested in Selenium testing. I'll jot down a little tutorial here that should help you start using Selenium RemoteControl Things to useSeleniumIt comes in two useful shapes: Selenium IDE and Selenium RC. Download both.IDE is a Firefox extension, so you'll need this browser too. Selenium IDE is helpful with 'real-time' building of your tests. You'll use it to check how your test works, where it fails, what errors it throws. It also provides the insight to all the Selenium commands and their usage. RC is a server that behaves as a proxy - your commands go through this server and end up as javascript commands in browser. Result of these commands (handled by browser) is then returned through server to your test. That's how you communicate with the browser. Unlike IDE, Selenium RC is capable of running tests on any browser you provide, most important of which being Internet Explorer. Selenium RC has two parts: a server (in Java) and some clients (in different languages - Java, Ruby, Perl, .Net, Php, Python). This means that you'll need Java installed to run server. This also means that you can create tests in different languages. Apache AntAnt is not really needed, but it helps a lot. Download it, extract it somewhere and add its "/bin" directory to path (see here). With Ant you can automate your processes (in this case - starting your tests). If you, for instance, create tests in Java, you can compile your code, export it to some directory, start Selenium server, start tests and write test results to some file, all using a single Ant script.FirebugWhatever you do with web applications, Firebug will come handy. Among other things, it allows you to get details of any HTML page element, which is crucial for creating Selenium tests. Firebug is a Firefox extension and can be easily installed.How to use it1. Install Ant (as described above; google a bit for details)2. Unpack Selenium RC (I'll refer to this directory as SEL_HOME) 3. Create a directory SEL_HOME/tests with directories 'src' and 'build'. Create a file called 'build.xml' in 'tests' directory. File system should now look like this: 4. Under 'src' directory create another called, for instance, 'mytests' and there create "Login.java" file Now you have your environment set for testing. We need to create a test in "Login.java" file and an Ant script in "build.xml" to get everything going Create a testEdit "Login.java" file and enter something like this:package mytests;Be sure to change Firefox options to suit your needs!! Change "profile" path and path to firefox.exe Create an Ant scriptUse the build.xml file attached at the bottom of this page. This file says the following:1) default target of this script is "run_tests" 2) this target depends on the target "compile", so run "compile" first. 3) "compile" deletes 'build' directory and creates the fresh, empty one 4) "compile" uses "javac" compiler to compile your ".java" files (like Login.java") from 'src' directory. Compiled classes are put to 'build' directory. In order to compile your classes, classpath is provided containing all the jars (classes). That's the jars/classes contained in "selenium server" and "selenium java client" directories. Google a bit if you don't understand the classpath notion. 5) When compilation finishes, jUnit runs a test "mytests.Login" and writes the results to "result" file. That's all that is needed to start tests. Configure FirefoxIn order for this script to work well, you need to set up Firefox correctly. Set its connection to use selenium server as a proxy. Find more about this on this link.Run everythingFirst start the server:java -jar SEL_HOME\selenium-server-1.0-beta-1\selenium-server.jar Then start your tests: in console change the directory to SEL_HOME\tests and then enter "ant". This should start your script. TroubleshootingSeveral things might happen with this configuration.1. Firefox instance might be blocking the new, Selenium's instance of the browser. Check the processes (ctrl-shift-esc) and kill the firefoxes you don't need. 2. Firefox might ask for https certificate. Add the certificate as an exception. Some hints can be found here. 3. Firefox might ask weather to open previous sessions or not. Choose not to open previous sessions. 4. Firefox might prevent Selenium opening a popup. Select always to allow the site opening popups. |
