微信商城UI自动化测试技术选型和实现思路

Purpose:

Build up the Auto Test framework with the CI process;

With the Help of Auto Test, the KPI of DEV Team can increased with 50%;

Background:

In Q3 there are lots of new feature will be deliver in WeChat Store, the work load is over 2 QA Engineers' capacity; 

Current Status:

For each sprint, there are about 30 points should be completed,

DEV engineers can only put 5% time for UT task, only the happy route can be covered;

 

QA engineer only has 8 working days for design cases, prepare test data and execution for about 10 stories;

And last 2 days for regression test; 

Each point can only get about 2 hours for each test task, there are :

QA Task

Weight

Note

Analysis Story10%Human task
Plan Schedule5%Human task
Design cases20%Human task
Data prepare10%can be Auto
ENV deploy10%can be Auto
Execution40%can be Auto
Report5%can be Auto
 ~65%can be Auto


DEV & QA engineers can force on core work in every sprint;

 

RISK: Currently, the DEV & QA Backend env are not stable, and non-independent, in some day, we can't login target page;

So the scripts coding are blocked;

Target:

The repeat Execution(40% workload), Data Prepare(10% workload), Env Deploy(10% workload) and part of report(5% workload) can be automatic,

the QA Engineer can focus on core work as Analysis and Design cases;

Because the Auto test tool can't design test cases as human for new story,

so we want to make the regression test can be executed automatic (should be ready in 2018/8); 

After that we want to make the data prepare and execution for new feature can been automatic (should be ready in early 2018/9);

 

Evolutionary Process of the Framework:

 

Step

Description

Note

1Code the test scripts with some hard code when the elements or pages in product is untestable;Done with CYPRESS;
2Encapsulation for the repeatable step, parameter, variable and configuration;Done with CYPRESS;
   

 

 

WHAT SHOULD TEAM DO:

Considering the main workload(40%) is execution, the highest priority task is making execution been automatic;

 

Building up phase:

 

Description

Status

1Define the test scope which MUST/SHOULD/Can't be covered by Auto Test;Done, E2E
2Build up the Auto test Demo in Local Env for Test Framework verification and select the Framework with high applicability and generality, low maintain cost;Done, need Manager confirm
3

Make the E2E test be covered by Auto Test;

Auto Engineer complete the test scripts for E2E scenarios and guide documents for installation, execution and code scripts;

POC Done, Release Engineer are preparing for Pipeline
4Modify the code for adding the test attitude, then expand the Framework usage to more scope in E2E/Regression test;ToDo, Auto engineer is collecting the information;
   

 

Stable phase:

 

Description

Status

1Auto Engineer code more scripts in Regression scopeDoing
2Training the QA for how to mock the API response with auto test tool for reducing Data Prepare for IT;ToDo, Auto engineer should make some example
3Auto engineer help the QA to use the auto tool in daily work and training the scripts coding;

ToDo

4When analysis story, Auto Engineer should discuss with DEV for add unique attitude for element location;ToDo
5When there are enough scripts are ready, DEV team can make UT with lower cost and more scenario;ToDo

 

There are 2 kinds of ways for Preparing test data(10% workload):

1. MOCK:

There are 2 way for MOCK Backend API;

a) CYPRESS support this, samples as;

      it('cy.route() - route responses to matching requests', () => {
          // https://on.cypress.io/route

          let message = 'whoa, this comment does not exist in real response'
          cy.server()

          // Stub a response to PUT comments/ ****
          cy.route({
              method: 'PUT',
              url: 'comments/*',
              status: 404,
              response: { error: message },
              delay: 500,
          }).as('putComment')

          // we have code that puts a comment when
          // the button is clicked in scripts.js
          cy.get('.network-put').click()

          cy.wait('@putComment')

          // our 404 statusCode logic in scripts.js executed
          cy.get('.network-put-comment').should('contain', message) 

          cy.get('.some-element-appear-with-response-code-404').should('be.visible',{timeout: 1000)})

   })

    I can add the lines as "flag4MOCKstart","flag4MOCKend" to around the MOCK declaration and implementation in scripts, 

    and use other maintain scripts to annotation/un-annotation the test scripts when we run it without/with MOCK;

 

