SeleniumThe Ultimate Automated test Environment Setup (II.)Selenium+eclipse+python
The previous example of the selenium+eclipse+junit+testng Automated test environment, on the basis of the previous article, the following example Selenium+eclipse+python test Environment Setup.
First step: InstallPython
According to the following address, the direct one-click installation, all the default mode.
: Http://www.python.org/ftp/python/2.7.5/python-2.7.5.msi
Install to C:\Python27, set Python environment variable,Path = E:\Python27; (Previous installation JDK , there has been Path environment variables, which can be added directly to the front, note Python27 behind the '; ' )
Step Two: InstallPythonof theSetuptools
In fact, Setuptools is a tool to help you install third-party toolkit software, download it according to the following address, and then press the Next button to install.
Setuptools-0.6c11.win32-py2.7.exe.exes
:
Http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11.win32-py2.7.exe#md5=57e1e64f6b7c7f1d2eddfc9746bbaf20
Step Three: InstallPythonThe package management toolpip-It 's similar .Setuptools,but it's stronger than it .
using the second-step installation Setuptools to install, open DOS interface, go to directory:
C:\Python27\Scripts, then typing the command: easy_install pip, wait for the completion to be OK.
Fourth step: Install based onPythonof theSeleniumPackage
Open the DOS interface and go to directory: C:\Python27\Scripts
Then typing command: pip install selenium or pip install–u Selenium(after using a seemingly error, with the previous one can be installed. )
Installation may have some warning, no tube, after installation, as follows,
Fifth Step: Verify Selenium whether the installation was successful
write the following code in Notepad: (Save as pytest.py , then double-click to run directly! )
From selenium import Webdriver
Browser = Webdriver. Firefox ()
Browser.get ("http://www.yahoo.com")
Assert "Yahoo!" in Browser.title
Browser.close ()
If the code runs successfully, it means that the Selenium installation was successful! Very good!
Sixth step:pythonThe development environment configuration-eclipse-pydevplug-in installation
Two installation methods for installing the PyDev plug-in:
1 , Baidu Search PyDev 2.4.0.zip , unzip after download, get Plugins and the Feature folder, copy two folders to Eclipse directory, can be overwritten.
Restart after completion Eclipse , if the Eclipse Menu help->about eclipse->installation detail->plug-ins , can see PyDev component, the installation is successful.
2 , directly in Eclipse Select the menu: help-install New software. -add, enter http://pydev.org/updates, download and install.
Configure PyDev
After installing The PyDev, the Python/jython interpreter needs to be configured and the configuration process is simple.
InEclipsemenu bar, selectWindow > Preferences > Pydev > Interpreter-python, configure herepython/Interpreter,add an already installed interpreter. Here,Pythoninstalled inC:\Python27the path. ClickNew, selectPythonInterpreterPython.exe, opens a window with many checkboxes, selects the system to be added PYTHONPATH's path, clickOk.
Seventh Step: Execute Selenium instance
Next, let's create a python project.
In the Eclipse menu bar, choose File > New > Project > Pydev > PydevProject, new project:Python Case, click Next.
Complete the following:
Creating Python packages and modules
Next, start creating Python packages and modules in the project you just created.
Into the Pydev perspective, in the Python package Explorer , right-click srcand select new- >pydevPackage, enter the package name Python27.
When you click Finish,thePython package is created , and the __init__.py file is automatically generated. The file does not contain any content.
Attention:
If the Create default src folder and add it to the Pythonpath check box is not selected when creating the project , you need to pass File > New > O ther > Source folder Create a manual file manually src.
After you create the Pydev package, right-click the created bundle, select new->pydevmodule, enter the module name pythoncase1.py Finish . In this way,thePython module is built.
Modify the pythoncase1.py content as follows:
#-*-Conding=utf-8-*-
From selenium import Webdriver
if __name__ = = "__main__":
Driver = Webdriver. Firefox ()
Driver.implicitly_wait (30)
Driver.get ("http://www.google.com.hk")
Driver.find_element_by_name ("Q"). Send_keys ("Hello selenium!")
Driver.find_element_by_name ("Q"). Submit ()
print ' Page title is: ', driver.title
Driver.quit ()
Execute script
Run run_selenium.batand start the selenium RC server. Right-click pythoncase1.py,run As->python run, to perform the following successful results:
Selenium Ultimate Automated Test Environment Construction (ii) Selenium+eclipse+python