WebTest-----WebUI Automation Framework

Source: Internet
Author: User
Tags html form

WebTest Framework Introduction Address

Https://github.com/wuranxu/webTest

I hope we can enjoy!!!

Brief introduction

This framework is based on Python3+selenium3+unittest, where users write use cases in the form of Page object. The positioning and operation of elements are divided into pages to achieve the purpose of web-based automated regression testing and generate test reports. Browser compatibility is temporarily incomplete.
This example shows a Bing home search "Dragon Ball Super" test case, relatively simple.

Run log

Process

Effect Show

Get started quickly
    • Pull the replacement code from the remote repository

git clone https://github.com/wuranxu/webTest.git

    • Install dependent packages

Go to the downloaded webtest directory and run it in this directory install.py
Mac/linux:python3 install.py
Windows:python install.py

    • Run Demo

Enter the command in the WebTest directory (make sure that Chrome is installed and the driver will download it yourself):

python run_case.py

Environment Configuration Note: No desktop version of Linux is currently only supported Firefox
    • Os:windows/mac OS X/linux
    • python3.x
    • Chrome browser
Directory structure
project└───ErrorPic|└───DataBase|└───Log|└───Xmind|└───Page|└───Report|└───Page|└───TestSuite|   |    base_case.py|└───templates|   |   report_templates.html└───TestResult|   |   report_templates.html|   |   GenerateReport.py|   |   Result.py|└───chromedriver│   │   chromedriver.exe|└───Tools|   |   chrome.py|   |   decorator.py|   |   driver.py|   |   logger.py|   |   web_tool.py|│   README.md│   run_case.py|   requirements.txt    │   config.py|   
Content Introduction
    • Chromedriver

Storage Chromedriver driver, if the machine is not installed chromedriver automatically match the native version of Chrome to download the corresponding driver.

    • DataBase

Connection classes that store MySQL and MongoDB

    • Errorpic

An error occurred, and the folder is now created and stored according to the use case name.

    • Log

Store all log files, currently only Webdriver_test.log, the main purpose is to separate the log.

    • Page

Page directory, extensible, for different modules of the page can be designed to different directory structure. The Action (action) and element (location) that typically holds the page, and the use case specific assertion is not recommended here (varies from person to person).

    • Report

Store test reports in HTML form, right-click through the browser and use chrome for better results.

    • Templates

Store HTML templates and pass in test results to generate test reports.

    • TestResult

    • generatereport.py

      is to organize test results, generate test reports, and fill in the data to the HTML report template method.

    • result.py

      Inherit from UnitTest. Texttestresult class that stores test results.

    • TestSuite

Test suite directory, extensible, subdirectory for a test set. Test cases are stored centrally.

    • base_case.py

      Store the underlying test case.

    • Tools

    • chrome.py

      For update/download chromedriver, only Mac OS and Windows systems are currently supported.

    • decorator.py

      Used to store the Auto/re-run and other decorators, mainly for testing functions to add errors and re-run functions.

    • driver.py

      Inherits from the Webdriver class, primarily for simplifying native APIs and adding APIs such as switching Frame/handle.

    • logger.py

      The function function that logs the log.

    • web_tool.py

      A tool class for Web automation testing, including methods for obtaining use cases, and so on.

    • xmind_reader.py

      Used to parse the Xmind file and temporarily does not support overly complex xmind. The use case is probably written in such a way.

    • Xmind

The Xmind file is stored, and the Xmind file is used to write test cases.

    • config.py

For storing most of the configuration. Inherits from the Baseconf class and can have its own configuration.

    • Requirements.txt

Used to store the library required for this framework.

    • run_case.py

Store organizational use cases, generate test suites, run test cases, and so on.

    • Webdriver_test.log

Store information about actions and error messages when the test case is executed.

Note: The above directory structure/naming may not be reasonable, but also look haihan. User manual The following content can be skipped if it is already installed.
    • Installing Python3

Python3.6

Download the Python version of the corresponding operating system and install it.

    • Download IDE (not required)

Recommended Pycharm

Pycharm

    • Install the necessary libraries

install.py in the directory, after installing Python, enter the following command in the terminal window:

Linux/mac:python3 install.py

Windows:python install.py

Note: You need to take the install.py path or enter the directory where the file is installed.

    • Pycharm configuration (if any)

    • First step: Configure the Project Python environment

      File->open

Select the WebTest directory and click Open in the lower right corner of the window