b) RAP from Alibaba support the same MOCK, Backend Team(Micheal Shen) will release the feature before 2018/8/13,

        but FrontEnd team need maintain the related data by they-self; The maintain cost need to be estimated;

 

2. Set the real data of account/address/history/etc. in DEV/QA/PreLIVE Environment; The backend tool HAWKEYE already cover this feature, I will make some scripts for typical scenarios;

 

After read some documents from eBay, the 70~80% cases of component/model layer have been covered by auto test;

In E2E test scope, the manual test still cover more than 50% cases; Especially in the Exploratory Testing, human work are irreplaceable.

 

Then Why E2E test:

We want to cover the Happy Path for Basic Flow, then we can know which part of project are not available for Auto test;

Because we hope all test for single Sprint can be finished in 4 hours with high quality and enough coverage;

But the GUI test is not stable when involved with Mobile and App, so GUI can't be the main point, just the main Business Flow - E2E can be covered;

 

 

WeChat Store drived by Real Mobile
H5 Page without Auth Limitation running in WeChat SDK
E2E test with Tools as cypress
Advantage
Real customer angel view, involve all the environments : 
network, Mobile, Mobile OS, WeChat APP, etc.
Normal browser as Chrome/FF can handle the H5 page test, 
selenium can handle the test quickly;
Quick RUN, working with Backend API directly;
Defect
WeChat internal browser block the Web View handle;
Without WeChat, the result is incomplete; 
WeChat Auth block the H5 page running in Chrome/FF;
Without WeChat, the result is incomplete; 
Scripts based on JS, can't be sync with 
the existing HAWKEYE;
Plan
Appium drive the webview
Selenium drive the Web View;
CYPRESS or MOCHA;
Status
Blocked, only location can be used to tap the screen, 
this kind of "Blind" operation can't check the flow step;
Trying the non-Auth web login, but the Order/Bag pages 
are still blocked;
Waiting for H5 page isolated with 
WeChat version ready, but the 
Order/Bag pages are still blocked;

 

Compare several E2E Test Framework:

TOOL
Element operation
Variables & Aliases
assertion
Test Cases Running
Condtional Testing
ENV config
Dependency
Platform
Script Maintain Cost
LOG & Project Organization
Code Coverage

 

 

 
CYPRESS
Actionability, Visibility, 
Disability, Animations, Covering, 
Scrolling,Forcing, etc.

Suitable for Mobile;

Can get element by Text Content 
from human's view OR CSS SELECTOR;
yes
should-end cases;

expect-end cases;

timeout(before/after)-auto repeat 
then fail and end cases;
not support parallel;

Only back end/network down will 
cause skip all following cases;

Without script grammar check 
before execution;
yes
yes, simply K-V format;

2 Layer with overrule mechanism;

we can use this as NATIVE Product 
Branch/ENV controller.
NO
MAC,LINUX,WINDOWS
Midle,

simple assert, flex var, 
smart screen with case step tree, 
video;
 
Yes, but stored in 3rd, we can get private space with pay;

Support 3rd reporter as JUnit for TeamCity/Jenkins;
Not Supported yet  
 
NightWatch
Actionability, Visibility, Disability;

CSS/JS related, suitable for Web Page;

Only support attributes/property of 
JS/CSS OR XPath to get the element;
yes
assert-end case;

verify-log & continue case;

expect-end cases;

timeout(before/after)-auto repeat 
then fail and end cases;
support parallel;

Exception/Failure will cause 
skip all following cases;

Without script grammar check 
before execution;
yes
yes, JSON format(); 

config for Product Branch/ENV should be 
maintain in the same file with different Domain;
Selenium for non-Chrome
MAC,LINUX,WINDOWS
High,

simple assert, complicated var, 
screen without case step, 
no video;
Support 3rd reporter as JUnit for TeamCity/Jenkins;Not Supported yet  
 

MACACA

 

