Automated test case
1, a frame. The company has a framework for direct use
2, there is no framework. Choose their own framework, write frame.
Our framework presented here is not a case, then the next, start learning how to do the automation framework
Process
First to set a framework to write automated process:
- Example data read by
- Call interface, get results
- Determine whether the expected results and the actual results are consistent
- Save the test results, which writes excel
- Generate test reports, send e-mail
Frame set
Inside the framework, we have what directory it?
- cases: test cases
- conf: configuration files
- lib: Testing Tools
- logs: Logs
- report: report
- main.py: The main program
- readme.txt: Notes
ATP │ main.py │ readme.txt │ ├─cases │ test.xlsx │ ├─conf │ │ settings.py │ │ │ └─__pycache__ │ settings.cpython-36.pyc │ ├─lib │ my_request.py │ parse_request_data.py │ parse_response_data.py │ tools.py │ ├─logs │ atp.log │ └─report
All these directories is the basic framework of the whole, we can achieve a complete process, then the process is now divided over what to do
Read test data
Read test cases from Excel
Use Case form we want to set it:
project | url | Request method | Request header | Request parameter | Whether json | expected results | actual results | Whether by | Testers |
A test project | /api/user/login | get | username=<username>, password=<password> |
Yes | code=0,age>10 | Ganzi Wen | |||
Moreover, we support parameterized request parameters, such as <username> in the table is actually read out is replaced with a parameter; Analyzing the expected result can support, such as expected results age> 10, keep up with the actual results returned if the comparison result of age> 10.
1, parameterization
Data falsification module --faker
faker module can generate a lot of stuff: phone number, address, bank card number, zip code, province, etc.
Reference: https://faker.readthedocs.io/en/latest/locales/zh_CN.html
Commonly used methods: city_suffix (): city and county country (): National country_code (): Country code district (): District geo_coordinate (): geographical coordinates of latitude (): geographical coordinates (latitude) longitude (): geographical coordinates (longitude) lexify (): replace all question marks ( "?") events with random letters. numerify (): three random numbers postcode (): Zip province (): State street_address (): Street address street_name (): street name street_suffix (): Street, road random_digit (): 0 ~ 9 random number random_digit_not_null (): 1 to the random number 9 random_element (): random letters random_int (): random number, the default 0 to 9999 , can be set by setting min, max random_letter (): random letters random_number (): random number parameter digits set generated digits color_name (): random color name hex_color (): random HEX color rgb_color (): random RGB color safe_color_name (): random-safe color name safe_hex_color (): random security HEX color bs (): random company service name company (): random company name (long) company_prefix ( ): random company name (short) company_suffix (): company type credit_card_expire (): random credit card expiration date credit_card_full (): generate full credit card information credit_card_number (): credit card number credit_card_provider (): credit cards credit_card_security_code (): Credit Card security code CURRENCY_CODE (): money coding am_pm the (): AM / the PM cENTURY (): random century dATE (): random date date_between (): randomly generated within a specified date range, parameters: start_date, end_date value: specific date or Today, - 30d, - 30Y similar date_between_dates (): randomly generated within a specified date range, use ibid date_object (): random production of 1970 -l-1 to random date specified date. date_this_month (): date_this_year (): date_time (): randomly generate a specified time (1 January 1970 to date) date_time_ad (): generated the year 1 to the current random time date_time_between (): Use with a dates future_date (): Future date future_datetime (): future time month (): random month month_name (): random month (English) past_date (): randomly generated has a past date past_datetime (): randomly generated time that has elapsed time (): random 24-hour time timedelta (): random acquisition time difference time_object (): random 24-hour time, time objects time_series (): random TimeSeries Object timezone (): random time zone unix_time (): random Unix time year (): random Year file_extension (): random file extension file_name (): random file name (including the extension, without path) file_path (): random file path (including the file name, extension) mime_type (): random mime Type ascii_company_email (): random ASCII E-mail name ascii_email (): random ASCII mailbox ascii_free_email (): ascii_safe_email (): company_email (): domain_name (): generating domain name domain_word (): Domain term (ie, does not contain a suffix) Email () : free_email (): free_email_domain (): f.safe_email (): security mailbox f.image_url (): random URL address ipv4 (): random IP4 address ipv6 (): random IP6 address mac_address (): random MAC address tld () : Web site domain name suffix (. .com, .net.cn, etc., are not included) uri (): random URI address uri_extension (): URL file extension uri_page (): URL file (containing no suffix) uri_path (): URL file path (not including the file name) url (): random URL address user_name (): random user name isbn10 (): random ISBN (10 Wei) ISBN13 (): random ISBN (13 Wei) the job (): random posts paragraph (): generating a random paragraph paragraphs (): randomly generating a plurality of passages, the number of paragraphs is controlled by the parameter nb, returns an array of sentence (): randomly generated word sentences (): generating a plurality of random words, similar to the paragraph text (): randomly generated article (do not fantasize about artificial intelligence, and so far did not fully understand what a word means) word (): randomly generated words words (): randomly generating a plurality of words, and the use of paragraphs, sentences, similar binary (): randomly generated binary-coded boolean (): True / False language_code (): randomly generated two coding language locale (): randomly generated language / international information md5 (): randomly generated MD5 null_boolean (): NULL / True / False password (): randomly generated passwords, optional parameters: length: password length; special_chars: can use special characters; digits: contains numbers; upper_case: contains uppercase letters; lower_case: lowercase letters contain sha1 (): random SHA1 sha256 (): random SHA256 uuid4 (): random UUID first_name (): first_name_female (): female name first_name_male (): male name first_romanized_name (): Roman name last_name (): last_name_female (): female name last_name_male (): male surname last_romanized_name (): name (): randomly generated full name name_female (): Men's full name name_male () : Women full name romanized_name (): Roman name msisdn (): mobile station international Subscriber Identity, namely mobile ISDN number of users phone_number (): randomly generated phone number phonenumber_prefix (): randomly generated segments phone number profile (): randomly generated file information simple_profile (): simple Profile information generated randomly generated randomly specified type of data: pybool (): pydecimal (): pydict (): pyfloat (): left_digits =. 5 # generated integer bits, right_digits = 2 # generates decimal digit, positiveTrue = # if only positive pyint (): pyiterable () pylist () pyset () pystr () pystruct () pytuple () ssn (): generated ID number chrome (): randomly generated Chrome browser user_agent information firefox (): randomly generated FireFox browser user_agent information internet_explorer (): randomly generated IE browser user_agent information Opera (): randomly generated Opera browser user_agent information Safari (): randomly generated Safari browser user_agent information linux_platform_token () : random Linux information user_agent (): random user_agent information
For example, to generate mail and other:
Import faker f = faker.Faker (locale = ' zh-CN ' ) # China's Print (f.credit_card_number ()) # credit card number Print (f.email ()) # E-mail Print (f.phone_number ()) # phone No. Print (f.ssn ()) # identification number Print (f.user_name ()) # random user name