Foreplay
I believe everyone is familiar for web automation selenium, is a web automation framework, my first company when the product is a version two weeks, every time release testing should be carried out regression testing, that is, it says little point , but then I thought, can not be made automatic, so the code to back my regression testing, every day after work, to study selenium's api, then finally use selenum + python to write a web automated testing framework, each return just run the program when the program will automatically execute for me, I met with failure cases would give me write screenshots and error messages, I just look at the use case of failure can be, greatly reducing my return testing time. How it compared to that selenium and QTP automation? Look at the following comparison
* Free, QTP also no longer need to crack a big headache
* Compact, for it is just a different language package, but rather the QTP need to download and install more than one program G's.
* This is the most important thing, whether you're more familiar with C before, java, ruby, python, or are C #, you can complete the automated testing by selenium, and QTP only supports VBS
* Support for multiple platforms: windows, linux, MAC, supports multiple browsers: ie, ff, safari, opera, chrome
* Support for distributed execution of test cases, test cases can be distributed to perform different test machines, the equivalent function dispensing machine
installation:
Our automated installation environment is a necessary step, web automation easier sorts of sorts with respect to appium installation environment. . .
First of all I am using python version 3.6, editor is pycharm, selenium version is 3.12.0, version of Google's browser is 74.0.3729.157
Several software above I believe we will install, not described in detail here
Then we write a simple example to look at
from selenium import webdriver Driver = webdriver.Chrome () # example of a Google browser object driver.get ( " https://baidu.com/ " ) # Open Baidu website
The implementation of the above code, the error found
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Because we have less to install a Google Drive, you can go here to download
Download the file is a chromedriver.exe, we put it in a directory and python.exe
Then we re-run the above code, then it will open the browser, go to Baidu Home
If we want to use firefox browser how to do, it is very simple, you can go to download a firefox drive, and then also on that directory, then the above code change
from selenium import webdriver Driver = webdriver.Firefox () # example of a Google browser object driver.get ( " https://baidu.com/ " ) # Open Baidu website
If you can not find python.exe directory it does not matter, we can generate a driver at the time, indicating the browser will be able to drive address
from selenium import webdriver Driver = webdriver.Chrome (R & lt executable_path = ' F.: \ CJMDXTtest \ config \ Driver \ chromedriver.exe ' ) # instance of a browser object Google, indicating the drive address driver.get ( " https://baidu.com/ " ) # open Baidu website