Based on web driver and selenium, so ID, CLASSNAME, XPATH, CSS SELECTOR, etc.yes, based which Language you selected: JS, JAVA, PythonDefault JUnit, you can expand with other framework such as TestNG OR PyTest;Dependent with which JUnit or other framework such as TestNG OR PyTest;yes, based which Language you selected: JS, JAVA, Pythonbased which Language you selected: JS, JAVA, PythonWeb DriverMAC,LINUX,WINDOWSHigh,

simple assert, complicated var, 
screen without case step, 
no video;
Support 3rd reporter as JUnit for TeamCity/Jenkins;Not Supported yet  

 

 

 

               


 

What should ENV Platform involve:

Browser(headless mode also need the core),

CI Platform (Jenkins OR Teamcity),

Test Tool (CYPRESS, Nightwatch),

Test Scripts,

ENV Config file, etc.

 

How the E2E Test tool work with CI pipeline:

In this image, the UT are executed with DEV team with their own code, but we hope the Auto Framework can help them to finish this task in future;

UAT mean the manual test and the remaining part of the Regression test;

 

Feature Layer

INPUT

OUTPUT

Description

1Merge RequestGitlab eventSomeone in DEV team push some change as Merge Request to the FEATURE Branch;
2Gitlab eventBuild eventCI Server (Jenkins + Gitlab Merge Request Builder) configured with GitLab Project Path, Builder detail, test start command, etc.; When the MR arrived, the Build task will start;
3product packagein locationIf the build completed successfully, the product will be stored in Library;
4Test scriptsTest tool and scripts readyCI Task for build up the TEST Tool will install the Test Tool and deliver the ENV config files and scripts to the position under the Project Path;
5command line for start sample testsample test resultStart the sample test with default scripts with sample Product in test Tool to confirm the deliver, ENV config and dependency works well;
6product package in speical locationproduct deliver to the target locationCI Task for build up the TEST ENV will get the package from Library and deliver to the TEST ENV; GIT Clone to the Project Path;
7command line for start E2E testTest log, etc.CI Task for execution the test will start the local Node for WeChat Store and modify the test ENV configuration file, then start the Test Tool with selected scripts;
8Test reportMerge job completeIf the Test cases are all passed, the FEATURE Branch will include the code change with the last MR; Otherwise, the MR will be rejected and the DEV will be alarmed;
9Success notice to DEV team Then the DEV Team can push the code change to TRUNK now;

 

Sprint Layer

INPUT

OUTPUT

Description

1Merge RequestGitlab eventSomeone in DEV team push some change as Merge Request to the TRUNK Branch;
2Gitlab eventBuild eventCI Server (Jenkins + Gitlab Merge Request Builder) configured with GitLab Project Path, Builder detail, test start command, etc.; When the MR arrived, the Build task will start;
3product packageStored in locationIf the build completed successfully, the product will be stored in Library;
4Test scriptsTest tool and scripts readyCI Task for build up the TEST Tool will install the Test Tool and deliver the ENV config files and scripts to the position under the Project Path;
5command line for start sample testsample test resultStart the sample test with default scripts with sample Product in test Tool to confirm the deliver, ENV config and dependency works well;
6product package in speical locationproduct deliver to the target locationCI Task for build up the TEST ENV will get the package from Library and deliver to the TEST ENV; GIT Clone to the Project Path;
7command line for start E2E testTest log, etc.CI Task for execution the test will start the local Node for WeChat Store and modify the test ENV configuration file, then start the Test Tool with selected scripts;
8Test reportMerge job completeIf the Test cases are all passed, the TRUNK Branch will include the code change with the last MR; Otherwise, the MR will be rejected and the DEV will be alarmed;
9Success Test reportPush code change to MASTERThen the CI Task will push the TRUNK to the MASTER;
10Build scriptDeliver to Pre-LIVEThe product will be built with MASTER and deliver to the Pre-LIVE ENV;
11Deliver success noticeManual test resultManual test can be executed after CI send the notice;
12  Then if any other steps in the pipeline, continue until the end;
13  If Manual test passed, MASTER will be marked as “Ready to Deliver”; The Release Engineer and Head of DEV will receive the Notice;
14  Then the Deliver to LIVE can start;

 

