Selenium + Python automated test environment setup

Source: Internet
Author: User
Tags seleniumhq

Selenium is a web of automated testing tools, many learning function automation students began to prefer selenium, compared with QTP because it has a lot of a bit:

* Free, no need to crack QTP and big headache

* Small, for different languages it's just a package, and QTP needs to download and install 1 + G programs.

* This is also the most important point, whether you are more familiar with C, Java, Ruby, Python, or all C #, you can complete automated testing via selenium, while QTP only supports VBS

* Multi-platform support: Windows, Linux, MAC, multi-browser support: IE, FF, Safari, opera, Chrome

* Support the execution of distributed test cases, can distribute test cases to different test machine execution, equivalent to the function of the dispenser.

The basics of selenium with the Java platform, I have previously written a "Rookie Learning Automation Test" series, recently learned Python, so want to try to selenium in the Python platform how to build; Fortunately this method of the article is very easy, here will build steps to organize and share.

Build platform Windows

The preparation tools are as follows:

-------------------------------------------------------------

Download python

https://www.python.org/

-------------------------------------------------------------

If you are a newly-learned python, which you do not want to use the package is must rely on pyhton2.x, then please do not hesitate to choose python3.5 Bar!

Window Installation steps:

1. Download the Python installation.

https://www.python.org/downloads/release/python-351/

Depending on your operating system 32/64 bits, select the appropriate version.

The installation process I do not need to describe, my installation directory is: C:\Python35

2. Enter the "python" Command under CMD (Windows command Prompt).

(If you are prompted that Python is not an internal or external command!) Don't worry, just configure the environment variable.)

Modify My Computer, properties, advanced-environment variable--the path in the system variable is:

Variable name: PATH

Variable value:; C:\Python35; C:\Python35\Scripts;

3, installation Selenium

3.1. Install via PIP

c:\users\fnngj>python3-m pip Install Selenium

3.2. Install by download package

or download the Selenium package directly:

Https://pypi.python.org/pypi/selenium

Unzip, cmd into the directory:

c:\selenium\selenium2.53.5> python3 setup.py Install

===============================================

How to install under Ubuntu:

1. Installation: Setuptools

[Email protected]:~# apt-get Install Python-setuptools

2. Install Pip

[Email protected]:/home/fnngj/python# tar-zxvf pip-1.4.1.tar.gz

[Email protected]:/home/fnngj/python# cd PIP-1.4.1/

[Email protected]:/home/fnngj/python# python setup.py Install

3, installation Selenium

[Email protected]:/home/fnngj/python/pip-1.4.1# pip Install-u Selenium

Congratulations! Your early work has been done, the above steps are really a bit cumbersome, but not difficult, but we have finished, let's experience the results! Take the example on the Python website:

From selenium import webdriverfrom selenium.common.exceptions import Nosuchelementexceptionfrom Selenium.webdriver.common.keys import Keysimport timebrowser = Webdriver. Firefox () # Get Local Session of Firefoxbrowser.get ("http://www.yahoo.com") # Load Pageassert "Yahoo!" in Browser.titleele  m = Browser.find_element_by_name ("P") # Find the query Boxelem.send_keys ("SELENIUMHQ" + Keys.return) Time.sleep (0.2) # Let The page load, would be is added    to the Apitry: Browser.find_element_by_xpath ("//a[contains" (@href, '/HTTP// Seleniumhq.org ')] except nosuchelementexception:    assert 0, "can ' t find Seleniumhq" browser.close ()

(If an error occurs during the run:

Webdriverexception:message:u ' unexpected error launching Internet Explorer.

Protected Mode settings is not the same for all zones. Enable Protected Mo

De must is set to the same value (enabled or disabled) for all zones. '

To change the Internet options for IE, safely, remove the Enable protection mode from the internet/local internet/trusted standing/restricted site, or all the hooks. )

-----------------------------------------

A good document for selenium + python

Http://selenium.googlecode.com/git/docs/api/py/index.html

=========================== If you want to run a script from another browser (IE Chrome) =================================

Install Chrome Driver

Chrome driver is here.

1. Download unzip, you will get a Chromedriver.exe file (I click to open, run hint started no prot 9515, what is this? Is port 9515 accounted for? In the middle of the day), only then know the need to put this guy in the Chrome installation directory ... \google\chrome\application\, then set the PATH environment variable, put Chrome's installation directory (my: C:\Program files\ Google\chrome\application), and then call run:

# coding = Utf-8from Selenium Import webdriverdriver = Webdriver. Chrome () driver.get (' http://radar.kuaibo.com ') print driver.titledriver.quit ()

And made a mistake:

Chrome version must be >= 27.0.1453.0\n (Driver info:chromedriver=2.0,platform=windows NT 5.1 SP3 x86)

said that my chrome version is not greater than 27.0.1453.0, this is good to do, update to the latest version can be.

Installing IE Driver

In the new version of Webdriver, only IE driver is installed to test the work using IE.

IE driver here, remember to download the corresponding driver according to the operating system version of your machine.

For the time being, it should be similar to how chrome is installed.

Remember to configure the protection mode of IE

If you want to use Webdriver to start IE, then you need to configure the protection mode of IE.

The protection mode in IE is selected or all can be ticked off.

How to install ethanol:

http://easonhan007.github.io/python/2013/05/07/setup-env/

5 minutes to install the Selenium Webdriver + python environment:

Http://v.youku.com/v_show/id_XNjQ1MDI5Nzc2.html?qq-pf-to=pcqq.group

Selenium + Python automated test environment setup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.