test design essentials for great test automation - titus

14
TEST DESIGN FOR GREAT AUTOMATED TESTS TITUS FORTNER

Upload: sauce-labs

Post on 29-Jan-2018

331 views

Category:

Technology


0 download

TRANSCRIPT

T EST DES IGN FOR GREAT AU TOM ATED TESTSTITUS FORTNER

10/25/2017 2© Sauce Labs, Inc.

Th ink Before You Tes t• Test Creation vs Test Maintenance Costs

• Each Test

• What does a failure indicate about the correctness of the system?• How much does a success increase confidence?

• Framework Design

• Configuration / Settings (browser, application, parallelization, etc.)• Initialization and Cleanup • Assertions on Actions (Tests)• Site Modeling Abstractions (Page Objects)• Wrappers and Helpers• Data

3© Sauce Labs, Inc.

Manual Tes t ing Example

10/25/2017 4© Sauce Labs, Inc.

Trans la ted in to Seleniumdriver = Selenium::WebDriver.for :chromedriver.get "https://address-book-example.herokuapp.com"driver.first(css: "a[data-test='sign-in']").clicksleep 0.5driver.first(css: "a[data-test='sign-up']").clickemail = "#{rand 10000000}@example.com"password = 'test1234'sleep 0.5driver.first(id: "user_email").send_keys emaildriver.first(id: "user_password").send_keys passworddriver.first(css: "input[data-test='submit']").clickexpect(driver.first(css: "span[data-test='current-user']").text).to eq emaildriver.first(css: "a[data-test='sign-out']").clickexpect(driver.all(css: "a[data-test='current-user']")).to be_emptydriver.first(id: "session_email").send_keys emaildriver.first(id: "session_password").send_keys passworddriver.first(css: "input[data-test='submit']").clickexpect(driver.all(css: "span[data-test='current-user']")).not_to be_emptydriver.first(css: "a[data-test='addresses']").clicksleep 0.5driver.first(css: "a[data-test='create']").clicksleep 1driver.first(id: 'address_first_name').send_keys "First"driver.first(id: 'address_last_name').send_keys "Last"

driver.first(id: 'address_line_1').send_keys "123 Main” driver.first(id: 'address_city').send_keys "London"driver.first(id: 'address_state').send_keys "Confusion"driver.first(id: 'address_zip_code').send_keys "0"driver.first(id: 'address_note').send_keys "Hi Mom"driver.first(css: "input[data-test='submit']").clickexpect(driver.first(id: 'notice').text).to eq 'Address was successfully created.'driver.first(css: "a[data-test='list']").clicksleep 0.5expect(driver.all(css: 'tbody tr').size).to eq 1driver.first(css: 'tbody td:nth-child(6) a').clicksleep 0.5driver.first(id: 'address_first_name').cleardriver.first(id: 'address_first_name').send_keys "Changed"driver.first(id: 'address_last_name').cleardriver.first(id: 'address_last_name').send_keys "Name"driver.first(css: "input[data-test='submit']").clickexpect(driver.first(id: 'notice').text).to eq 'Address was successfully updated.'driver.first(css: "a[data-test='list']").clicksleep 0.5expect(driver.first(css: 'td').text).to eql "Changed"expect(driver.first(css: 'td:nth-child(2)').text).to eql "Name"driver.first(css: 'td:nth-child(7) a').clickdriver.switch_to.alert.acceptexpect(driver.first(id: 'notice').text).to eq 'Address was successfully destroyed.'expect(driver.all(css: 'tbody tr')).to be_empty

5© Sauce Labs, Inc.

Act ions Taken

Navigate to Sign InNavigate to Sign UpSubmit Sign Up formVerify Sign UpSign OutVerify Sign OutNavigate to Sign InSubmit Sign In FormVerify Sign InNavigate to Address List

Navigate to New AddressSubmit New Address FormVerify new AddressNavigate to Edit AddressSubmit Edit Address FormVerify Edit AddressNavigate to Address ListDelete AddressVerify Address Deleted

6© Sauce Labs, Inc.

Funct ional i ty Being Tes ted

Navigate to Sign InNavigate to Sign UpSubmit Sign Up formVerify Sign UpSign OutVerify Sign OutNavigate to Sign InSubmit Sign In FormVerify Sign InNavigate to Address List

Navigate to New AddressSubmit New Address FormVerify new AddressNavigate to Edit AddressSubmit Edit Address FormVerify Edit AddressNavigate to Address ListDelete Address Verify Address Deleted

7© Sauce Labs, Inc.

Sp l i t Them Upit'signsup'doSignUp.visit.submit_form(user)expect(Home.visit.signed_in_user).toeq user.email_addressend

it'logsin'doSignUp.visit.submit_form(user)Home.new.sign_out_userSignIn.visit.submit_form(user)expect(Home.new.logged_in?).toeq trueend

it'logsout'doSignUp.visit.submit_form(user)Home.new.sign_out_userexpect(Home.new.logged_in?).toeq falseend

it'creates'doSignUp.visit.submit_formAddressNew.visit.submit_form(address)expect(AddressShow.new.created_message?).toeq trueexpect(AddressShow.new.address?(address)).toeq trueend

it'lists'doSignUp.visit.submit_formAddressNew.visit.submit_form(address)address2=AddressNew.visit.submit_formexpect(AddressList.visit.address?(address)).toeq trueexpect(AddressList.visit.address?(address2)).toeq trueend

it'edits'doSignUp.visit.submit_formAddressNew.visit.submit_form(address)AddressShow.new.update_address(address)edited_address =AddressEdit.visit(address).submit_formexpect(AddressShow.new.updated_message?).toeq trueexpect(AddressShow.new.address?(edited_address)).toeqtrueend

it'deletes'doSignUp.visit.submit_formAddressNew.visit.submit_form(address)AddressList.visit.destroy(address)expect(AddressList.new.destroyed_message?).toeq trueexpect(AddressList.new.address?(address)).toeq falseend

8© Sauce Labs, Inc.

Running on Sauce

10/25/2017 9© Sauce Labs, Inc.

Resul ts in Ser ia l 2 minutes, 55 seconds

10/25/2017 10© Sauce Labs, Inc.

Resul ts in Para l le l 1 minute, 30 seconds

10/25/2017 11© Sauce Labs, Inc.

Avoid the Browser• Use the same information the browser does, without the browser

• Log in users with a cookie instead of a form

• Use the Application API

(Mobile? JS Framework?)

10/25/2017 12© Sauce Labs, Inc.

Log In User

10/25/2017 13© Sauce Labs, Inc.

Crea te Address

10/25/2017 14© Sauce Labs, Inc.

Resul ts us ing API 45 seconds!!!