Test Platform File structura:

 

1.For more exact element location, DEV Engineer need add the special attribute for identify,What should DEV modify the Code for better Selecting Elements with CYPRESS:

Anti-Pattern: Using highly brittle selectors that are subject to change.

Without attribute for auto test

Best Practice: Use data-* attributes to provide context to your selectors and insulate them from CSS or JS changes.

With attribute for auto test

 

Every test you write will include selectors for elements. To save yourself a lot of headaches, you should write selectors that are resilient to changes.

Oftentimes we see users run into problems targeting their elements because:

Oftentimes we see users run into problems targeting their elements because:

  • Your application may use dynamic classes or ID’s that change
  • Your selectors break from development changes to CSS styles or JS behavior

Luckily, it is very easy to avoid both of these problems.

  1. Don’t target elements based on CSS attributes such as: idclasstag
  2. Don’t target elements that may change their textContent
  3. Add data-* attributes to make it easy to target elements

How It Works:

Given a button that we want to interact with:

<button id="main" class="btn btn-large" data-cy="submit">Submit</button>

Let’s investigate how we could target it:

Selector

Recommended

Notes

cy.get('button').click()

 Never

Worst - too generic, no context.

cy.get('.btn.btn-large').click() NeverBad. Coupled to styling. Highly subject to change.
cy.get('#main').click() SparinglyBetter. But still coupled to styling or JS event listeners.
cy.contains('Submit').click() DependsMuch better. But still coupled to text content that may change.
cy.get('[data-cy=submit]').click() AlwaysBest. Insulated from all changes.

Targeting the element above by tagclass or id is very volatile and highly subject to change. You may swap out the element, you may refactor CSS and update ID’s, or you may add or remove classes that affect the style of the element.

Instead, adding the data-cy attribute to the element gives us a targeted selector that’s only used for testing.

The data-cy attribute will not change from CSS style or JS behavioral changes, meaning it’s not coupled to the behavior or styling of an element.

Additionally, it makes it clear to everyone that this element is used directly by test code.

 Did you know?

The Selector Playground automatically follows these best practices.

When determining an unique selector it will automatically prefer elements with:

  • data-cy
  • data-test
  • data-testid

 

2.The CYPRESS already support the dashboard for result presentation in organizations, next step is adding the item into TEAMCITY.

 

 

3.How to make CYPRESS scripts work smoothly with the different point between Branch/Version/Language:

There are 2 layer of Environment configuration files: cypress.json & cypress.env.json, the duplicated item in cypress.env.json will overwrite the same item in cypress.json;

In cypress.json, we define all the location str for related elements in the target Code Branch ;

In cypress.env.json, we define Test Platform Node IP, Port, User account info for different Test Env(as DEV, QA, Pre-Live, Live), different Text Content of element in different language;

And some element which work with different Test Env;

 

4.Performance monitoring can get the sample data with ST in pre-Live ENV, and compare with the real data in LIVE ENV; 

But we still need Active measuring instrument in “Payment”, etc. before the WeChat Auth can be overruled.

 

AS Google Test Model, what should TEAM do & the Benefit: 

Role

Input

Output

Feature

Scenario

TC STEP

TC DATA

Benefit from Auto Test

PORequirementStoryDefineSimple Define  Clear view of Scenario
DEVStoryDesignAnalysis, ImplementDefine, Implement  Don't need to prepare the UI Test, just need maintain the Unit Test
QA(Feature Owner)RequirementTCAnalysisAnalysisDefineDefineLow miantain cost for TC/Data, more effort for Intellectual work
QA(Executor)TCtest resultUnderstand, simple analysisUnderstand, simple analysisExecuteExecuteLess time for manual test, focus on analysis the test report/log
Above Role don't need to change thedaily work significantly Only QA need prepare the Test case and Test Data in new Formate;     
Auto Test EngineerTest PlanFramework, script templateUnderstandUnderstand, map to script groupmap to Key word(every Key word including 1~several steps)map to Data Group 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值