UI test automation installation and deployment environment eclipse + Python + selenium + pymysql + HTMLTestRunner

Two days before leaders make redeploy a test environment, suddenly a little know how to start, a variety of Baidu, so decided to write here;

First, download and configure the JDK

First we need to download java development kit JDK, Download: http://www.oracle.com/technetwork/java/javase/downloads/index.html

 

JDK installation according to prompts to download, install JDK when there will install the JRE, install it together.

Installation JDK, installation can customize the installation directory and other information, for example, we select the installation directory is C: \ Program Files (x86) \ Java \ jdk1.8.0_91.

Configuration environment variable

1. After installation is complete, right-click "My Computer", click "Properties", select "Advanced System Settings";

2. Select the "Advanced" tab, click on the "Environment Variables";

Then the screen will appear as shown below:

Set three properties in the "System Variables", JAVA_HOME, PATH, CLASSPATH (capitalization does not matter), If there is already then click the "Edit" does not exist, click "New."

Note: If you use version 1.5 or later of the JDK, do not set the CLASSPATH environment variable can be properly compile and run Java programs.

Variable is set to the following parameters:

  • Variable name: JAVA_HOME
  • Variable value: C: \ Program Files (x86) \ Java \ jdk1.8.0_91 // to be configured according to their actual path
  • Variable name: CLASSPATH
  • Variable values:;.% JAVA_HOME% \ lib \ dt.jar;% JAVA_HOME% \ lib \ tools.jar; // in front of a recall. ""
  • Variable name: Path
  • 变量 值:% JAVA_HOME% \ bin;% JAVA_HOME% \ jre \ bin;

Setting JAVA_HOME

PATH settings

Note: In Windows10, Path variable in a sub-section of the show, we need to% JAVA_HOME% \ bin;% JAVA_HOME% \ jre \ bin; added separately, or can not identify:

%JAVA_HOME%\bin; %JAVA_HOME%\jre\bin;

More may refer to: Windows 10 Configuration Java Environment Variables

Setting CLASSPATH

This is a Java environment configuration, the configuration is complete, you can start Eclipse to write code, it will automatically configure the java environment.

JDK is installed successfully test

1. "Start" -> "Run", type "cmd";

2, type the command: java -version, java, javac few commands, the following message appears, indicating successful configuration environment variable;

 

Second, download and install Python

Python's official website: https://www.python.org/

 

Select Software system according to

 

Select version, *** MSI installer

 

Once downloaded, double-click the download package into Python installation wizard, the installation is very simple, you just use the default settings Click "next" to complete the installation.

Environment variable configuration

  • Right-click on "Computer" and then click "Properties"
  • Then click on the "Advanced System Settings"
  • Select "System Variables" window under the "Path", double click!
  • Then in the "Path" line, the C: \ Python27 and C: \ Python27 \ Scripts environment variable added to them, so that after the addition of the path.
  •  ps: Remember, the direct path with a semicolon ";" to separate!

 

Python is installed successfully test

1. "Start" -> "Run", type "cmd";

2, type the command: python, the following message appears, indicating successful configuration environment variable;

 

Third, the installation and configuration eclipse

First to enter the official website to download: http://www.eclipse.org/downloads/

 

 

 

 

 

 

四、Eclipse+Pydev

After running Eclipse, then select help -> Install new Software, as shown below.

Click Add, add pydev installation address: http: //pydev.org/updates/, as shown in FIG.

When finished, click "ok", PyDev then click the "+", expand the node PyDev, and to wait for a short time, let it get PyDev related packages from the Internet, when completed will be more relevant in the sub-node packages PyDev in , are then checked by the next installation. As shown below.

After installation is complete, you can restart Eclipse

Set Pydev

After installation, you need to set it PyDev, select Window -> Preferences to set PyDev. Set Python path from Pydev of Interpreter - Select New Python page

A window will pop up to let you choose the installation location of Python, select the location where you installed Python.

After completing PyDev setting is finished, you can start using it.

Build Python Project:

After installing Eclipse + PyDev, we can begin to use it to develop the project. First create a project, choose File -> New -> Pydev Project

A new window will pop up, fill in the Project Name, address and save the project, and then click Create next to complete the project.

 

Fifth, install selenium

Download setuptools-15.1, after extracting installation, cmd enter python setup.py install

Download pip-6.1.1.tar.gz, after extracting installation, cmd enter python setup.py install, after installation can be installed pip

Input pip install -U selenium in cmd command, and then it can be automatically installed

Now need the latest version of Chrome and ChromeDriver, ChromeDriver needs to be placed C: \ Python27 best directory

Test environment is installed, the python interface input from selenium import webdriver, if not an error, indicating that the installation was successful selenium

Test driver is operational (open Baidu, you can query success):

from selenium import webdriver

driver = webdriver.Chrome()

driver.get('http://www.baidu.com')

driver.find_element_by_id('kw').send_keys('selenium')

driver.find_element_by_id('su').click()

#driver.close()

driver.quit()

6, installation pymysql

cmd into the C: \ Python27 \ Scripts

pip install pymysql

Seven, installation HTMLTestRunner

cmd into the C: \ Python27 \ Scripts

pip install HTMLTestRunne

If this fails. You will need to manually download.

Download: http://tungwaiyip.info/software/HTMLTestRunner.html

 

After downloading, copy the files to the HTMLTestRunner.py to lib file in the Python installation folder path.

In python3 with HTMLTestRunner.py newspaper importError ": No module named 'StringIO' solution

The reason is that the official website of python2 grammar is written, Tell me what the HTMLTestRunner.py manually change the syntax of the official website of python3.

Modify the content:

Line 94 will be modified to import io import StringIO

Line 539, the self.outputBuffer = StringIO.StringIO () modified self.outputBuffer = io.StringIO ()

The first 642 rows will if not rmap.has_key (cls): modified if not cls in rmap:

第631行,将print >> sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime)修改成print(sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime))

The first line 766, the uo = o.decode ( 'latin-1') modified uo = e

The first line 775, the ue = e.decode ( 'latin-1') modified ue = e

 

Released four original articles · won praise 2 · Views 858

Guess you like

Origin blog.csdn.net/KRIS891001/article/details/100048391