Tag: "selenium test"

Video Record your Selenium Tests

When a Selenium test fails, you usually get a clear error message or trace to indicate where the problem is located. A video of your Selenium test will offer even more help in finding out just why your Selenium test failed.
By video-recording your Selenium test, you can track down when and where a problem occurs.

We at TestingBot video record every Selenium test on our grid.
When a test fails, you can log into our member area, click the failed test and see a video of your test.
This video is also available through our API, so you can easily integrate this feature into your Continuous Integration system.

Together with a video, we also take a full-screen screenshot of every single step in your test. This provides for another method to examine your tests.
These screenshots are available in our member area or by accessing our API.

It’s important to note that video recording your test does not slow down the execution of your test.
We use the Windows built-in screen recording capabilities, which uses very little CPU.

The video is recorded into a WMV file, then later encoded to an FLV file on a separate server, before it’s available to the customer. This process takes between 1 and 3 minutes to complete.

Below is a Ruby code example of running a test and grabbing the video and screenshots from our API.

require "rubygems"
gem "selenium-client"
require "selenium/client"
gem 'test-unit'
require 'test/unit'

gem "testingbot"
require "testingbot"

class ExampleTest < TestingBot::TestCase
attr_reader :browser
  def setup
     browser = Selenium::Client::Driver.new \
        :host => "hub.testingbot.com",
        :port => 4444,
        :browser => "iexplore",
        :version => "9",
        :platform => "WINDOWS",
        :url => "http://testingbot.com",
        :timeout_in_second => 60

    browser.start_new_browser_session
  end

  def teardown
    browser.close_current_browser_session
  end

  def test_page_open
    browser.open "/"
    p browser.session_id
  end
end

This code will return a String with the session_id of the test (a unique identifier for the test).
For example, the session_id we receive is: “7f5br7939150a9f199d2215920403e83″

You can then query our API to fetch the video and screenshots of this test:

curl -u key:secret http://api.testingbot.com/v1/tests/7f5br7939150a9f199d2215920403e83

This call will return a JSON formatted string with the following data:

				{
					"created_at":"2012-01-20T23:21:23Z",
					"extra":null,
					"id":121453,
					"name":"ExampleTest::test_page_open",
					"session_id":"7f5br7939150a9f199d2215920403e83",
					"status_message":"OK",
					"success":true,
					"thumbs":["https://s3.amazonaws.com/thumbtestingbot/7f5br7939150a.jpg"],
					"video":"https://s3.amazonaws.com/rectestingbot/7f5br7939150a.flv",
					"browser":"IE9",
					"os":"WINDOWS"
				}

The response contains the video URL (https://s3.amazonaws.com/rectestingbot/7f5br7939150a.flv) and the thumbnails of every step in your test.

This is just one example call to our API, for more information, please consult our API guide.

VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

How does a Selenium test work?

Selenium is the industry standard for automatically testing websites in browsers.
A selenium test is a set of instructions that will be sent to a browser of your choice.

Most major programming language offer support for Selenium. Either by plugins or by default.
These plugins will translate language specific syntax to Selenium commands which can be understood by a Selenium Grid.

For example, let’s say we want a test where we will test Google on Firefox. We want to check if the title of the homepage on Google is “Google”.

We start of by specifying which browser we want to use. In Selenese (the syntax used by Selenium), we would use the command getNewBrowserSession together with the options: Firefox and browser version.

This command is sent to the Selenium grid, which is managed by a hub.
The hub will receive the command, check if its grid supports the browser and assign the requester (client) a session.

The client now needs to use this session to further instruct the grid. An example of a session-id would be sofpa92f3fj023jfodsf9.

When we’ve reached this point, the hub has instructed one of its node on the grid (which supports the browser we requested) to start the browser.

Since we want to test Google, we need to instruct the browser on the node to go to google.com.
We do this by sending the “open” command to the grid, together with the URL and our sessionid.
The hub will receive the request, check the sessionid and knows that we previously requested a Firefox browser on a specific node.

Our hub will forward the request to the node, which in its turn will instruct Firefox to open the page and go to the requested URL.

To end our test, we need to verify if the title of the page which is now opened on the node does in fact equal “Google”.
We send a request to the grid, asking our hub to contact the correct node and ask for the title of the current page.

We receive the title back from the grid and verify if the title does in fact equal the title we expect.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)