Life is short, the history of the whole letter python keyword-driven test automation solutions

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_45523154/article/details/102750397

 method of operation of the browser are fixed and can not be changed.
Field (positioning method, targeting expression, the value of the operation) the operation method requires l is represented by a separate column.
 After running the program requires an exception error message and error screenshots
2.3. The concept
we put on top of this design method is called keyword-driven, summed up the following two points.
1. Keyword-driven framework is a functional automated testing framework
 is called table-driven testing
 action is called word-based tests.
2. important part of keyword-driven framework
 Test Procedure (the Test the Step),
 step test object (Test Object) - Object mouse, keyboard, browser and other
actions  test subjects performed (Action)
 test data (Test data) required objects
3. how to design keyword-driven
3.1. how to design a program?
From the above use case design, we need to achieve in order to analyze the function of.

We hope that the automation framework script can read each line use cases, and then after performing the test results. If it is wrong to have executed an error message, error screenshots. Then we need to complete the preparation of the following codes.
(1) Excel operation (read, write)
 read key names, operating elements targeting, positioning expression control elements, operating values
written execution time, test results, error messages, screenshots  file location after execution is complete
(2 ) name keyword, targeting operating element, the operating element targeting expression, action script operating values develop web
(3) by the method of Example of script execution
(4) the method of recording a script error message
(5) the method of theme script error
3.2.Excel of operating
the main achievement of reading and writing excel spreadsheet

OperateExcel class (builtins.object)
Methods defined here Wallpaper:
the init (Self, ExcelFile)
: param ExcelFile: EXCLE file path and name
get_cell_of_object (Self, Sheet, Coordinate = None, row_no = None, cols_no = None)
: param Sheet: Sheet Object
: param coordinate: coordinates
: param rowNo: line number
: param colsNo: column number
: return: the cell objects
get_cell_of_value (Self, Sheet, coordinate = None, row_no = None, cols_no = None)
: param Sheet: Sheet Object
: param coordinate: coordinates
: param row_no: line number
: param cols_no: column number
: return: cell value
get_cols_number (Self, Sheet)
: param Sheet: Sheet Object
: return: sheet has ends column data area of the line number
get_column (self, sheet , col_no)
: param sheet: sheet Object
: param col_no: subscript starting at 1
: return:
get_row (Self, Sheet, row_no)
: param sheet: sheet Object
: param rowNo: starting with 1
: return: return of the line all the data SUMMARY composition tuple
get_rows_number (Self, Sheet)
: param Sheet: Sheet Object
: return: sheet have line data area end line number
get_sheet_by_index (Self, sheet_index)
: param sheet_index: Sheet index number
: return: sheet objects
get_sheet_by_name ( Self, SHEET_NAME)
: param SHEET_NAME: Sheet name excel in
: return: sheet objects
get_start_col_number (Self, Sheet)
: param Sheet: Sheet Object
: return: sheet have column numbers starting data region
get_start_row_number (Self, Sheet)
: param sheet: sheet Object
: return: sheet has a data start line number area
write_cell (Self, Sheet, Content, Coordinate = None, row_no = None, cols_no = None, style = None)
: param Sheet: Sheet Object
: param content: the written content
: param coordinate: coordinates
: param row_no: line number
: param cols_no: column number
: param style: font color names, such as Red, Green
: return: successful return True
write_cell_current_time (Self, Sheet, Coordinate = None, row_no = None, cols_no = None)
: param Sheet: Sheet Object
: param coordinate: coordinates
: param row_no: line number, subscript 1 from the beginning
: param cols_no: column number, index starts at 1
: return: the successful return True
3.3.Web action scripts
main page elements to achieve the page to find the package and check function assert assert package

