1. Linear test
Advantages: Each script is completely independent, each script corresponds to a test case
Disadvantages: high development cost, there will be repeated operations and repeated scripts; maintenance costs are also high, when you modify the repeated operation scripts, you must modify them one by one.
2. Modular drive test
Repetitive operations are independent into a common module, which is called when the operation of this module is needed in the execution of the use case, so as to eliminate duplication to the greatest extent and improve the maintainability of the test case.
Solved two problems of linear test:
(1) Improve development efficiency
(2) Simplified maintenance complexity
Disadvantages: In the case of data changes, it will increase the preparation of repeated scripts (for example, now I want to test the login scenario of different users, first Zhang San login, after logging in, change Li Si login, then continue to change user login There are duplicate login scripts, although the login steps are the same, but the login data is different)
Write a class to wrap the login function
Then write a main program to call the login function
3. Data-driven testing
Data-driven is the parameterization of data, because the input data is not painful and causes different output results; for example, defined arrays, dictionaries, or external files (Excel, csv, txt, xml, etc.) can be regarded as data-driven. The purpose is to achieve the separation of data and script.
Advantages: Further enhance the reusability of the script.
(1) Data drive through parameterization
The value to be input is used as a parameter to pass in, to achieve different execution results according to the data input
Registered functions are encapsulated by parameter
Then call this method in the main method, passing in different parameters
(2) Parametric search keywords
Define the keywords to be searched as a set of arrays, and then search in a looping manner. The searched keywords are different and the test results are different.
(3) Read the txt file
Python provides several ways to read txt files:
read (): read the entire file
readline (): read a line of data
readlines (): read all lines of data
(4) Read the csv file
(5) Read the xml file
parse (): Open the xml file
documentElement: used to get the only root element of the xml file
nodeName: node name
nodeValue: node value
nodeType: node type
ELEMENT_NODE: element node type
getElementsByTagName: You can get tags by tag name, and the obtained objects are stored in the form of an array
getAttribute (): used to get the attribute value of an element, similar to get_attribute () in webdriver
firstChild: The property returns the first child node of the selected node
data: means to get the data of the node, similar to the text method in webdriver
4. Keyword-driven testing