Current location - Education and Training Encyclopedia - Resume - How to Build python+selenium Automated Testing Framework
How to Build python+selenium Automated Testing Framework
Selenium? Is a web-oriented automated testing tool. Many students who study functional automation choose selenium first. , because it has many advantages compared with QTP:

* Free, and you don't have to worry about cracking QTP.

* Small, just packages in different languages, QTP needs to be downloaded and installed 1 multi-G? This project.

* This is also the most important point, whether you are more familiar with C or not. Java, ruby, python, or all C#? , you can complete automated testing through selenium, and QTP only supports VBS?

* Support multiple platforms: windows, linux, MAC? , supports a variety of browsers: ie, ff, safari, opera, chrome.

* Support the execution of distributed test cases, which can be distributed to different test machines for execution, which is equivalent to the function of distributor.

Regarding the combination of selenium's basic knowledge and java platform, I have written a series of "Automatic Test for Beginners" before, and recently learned python, so I want to try how selenium is built on python platform. Fortunately, the article of this method is very easy, so I will sort out and share the construction steps here.

Build a windows platform?

The preparation tools are as follows:

-

Download python

-

If you are a freshman in python, if you don't have any packages that need to rely on pyhton2.x, please choose python3.5 without hesitation!

Windows installation steps:

1. Download python installation.

According to your own operating system 32/64 bits, choose the corresponding version.

I don't need to describe the installation process. My installation directory is: C:\Python35.

2. Enter cmd(windows command prompt) and enter the "python" command.

If python is not an internal or external command! Don't worry, configure environment variables)

Modify my computer-> Attribute-> Advanced-> Environmental variables->; The path in the system variable is:

Variable name: path

Variable value:; c:\ python 35; c:\ python 35 \ Scripts; ?

Step 3 install selenium

3. 1. Install through pip

c:\ Users \ fnngj & gt; Python3 -m pip contains selenium?

3.2, through the download package installation

Or download selenium package directly:

Unzip, cmd to directory:

C:\ Se \ Se 2.53.5 > Python3 setup.py installation

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

Installation method under ubuntu:

1. installation: setuptools

root@fnngj-H24X:~#? Apt-get installs python-setuptools.

Step 2 install pip

root @ fnngj-H24X:/home/fnngj/python #? tar-zxvf pip- 1 . 4 . 1 . tar . gz

root @ fnngj-H24X:/home/fnngj/python #? cd pip- 1.4. 1/?

root @ fnngj-H24X:/home/fnngj/python #? Python setup.py installation

Step 3 install selenium

root @ fnngj-H24X:/home/fnngj/python/pip- 1 . 4 . 1 #? pip install -U selenium

Congratulations ~ You have done the preliminary work. The above steps are really complicated, but they are not difficult, but we have finished them. Let's experience the results! ? Take the example on python website as an example:

Import webdriver from selenium import nosuchelementexception from selenium. webdriver.common.keys import key import time.

Browser = webdriver. Firefox()# Get Firefox browser . Get(" hto . com ")# Load page assert " Yahoo!" In the browser. title

Elem = browser.find _ element _ by _ name ("p") # Find the query box elem.send _ keys ("Selenium HQ"+keys. Return)

Time.sleep(0.2) # Let the page load and add it to APItry:

browser . find _ element _ by _ XPath("//a[contains(@ href,'? Explorer.

Protected? Mode? Settings? Is it? Isn't it? That? Same? For what? All of them? Area. ? Enable? Protected? molybdenum

De? Must? Is it? Settings? Where to? That? Same? Value? (enabled? Or? Disabled)? For what? All of them? Area. ?

Change internet options for IE-> Security, delete all enabled protection modes from Internet/local Internet/trusted sites/restricted sites? Put it down or hook it all. )

-

Selenium? +? A good python document.

= = = = = = = = = = = = = = If you want to run the script through other browsers (namely Chrome) = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Install Chrome? driver

chrome? The driver download address is here.

1.? Download and unzip, and you will get a chromedriver.exe file (I click Open and run the prompt to start? No? Porter. 95 15? , what is this for? Is port 95 15 occupied? I struggled for a long time), and then I realized that I needed to put this guy in the installation directory of chrome ... \Google\Chrome\Application\? , and then set the path environment variable, and put the installation directory of chrome (my: C:\Program? Files \ Google \ chrome \ application), and then call Run:

# coding = utf-8 from selenium import web driver driver = web driver。 Chrome()driver.get('http:om') prints driver.title

driver.quit()

Another mistake is:

Chrome? Version? Must? Is it? & gt=? 27.0. 1453.0\n (drive? Information:? Chromedriver=2.0, platform =Windows? NT? 5. 1? SP3? x86)

Say that my chrome version is not greater than 27.0. 1453.0? This is easy to handle, just update to the latest version.

Install IE? driver

Only ie is installed in the new webdriver? The driver is tested with ie.

ie? The download address of the driver is here. Remember to download the corresponding driver according to the operating system version of your machine.

I haven't tried it yet. It should be similar to the installation method of chrome.

Remember to configure IE's protection mode.

If you want to use webdriver to start IE, you need to configure IE's protection mode.

Just select all protection modes in IE or check them.