Four examples of automated test models and their advantages and disadvantages

Source: Internet
Author: User

One, linear test

1. Concept:

The linear script produced by recording or writing the corresponding application does not go. Simple to simulate the user's complete operation of the scene.

(Operations, repetitive operations, data) are all mixed together.

2. Advantages:

Each script is relatively independent and does not produce any other since and calls.

3. Disadvantages:

Development costs are high, and duplicate operations exist between use cases. For example, duplicate user login and exit.

High maintenance costs, because of repeated operations, when the repeated operation changes, you need to make a script modification.

4. Linear Test Example

User Login

#Coding=utf-8" "Created on 2016-7-20@author:jenniferproject: simple element Operation login 126 mailbox, Element Clear (), Send_keys (), click () operation found some elements not located when locating Finally, it was found that another page was actually embedded in the iframe,frame. If the IFRAME has a name or ID, use Switch_to_frame ("Name value") or Switch_to_frame ("id value") directly, which is the most ideal and easiest way to do so. " " fromSeleniumImportWebdriverImportTimedriver=Webdriver. Firefox () Driver.get (R'http://www.126.com/')#string plus r to prevent escaping. Time.sleep (3)Print 'start signing in to your mailbox'Try:    assert '126' inchDriver.title#title is variable, cannot title ()exceptAssertionerror:Print "error: The URL is not entered correctly"Else:    Print "Logging: URL input is correct"#driver.switch_to_frame (' x-urs-iframe ') #跳转到iframe框架Driver.switch_to.frame ('X-urs-iframe')#jump to the IFRAME frame as in the above statementUsername=driver.find_element_by_name ('Email') Username.clear () Username.send_keys ('JENNIFERHLF') Time.sleep (0.1) userpasswd=driver.find_element_by_name ('Password') Userpasswd.clear () Userpasswd.send_keys ('04870487ok_') Time.sleep (0.1) LOGINBT=DRIVER.FIND_ELEMENT_BY_ID ('Dologin') Loginbt.click () Time.sleep (3)        Try:        assert 'NetEase Email' inchDriver.titleexceptAssertionerror:Print 'Mailbox Logon Failure'    Else:        Print 'Mailbox Login Successful'    finally:    #operation: Receiving letters, writing letters and other operations, not to write an exampledriver.quit ()Print 'End of Test'

Second, modular Drive test

1. Concept:

The duplicate operation succeeds in the common module, which is called when the use of the module operation is required during the execution of the case.

Operations + (repetitive operations, data) are blended together.

2. Advantages:

Improved development efficiency and maintainability of test cases due to maximum elimination of duplication.

3. Disadvantages:

Although the steps for modularity are the same, the test data is different. For example, repeat the login module, if the user is different, you will still have to write the logon script repeatedly.

4. Example

Public modules: Modular encapsulation of logins and exits

The following user name password to apply for themselves, will not be the author's user password affixed out.

#Coding=utf-8" "Created on 2016-7-27@author:jenniferproject: Modular Drive Test instance, placing duplicate logon scripts in separate scripts for other use cases to invoke" "Import TimeclassLogin ():defUser_login (self,driver): Username=driver.find_element_by_name ('Email') Username.clear () Username.send_keys ('username') Time.sleep (0.1) userpasswd=driver.find_element_by_name ('Password') Userpasswd.clear () Userpasswd.send_keys ('Password') Time.sleep (0.1) LOGINBT=DRIVER.FIND_ELEMENT_BY_ID ('Dologin') Loginbt.click () Time.sleep (3)            defuser_logout (self,driver): Driver.find_element_by_link_text (U'Exit'). Click () driver.quit ()

Letter use case: The following code used a variety of positioning methods, it is worth learning, and then re-summarize this part

The login and Exit methods of the module are called directly.

