Per Erik Strandberg /cv /kurser /blog

I just did my first scripted web-test with Selenium.

On a Ubuntu 12.04 LTS machine all I had to do was three ridiculously simple steps:

1 - Install easy_install

In fact this was already done - but I'll demonstrate it here any way:

$ easy_install --version
The program 'easy_install' is currently not installed.  You can install it by typing:
sudo apt-get install python-setuptools

$ sudo apt-get install python-setuptools
[sudo] password for per: 
Setting up python-setuptools (0.6.24-1ubuntu1) ...

$ easy_install --version
distribute 0.6.24dev-r0

2 - Installing Selenium

$ sudo easy_install selenium
[sudo] password for per: 
Searching for selenium
Best match: selenium 2.25.0
Processing selenium-2.25.0.tar.gz
Running selenium-2.25.0/ -q bdist_egg --dist-dir /tmp/easy_install-sQCKSx/selenium-2.25.0/egg-dist-tmp-GH7sWH
warning: no files found matching 'docs/api/py/index.rst'
Adding selenium 2.25.0 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/selenium-2.25.0-py2.7.egg
Processing dependencies for selenium
Finished processing dependencies for selenium

3 - Verifying that the installation was ok

I got this test script of the selenium home page (see [1])

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from import WebDriverWait # available since 2.4.0
import time

# Create a new instance of the Firefox driver
driver = webdriver.Firefox()

# go to the google home page

# find the element that's name attribute is q (the google search box)
inputElement = driver.find_element_by_name("q")

# type in the search

# submit the form (although google automatically searches now without submitting)

# the page is ajaxy so the title is originally this:
print driver.title

    # we have to wait for the page to refresh, the last thing that seems to be updated is the title
    WebDriverWait(driver, 10).until(lambda driver : driver.title.lower().startswith("cheese!"))

    # You should see "cheese! - Google Search"
    print driver.title


I just ran it and it was ok

$ python 
cheese! - Sök på Google

By adding a time.sleep(5) in the finally branch I was able to take a screen shot:

See also Selenium Plus Android

This page belongs in Kategori Programmering
This page belongs in Kategori Test