Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up Selenium for recording as well as running in different browsers and platforms

I'd like to setup a Selenium server so that clients can record tests locally, recorded tests can be replayed and tested on an Ubuntu server with Firefox + Chrome.

Unfortunately the Selenium site is so confusing and mentions so many different projects (Selenium 1, Selenium 2, Selenium RC, Selenium Grid) that I'm not sure where to start.

How do I go about setting up Selenium Server on an Ubuntu box?

like image 786
Tom Avatar asked Jun 07 '11 11:06

Tom


People also ask

How do I run a Selenium script in multiple browsers at a time?

Create an XML which will help us in parameterizing the browser name and don't forget to mention parallel="tests" in order to execute in all the browsers simultaneously. Execute the script by performing right-click on the XML file and select 'Run As' >> 'TestNG' Suite as shown below.

Does Selenium support multiple platforms?

Selenium test scripts can be written in different programming languages like Java, Python, C# and many more. These test scripts can run across various browsers like Chrome, Safari, Firefox, Opera and also provides support across various platforms like Windows, Mac OS, Linux, Solaris.

Does Selenium support record and playback?

Record And Playback in Selenium is an easy process of creating test cases by simply using the web browser and performing several steps that need to be included in the test cases. Selenium IDE is the ultimate tool for using Record and Playback.

Which Selenium tool provides record and playback feature?

Testers can use Selenium IDE, an open source record and playback tool, within web browsers like Chrome and Firefox to evaluate web app UIs. The tool offers useful features for modern development teams.


3 Answers

Unfortunately the Selenium site is so confusing and mentions so many different projects (Selenium 1, Selenium 2, Selenium RC, Selenium Grid) that I'm not sure where to start.

Selenium has multiple versions

  1. IDE - mainly to record the test and play it back. It is mainly a Firefox Addon. This can be used for very basic testing. You can also export the recorded test to selenium RC. All these mentioned in seleniumhq.org->documentation section: http://docs.seleniumhq.org/docs/

  2. RC - Like any other automation tool, you can write your own code to run the test rather than just recording and playing it back. This has far better capabilities than IDE including support for several languages (Java, Javascript, Ruby, PHP, Python, Perl and C#) and support for almost every browser out there in various platform.

  3. Grid - This helps in running multiple tests in parallel.

To record and run the test in Firefox (NOT CHROME) its very easy. This doesn't require a selenium server running.

  1. record the whole test

  2. save it in a file

  3. Copy the file to Ubuntu machine

  4. Open the same test using IDE in Ubuntu machine and run it again in firefox

If you want to run on chrome, then you need to go to the next level of using selenium RC. And this requires the selenium server running.

How do I go about setting up Selenium Server on an Ubuntu box

Download selenium-server jar from here. Copy this to any directory in your ubuntu server

Open a terminal and navigate to the folder which has the selenium server jar.

Enter java -jar selenium-server-jarfilename.jar

Selenium server will start on port 4444 by default and keep listening to the tests.

like image 195
A.J Avatar answered Nov 09 '22 23:11

A.J


The site is confusing in terms of the versioning and names. Selenium is the name of the entire project which started off as Selenium RC (remote control). Selenium RC is the old version of the API which is also sometimes called Selenium 1. Selenium 2 is the newest version and the latest release was last week being Selenium RC2 (release candidate). This uses a different API to Selenium RC. The new API is known as WebDriver. The new API still allows you to access the older Selenium RC but only for backwards compatibility.

Since you're starting now, there is no reason for you to use the Selenium RC API. You should instead use the advanced user interactions which are part of WebDriver. Setting up WebDriver is pretty easy and there is a decent guide on it here. You should note that the API used there is the older standard (2.0 beta) which uses WebElements. The new API (advanced user interactions) decouples actions from the elements they are performed on a lot more. I would recommend you use the latest versions of the API which is being actively supported rather than older deprecated versions.

Since you want to do this all locally, the second link I gave you should be enough to get you up and running. Assuming you're going to be using the Java bindings it is as simple as:

public class Selenium2Example  {
    public static void main(String[] args) {
        // Create a new instance of the Firefox driver
        // Notice that the remainder of the code relies on the interface, 
        // not the implementation.
        WebDriver driver = new FirefoxDriver();

        // And now use this to visit Google
        driver.get("http://www.google.com");
        Actions builder = new Actions( driver );
        builder.sendKeys( driver.findElement( By.name("q") ), "Cheese!" );

        Action action = builder.build();
        action.perform();

        //Close the browser
        driver.quit();
    }
}

This is the example code edited to use advanced user interactions.

like image 41
Mike Kwan Avatar answered Nov 10 '22 00:11

Mike Kwan


You must have two things to write and execute selenium tests.

1) Selenium Server is also known as Selenium RC (Remote Control). You can go to this link and download Selenium Server. You can start selenium server with command java -jar ur_selenium_server.jar

2) Client Driver: Using client-driver you can code selenium tests. It consists of combination of selenium commands that perform certain actions on the UI. For e.g. click, select etc. Selenium supports many different language bindings for client-driver. Download appropriate client-driver for your preferred language from above download page.

You can refer client driver apis and code your tests.

Hope this helps

like image 22
Vaman Kulkarni Avatar answered Nov 09 '22 22:11

Vaman Kulkarni