#Coding=utf-8" "Created on 2016-7-27@author:jenniferproject: Send mail" " fromSeleniumImportWebdriverImport Time fromTest_5_2_publicImportLogin#because the public module file is named Test_5_2_publicDriver=Webdriver. Firefox () driver.implicitly_wait (30) Driver.get (R'http://www.126.com/')#string plus r to prevent escaping. Time.sleep (3) Driver.switch_to.frame ('X-urs-iframe')#invoking the Login moduleLogin (). User_login (Driver) time.sleep (10)#Send mail#Click Outbox#_mail_component_61_61 is a dynamic ID, so it cannot be used to locate#driver.find_element_by_css_selector (' #_mail_component_61_61 >span.oz0 '). Click ()#Cannot add U "//span[contains (text (), U ' write ')]", otherwise cannot be located. #The following positioning is to find the span label with a text (text) containing (contains) ' Letter ' element, which is important for the positioning methodDriver.find_element_by_xpath ("//span[contains (text (), ' letter ')]"). Click ()#fill in the recipientDriver.find_element_by_class_name ('Nui-editableaddr-ipt'). Send_keys (R'[email protected]')#fill in the topic#connect more properties with and to uniquely flag an elementDriver.find_element_by_xpath ("//input[@class = ' nui-ipt-input ' and @maxlength = ' + ']"). Send_keys (U'Automated Testing')#fill in the text#switch the current position to the inline page of the Frame/iframe form via Switch_to_frame ()Driver.switch_to_frame (Driver.find_element_by_class_name ('App-editor-iframe'))#Locate the message content location inside the embedded pageEmailcontext=driver.find_element_by_class_name ('Nui-scroll')#fill in the email contentEmailcontext.send_keys (U'This is the first automated test e-mail')#jump back to the outermost page by Switch_to (). Default_content ( )#Note: Do not write Switch_to (). Default_content (), otherwise report Attributeerror:switchto instance has no __call__ methoddriver.switch_to.default_content ()#Driver.switch_to.parent_frame ()#Click SendTime.sleep (3)#It is possible that an element is not visible (the viewing element is gray) and elementnotvisibleexception error is reported#contains a lot of elements to send two words, so you have to add other restrictions#Sendemails=driver.find_element_by_xpath ("//span[contains (Text (), ' send ')]")Sendemails=driver.find_element_by_xpath ("//span[contains (text (), ' send ') and @class = ' nui-btn-text ')") Time.sleep (3)#Verify that the message was sent successfullyTry:    assert 'sent successfully' inchDriver.page_sourceexceptAssertionerror:Print 'message sent successfully'Else:    Print 'message failed to send'#Call Exit ModuleLogin (). User_logout (Driver)

Receiving Credit Example:

The login and Exit methods of the module are called directly.

#Coding=utf-8" "Created on 2016-7-27@author:jenniferproject: Receiving mail" " fromSeleniumImportWebdriverImport Time fromTest_5_2_publicImportLogindriver=Webdriver. Firefox () driver.implicitly_wait (30) Driver.get (R'http://www.126.com/')#string plus r to prevent escaping. Time.sleep (3) Driver.switch_to.frame ('X-urs-iframe')#invoking the Login moduleLogin (). User_login (Driver) time.sleep (10)#Receive mail#Click to receive the message#The following positioning is to find the elements of the span tag that contain (text) contains (contains) ' receiving ', which is important for the positioning methodDriver.find_element_by_xpath ("//span[contains (text (), ' receiving letter ')]"). Click ()#Check to enter Inbox without errorTry:    #Click on one of the messagesDriver.find_element_by_xpath ("//div[@sign = ' letter ']"). Click ()exceptException as E:PrinteElse:    Print 'Successful receipt of the letter'#Call Exit ModuleLogin (). User_logout (Driver)

Third, data-driven testing

1. Concept:

It separates the test data and operations in the test, and the data is maintained separately in another file.

By changing the data to drive the execution of automated tests, the results of the test are eventually changed.

Operation + Repeat operation + data separation.

2. Advantages:

In this way, the data is separated from the repetitive operation, which can quickly increase the similarity test and complete the test under different data conditions.

3. Disadvantages

Not currently

4. Example

Not to be continued

Four, keyword-driven testing

1. Concept:

The implementation of automated tests is driven by the change of keywords, resulting in changes in test results. Keyword-driven tools are: Robotframework (RIDE).

2. Advantages

Not to be continued

Four examples of automated test models and their advantages and disadvantages

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.