WebPageAction class (builtins.object)
Methods defined here Wallpaper:
the init (Self)
: param BROWSER_NAME: Type chrome firefox ie browser
accept_alert (self)
prompts, operating
assert_driver_title_is (Self, title)
assert_is_text_in_element (Self, Locator, text, timeout = 10)
determines whether text is present in the text
: return:
assert_is_value_in_element (Self, Locator, value, timeout = 10)
determines the value attribute is the same
: return:
assert_string_in_pagesource (Self, String)
: param String: assert the page source code whether a key is present word or keyword strings
: return: the successful return True, otherwise False
back_browser (Self)
Back
capture_screen (self)
Screenshot
: return:
the Clear (Self, Locator)
click (self, locator, timeout = 10)
click on the element
: return:
close_browser (Self)
Close your browser
: return:
close_window (Self)
to close the current page
: return:
find_element (Self, Locator, timeout = 10)
positioning an element
find_elements ( self, locator, timeout = 10)
is positioned a set of elements
input_text (self, locator, text, timeout = 10)
write
: return:
maximize_browser (Self)
window is maximized
: return:
open_browser (Self, BROWSER_NAME = None)
OPEN_URLLearn ( self, url)
open URL
: return:
random_choice_select (Self, loc_1, loc_2 = 'the Option')
randomly selected drop-down box
refresh_browser (self)
refresh your browser
: return:
select_by_index (self, locator, index, timeout = 10)
indexes positioned down box options
: param locator: locator, is a tuple
: param index: receiving Index
: param timeout: Maximum latency
: return:
select_by_text (Self, Locator, text, timeout = 10)
text message targeting dropdown options
: param locator: locator, is a tuple
: param text: receiving text information
: param timeout: maximum latency
: return:
select_by_value (Self, Locator, value, timeout = 10)
value value of the positioning down box options
: param locator: locator, is a tuple
: param value: value value received
: param timeout: maximum latency
: return:
select_checkbox (Self, Locator, timeout = 10)
to select a single multiplexed box
: param locator: locator, is a tuple
: param timeout: locator, is a tuple
: return:
select_checkboxes (self, locator, timeout = 10)
all check box
: param locator: locator, is a tuple
: param timeout: Maximum latency
: return:
select_radio (Self, Locator, timeout = 10)
check box is selected Location
: param locator: locator, it is a tuple
: param timeout: maximum latency
: return:
sleep_seconds (Self, seconds The)
forced to wait

3.4 The logging
by running a log recording system logging module
3.5. Configured
to facilitate future maintenance or excel adjust the column after the column is added.

3.6. Run
(1) to write a custom function results in excle
(2) Example of execution in step
a) acquiring a first embodiment to be performed, to find the specific implementation of traversal sheet table with the embodiment.
b) performing step sheet table.
i. According to step sheet is determined whether the current use case executed successfully (number of patients with a need to be performed is equal to the number of cases used by the execution, is executed successfully)
II. If there is an error on the theme, and stores the error log
iii. test statistics performed how many use cases, how successful, how many failed.
c) the execution result is written in excle
4. Project Code
4.1 Code

Interested in Python or are studying a small partner, you can join us to learn Python buckle qun: 784758214, look at how seniors are learning! From basic web development python script to, reptiles, django, data mining and other projects to combat zero-based data are finishing. Given to every little python partner! Every day, Daniel explain the timing Python technology, to share some of the ways to learn and need to pay attention to small details, click on Join us python learner gathering

4.2 operating results

5. Analysis of the frame
(1) with an external test data file, a set of test cases using Excel and manage all steps of the test for each test case, the test case to achieve a complete file maintenance
(2) test results for each test case a document viewing and statistics
(3) by defining keywords, targeting and positioning operating elements of the expression values can be achieved and operational execution of each test step, can be more flexible to achieve the needs of test automation
(4) achieve targeting expression and separation test code to achieve targeting expression maintained directly in the test data file.
(5) framework provides log function to facilitate debugging and monitoring of the implementation of automated testing procedures
(6) testing framework based on keywords, even if people do not understand the development and testing of technology can also be implemented automated testing, to facilitate the promotion and use of automation throughout the test team testing technology to reduce technical barriers automated test implementation
(7) keyword-based way, it can be extended to any keyword to meet the needs of more complex test automation project

Guess you like

Origin blog.csdn.net/weixin_45523154/article/details/102750397