UI automation test environment setup steps (python + selenium)

Building an automated test environment

Main module combination: selenium + eclipse + python + unittest

Steps to build the environment:

Step 1: Download and install python;

     Download python-2.7.11.amd64.msi, and install it directly after downloading. After installation, add the python installation path to the system environment variable Path, Path = D:\Program Files\AutoTest\python2.7;

Step 2: Install python's SetupTools----setuptools-23.0.0.zip;

    Download setuptools-23.0.0.zip, and install it directly after downloading (pip depends on the installation of setuptools). SetupTools is an enhanced tool software that helps you install third-party toolkits;

Step 3: Install python's package management tool pip, and use SetupTools to install it;

     Use the SetupTools installed in the second step to install, open the DOS interface, enter the directory: D:\Program Files\AutoTest\python2.7\Scripts, and then type in the command: easy_install pip, wait for the completion to be OK, if no error is reported, that is Successful installation;

Step 4: Install the python-based Selenium package; (it is recommended not to use pip, which involves version compatibility issues)

     In the networked state: open the DOS interface, enter the directory: D:\Program Files\AutoTest\python2.7\Scripts and then type in the command: pip install selenium, there may be some warnings during installation, don't worry about it for now;

(If the automatically downloaded selenium version is relatively high, it may prompt that the pip version does not match, you need to use python -m pip install -U pip to upgrade the pip version)

    In the off-network state: download selenium-2.53.2tar.gz, manually download the selenium installation package, right-click to unzip it, and to be on the safe side, put the entire directory under C:\Python27\Lib\site-packages after unzipping, open it In the CMD window, enter the decompressed directory and run the command setup.py install;

   [Note: If you use the firefox browser, install firefox43, which matches the selenium-2.53.2 version;]

Step 5: Verify that selenium is successfully installed, write a test class, and run the test class to check;

     Write the following code in Notepad: (Save as pytest.py, then double-click to run it directly!)  

     from selenium import webdriver  

     browser = webdriver.Firefox()  

     browser.get("http://www.baidu.com")  

     assert "百度" in browser.title  

     browser.close()

Step 6: Install eclipse and javaJDK, and configure environment variables;

    Download eclipse-inst-win64.exe, jdk-8u91-windows-x64.exe, install, and configure environment variables;

    Configure environment variables:

        JAVA_HOME E:\Program Files (x86)\Java_64bit (root directory of jdk installation)  

        CLASSPATH .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar (note the current directory)

        PATH increased by %JAVA_HOME%\bin

Step 7: Build a python development environment in eclipse,

     Python development environment configuration - Eclipse-PyDev plug-in installation (there are two installation methods, the first one is preferred to avoid version mismatch );

          1. Baidu search for PyDev 2.5.0.zip, unzip it after downloading, get the Plugins and Feature folders, copy the two folders to the Eclipse directory, and overwrite them. (note the issue of PyDev matching Eclipse version)       

                Restart Eclipse after completion. If you can see the PyDev component in the Eclipse menu Help->About Eclipse->Installation Detail->Plug-ins, it means the installation is successful.

  • Eclipse 4.5, Java 8: PyDev 5.2.0 (preferred)
  • Eclipse 3.8, Java 7: PyDev 4.5.5
  • Eclipse 3.x, Java 6: PyDev 2.8.2

           2. Select the menu directly in Eclipse: Help—Install New Software..—Add, enter http://pydev.org/updates , (only select pydev for eclipse) to download and install. Then go all the way to Next, enter the installation path selection interface, use the default settings, accept the license agreement, and then Finish.

                Eclipse will download PyDev and the progress of the download can be seen from the Eclipse taskbar. After PyDev is installed, you need to restart Eclipse.

Step 8: Configure PyDev

      After installing PyDev, you need to configure the Python/Jython interpreter. The configuration process is very simple. In the Eclipse menu bar, select Window > Preferences > Pydev > Interpreter - Python, configure the Python interpreter here, and add the installed interpreter. Here, Python is installed in the path D:\Program Files\AutoTest\python2.7. Click New, select the Python interpreter python.exe, open a window with many check boxes, select the path that needs to be added to the system PYTHONPATH, and click Ok.

Step 9: Execute the Selenium instance

     Create a new python project --> create Python packages and modules --> write script code and execute it, whether running the script achieves the expected effect;

     In the Eclipse menu bar, select File > New > Project > Pydev > Pydev Project, create a new project: PythonCase, and click Next.

Creating Python packages and modules Next, start creating Python packages and modules in the project you just created. Enter the Pydev perspective, in the Python Package Explorer, right-click on src, select New->Pydev Package, and enter the Package name Python27. Click Finish, and the Python package is created. At this point, the __init__.py file is automatically generated, which does not contain any content.  

Note: If the "Create default src folder and add it to the pythonpath" checkbox was not checked when creating the project, you need to manually create a source code folder src via File > New > Other > Source Folder. After creating the Pydev Package, right-click the created package, select New->Pydev Module, enter the module name PythonCase1.py Finish. This way, the Python module is built.

Step 10: Install MySQL

      Download mysql-5.7.13-winx64.zip and install it.

Step 11: Install MySQLdb

 Because the module MySQLdb needs to be called in the script, MySQLdb needs to be installed (the prerequisite for installing MySQLdb is that MySQL needs to be installed first).

 

1) Download the version of MySqldb (mysql driver) corresponding to the python version:
         
        Download: MySQL-python-1.2.3.win-amd64-py2.7.zip Unzip, double-click to install
        After installation: Check whether the installation is successful, if the installation is successful, there will be no prompts, as follows:         
                       >>> import MySQLdb
                       >>>
        2) Check if there are folders in the D:\Program Files\AutoTest\python2.7\Lib\site-packages directory:  
           MySQL_python-1.2.3-py2.7.egg-info and MySQLdb.

Step 12: Download the database operation tool

      For example, download navicat110_premium_en_x64 plus crack .rar, unzip it, install the tool, and then connect to MySql.

Step 13: If installing MySQLdb reports an error : Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat

       A package of Micorsoft Visual C++ Compiler for Python 2.7 can be downloaded and installed  . Note: When creating a project, if you import the original project, the original project already has the function of generating reports, that is, you need to use HTMLTestRunner, then you need to go to the python folder D:\Program Files\AutoTest\python2.7\ Import HTMLTestRunner.py file in Lib.








   
 





















   





        



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325562295&siteId=291194637
Recommended