Open preferences, in Project interpreter, select the address where you just installed Python, click OK

    • Step Two: Configure run_case.py

Click Edit Configurations

If there is no Python configuration, click on the "+" icon in the graph and select Python and add

Configuration scripts

    • Step three: Run the use case

Right-click run_case.py, select Run mode, debug mode

    • Use case Authoring Rules

Python:

    • can refer to search.py writing use cases (preferably the class name of the use case is not duplicated)
    • Use cases need to be written in the testsuite/test set/This directory
    • Use cases need to inherit base_case.py
    • Use cases need to start with test such as Test_bmp
    • The test function of the use case requires an adorner with screenshot, without function
    • Reports are generated by time and are written to 2 copies of report.html
    • Log in Webdriver_test.log view
    • Page pages The actions and elements required to write this page
    • The location class is encapsulated with Webelement, which contains name, value, and is positioned by default in CSS mode
    • When instantiating a location class, you can specify a third parameter to facilitate the use of other targeted classmates. Such as:

      menu = Location("大后台左侧菜单", ".menuItem", "XPATH")

Xmind:

    • Canvas (required)

      is a testsuite name, which allows duplicate canvas names

    • root element (required)

      is the class name of the use case

    • Description (preferably available)

      The test point for the use case

    • Page (required)

      You need to fill in the page below, the child node is the method to be used under its page, if there are child nodes, then the method returns the value, if there are more than one return value is used; split and the return value is preserved for easy assertion

    • Skip (do not fill in the default build case)

      A use case is generated when it is not true

    • Number of re-runs (optional)

      If the use case fails, the number of times to rerun is 0 by default.

    • Step (required)

      A child node is a page method or assertion, and if it starts with an assert, it is judged as a method, and if the method is forgotten in the page, the internal method of the system is called.

      The child nodes of a method node are parameters, similarly, split.

      The assertion has a child node of 2 or 3, such as assertequal, which is understood to be A==B?true:msg that the last parameter is MSG, which causes the error.

    • Known defects
      1. Non-page method calls such as print have not been supported until now;
      2. Other class libraries required for importing this use case are not supported;
      3. Other unpleasant needs to be added.
Bright Pain Point
    • Browser driver

    • Problem: Browser drivers occasionally do not correspond to browsers
    • Solution: Download automatically, but only for Chrome under Mac/win, and the version is not too low. Firefox does not support, wayward.

    • Integrated Jenkins

    • Problem: centos6.x cannot run UI Automation use case without desktop
    • Solution:

      1. PHANTOMJS (not appropriate, or to write it out)

      The new version of the selenium will be discarded when used, it is recommended to replace with headless mode, and the operation is not stable.

      1. Chrome Headless mode (Centos7 above should be possible)

      Because Jenkins is on a machine centos6.x version is too low, Chrome has abandoned the support, Chrome browser cannot install

      1. Firefox headless mode (visual not OK, measured too many times to remember)

      Firefox can be installed normally, but geckodriver the browser version, many times the trial is unsuccessful, for a few browser version +geckodriver version has forgotten whether it is feasible.

      1. firefox+ Virtual Desktop (current solution)

      See Use case driver.py file. But not perfect, the page content of the error display is Long story, as if a blind man finally regain light but found himself full of leper. Back to the point, why not automatically sync Firefox driver, because in the C scheme stuck too long more disgusting.

      Version information:

      geckodriver0.16

      selenium>=3.4

      firefox52.0

    • Test report

Because the message does not support JS and the introduction of CSS, the report is ugly. Therefore, the use of attachment form, is now a relatively large pain point.

    • Page Object

About PO, there is no very deep research, just waiting for mice to test water.

    • API Encapsulation

API encapsulation is not enough, except for common methods. But basically each method has inserted the display wait, greatly reduced the element cannot find, the point not to, the variety not to be possible.

    • Re-run

Resolves an issue where using a decorator to run a use case does not perform setup+teardown.

    • Error

Save it with Base64, so only when it's wrong. Because the base64 is too big.

    • Xmind Writing Use Cases

It's a small bright spot.

    • Automating the configuration Environment

Completed for ease of use.

    • Database

Support MONGO and MySQL.

    • Execution efficiency

The current is single-threaded, not long threads, time is pressing. So in Jenkins that old machine is relatively slow, if the use case more up must not be.

    • Code Specification/Quality

Write a mess, we can not see the past to help change it, kneeling Xie Orz

WebTest-----WebUI Automation Framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.