This time in the self-study python, mainly want to contact with automated testing, in some groping, feel that with Selenium+python automated testing framework to carry out automated testing, the first step is to build the environment first. Search on the Internet a lot of posts, coupled with their own groping, to do some records, hoping to help the needs of the small partners. The steps are as follows:
Step1. Installing python3.6.1
Official website is https://www.python.org/downloads/windows/
(I don't like to install the software on the C drive, which affects the memory, so choose the D drive)
Installation of the choice is a custom installation, check the Add environment variable, just change the installation path, my installation path is D:\Program files\python36, the other is the default hook installation. It is important to note that the PIP is installed after python3.5, and no additional pip is required.
Step2. Installing Selenium
Open cmd, install Selenium in cmd, use the command "Pip install Selenium", install the latest version by default, I install the current update of Selenium 3.3. View its installation directory in: D:\Program files\python36\lib\site-packages
Step3. Install Firefox, installed by default on the C drive.
Step4. Installing Geckodriver
Since selenium3.x began, webdriver/firefox/webdriver/firefox/webdriver.py's _init_, executable_path= "Geckodriver" , while 2.x is executable_path= "wires", in addition to Firefox 47 or more versions, need to download third-party driver, that is, geckodriver;
Download URL https://github.com/mozilla/geckodriver/releases/, I installed is Geckodriver-v0.15.0-win64, decompression can, I unzipped the location is C:\dev\ Geckodriver-v0.15.0-win64, this folder is an EXE file.
Step5. Configure environment variables to add to the path of the environment variable
;D: \program Files\python36\geckodriver-v0.16.1-win64
In this special note, if your Firefox installation location is not a C-drive, if you install the F-drive, you need the path of the Firefox exe.
Step6. Verify success
A small demo, once again to write a simple small case. File name is demo.py
# Coding=utf-8
Import time
From selenium import Webdriver
Driver = Webdriver. Firefox () #打开火狐浏览器
Driver.get (' http://www.baidu.com ') #打开百度界面 driver.find_element_by_id (' kw '). Send_keys (' Selenium ') #在搜索框内输入想要搜索内容 Time.sleep (2) # Browser loading takes time
driver.find_element_by_id (' su '). Click () #搜索完成
Step7. Open Python's idle, file->open this file from the upper left corner, and then press F5 to run the demo file.
Selenium + Python Automated test Framework Setup