Automatic framework construction of selenium + Python

Source: Internet
Author: User

SeleniumIsWebOfAutomated TestingTools, andOthersCompared with the automated tools, the main features of the tool are cross-platform and cross-browser.
SupportedWindows, Linux, Mac, supporting IE, FF, Safari, opera, chrome, etc.
Another feature is the support for distributedTest CasesTo distribute test cases to different test machines, which is equivalent to the distribution machine function.

For the principles, architecture, and usage of selenium, refer to the information on its official website. Here we record how to set up an application.PythonSelenium test case development environment. Actually, Python
There are two ways to develop Selenium: one is to download the Python version of selenium engine from the selenium official website; the other is to build the robot automation framework, and then install the robot
Selenium plug-in.

Here we record the first build method:
1. Download and install setuptools for Windows. [this tool is a basic Python package tool]
2. download and install the PIP tool. [this tool is a python installation package management tool, similar to the aptget tool of ubuntu]
3. Run the PIP command to install selenium.
4. Test the demo script

Specific installation operations:
1. Go to this address to renew]
2. Install the installation package for windows, but the corresponding Python version is required.
3. Go to the address http://pypi.python.org/pypi/pipto download pipw.pip-1.0.2.tar.gz]
4. decompress the package with WinRAR and run the command line to enter its directory. Enter the command: Python setup. py install
5. directly use Pip to install selenium. The command is Pip install-u selenium.
6. Call the test script [Python demo. py] on the command line]

If the test is successful, you can see that the browser is opened and then runGoogleSearch. In addition, selenium is available in versions 1 and 2. Selenium of version 2 is installed here.
Appendix: The Script content of the demo is as follows:

#!/usr/bin/python# -*- coding: gb2312 -*-from selenium import webdriverfrom selenium.common.exceptions import TimeoutExceptionfrom selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0import time# Create a new instance of the Firefox driverdriver = webdriver.Chrome()# go to the google home pagedriver.get("http://www.google.com")# find the element that's name attribute is q (the google search box)inputElement = driver.find_element_by_name("q")# type in the searchinputElement.send_keys("Cheese!")# submit the form. (although google automatically searches now without submitting)inputElement.submit()# the page is ajaxy so the title is originally this:print driver.titletry:    # 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.titlefinally:    driver.quit()#==================================

Related Article

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.