890 likes | 911 Views
Learn about the importance of front-end automation, the benefits it brings, and how to make your application more automatable. Discover different techniques and tools for front-end automation.
E N D
ENSURE YOUR USERS EXPERIENCE A trip around end user validation automation tools
WHY ARE WE HERE TODAY • Maybe you have a microservice environment that needs final verification • Maybe you have an architecture that doesn’t allow for better test coverage • Maybe you have no other support from the organization • Maybe you want your first experience with code • Maybe you have no other choice
Started writing automation early 2010s WHO AM I - RICK CLYMER Love python but have realized the use for other languages Huge Cleveland sports fan
WHO ARE YOU? Testing Experience Automation Experience Language Experience
WHAT’S THE PLAN FOR TODAY? • Why do we use front end automation • Make your application more automatable • Get Hands-On With Selenium • Get Hands-On With Cypress • Get Hands-On With TestCafe • Review what the path forward looks like
WHY HAVEN’T WE USED FRONT END AUTOMATION • It’s slow • It’s brittle • It’s too hard to write and maintain • No developers want to write it • Unit and integration tests cover everything, you can just manually check a few things
WHAT HAS IT COST YOU EVERY CARD/SPRINT/RELEASE MANUALLY CHECKING SIMPLE THINGS BUGS HAPPENING ON BROWSERS THAT UNIT AND INTEGRATION TESTS DON’T COVER REGRESSIONS SNEAKING THRU BECAUSE THERE SIMPLY WASN’T ENOUGH TIME MAYBE EVEN YOUR SANITY
SO WHY SHOULD WE DO IT • Fast feedback on front end working as users expect it to • Able to test an environment where all of your microservices are together • Repeatable automation that can validate your application in minutes • Expand your career and reputation with your development team • Learn your application at a whole different level
SO WHY SHOULDN’T WE DO IT • Development team doesn’t want to write any automation or tests • We want to have a testing square rather than a pyramid • It’s all we’ve ever done so why diversify ourselves
LET’S DREAM What would make our application more automatable?
SOME OF THE RECENT THINGS I’VE TRIED/SEEN • Loading spinners or indicators until a page is fully loaded • Accessible data • Making a mobile app a hybrid app • Custom endpoints • Common actions • Non-UI based actions
MY FAVORITE Div(contains(text(), “Locators”)
WHERE DO WE START WITH LOCATORS • Chrome Dev Tools • Allows you to see entire page source • Watch network traffic • Emulate your experience in a mobile system • Simulate a locator • Other ways to access • Code base • Automation tools scrapping page source
TYPES OF LOCATORS? • ID • Name • Class Name • CSS Selector • Xpath • Link Text • Tag Name
LOCATOR EXAMPLES • Class Name = ‘gLFyf gsfi’ • Google search input • Xpath = ‘//*[@class=“dropdown-menu league-nav med”]/li[@class=“league”]/a’ • ESPN league score selector • CSS Selector = "header[class=main-header]>div>nav>ul>li[id='about’]” • Python about link • ID = twotabsearchtextbox • Amazon search input
STEP 1 (EXERCISE)BUILD TASK APP LOCALLY ON YOUR COMPUTER • git clone –b master https://github.com/clymerrm/todo-list.git: • Or download zip file github.com/clymerrm/todo-list • From terminal, navigate to root directory of project • Docker-compose up -d Want to refresh the data, from root directory run npm run start-fresh https://rb.gy/3881b0
STEP 2 (EXERCISE)FIND LOCATORS FOR THE FOLLOWING ELEMENTS • New Task Name Input • Create task button • Home link • 1st completed task name • 3rd non completed task due date • Delete button https://rb.gy/3881b0
STEP 2 (REVIEW)FIND LOCATORS FOR THE FOLLOWING ELEMENTS • New Task Name Input • (By.Name, ‘title’) • Create task button • (By.CSS_Selector, "input[value='Create Task’]”) • Home link • (By.LINK_TEXT, “Home”) • 1st completed task name • (By.XPATH, “//*[contains(@style, 'text-decoration: line-through')][1]”) • 3rd non completed task due date • (By.XPATH, "//*[not(contains(@style, 'text-decoration: line-through'))]/p") • Delete button • (By.ID, “delete”) But which one did you click? https://rb.gy/3881b0
DATA TEST KEYS git checkout data-test-keys
STEP 3 (EXERCISE)REEVALUATE NOW THAT DATA TEST KEYS EXIST • New Task Name Input • Create task button • Home link • 1st completed task name • 3rd non completed task due date • Delete button https://rb.gy/3881b0
STEP 3 (REVIEW)REEVALUATE NOW THAT DATA TEST KEYS EXIST • New Task Name Input • (By.CSS_SELECTOR, ‘input[data-test-key=task-name-input’]) • Create task button • (By.CSS_Selector, "input[data-test-key=create-task-button’]”) • Home link • (By.CSS_SELECTOR, “a[data-test-key=‘HomeLink’]”) • 1st completed task name • (By.XPATH, '//*[@data-test-key=”completed-task-element"][1]’) • 3rd non completed task due date • (By.XPATH, "//*[@data-test-key=‘task-element’][3]/p/span[@data-test-key=‘task-due-date’]") • Delete button • (By.ID, “delete”) https://rb.gy/3881b0
BREAK TIME Back in 10 minutes?
WHAT IS SELENIUM WEBDRIVER? • Tool for automating front end interactions with browsers • Browsers supported: • Chrome, Firefox, Edge, Internet Explorer, Safari, Opera • Languages supported: • C#, Java, JavaScript, Python, PHP, Ruby • Creates a webdriver instance to connect to your browser from your codebase of choice • Many secondary packages can be used to extend the tool • Many reporting packages exist to make your test results more usable
What you need to do to get setup WHAT ARE WE GOING TO COVER WITH SELENIUM Writing your first test Review the most commonly used functionality Refactor our testing to more usable in the future
LET’S GET SETUP Latest version of Node and NPM Selenium webdriver – npm install selenium-webdriver Webdriver-manager – npm install webdrivrer-manager Editor of choice (Intellij IDEA, Visual Studio Code, Atom) Python 3.7 or higher Pipenv – pip3 install pipenv Selenium webdriver – pip3 install selenium Webdriver_manager – pip3 install webdriver_manager Python Editor of Choice (PyCharm, Visual Studio Code, Sublime Text)
START SELENIUM WEBDRIVER UP webdriver-manager update webdriver-manager start (will display in terminal) Optional to run in background: webdriver-manager start –detach from webdriver_manager.chrome import ChromeDriverManager from selenium import webdriver webdriver.Chrome(ChromeDriverManager().install())
TEAR SELENIUM WEBDRIVER DOWN If running in background, webdriver-manager shutdown If not, exit like you would anything else from command line driver.quit() or driver.close()
ASSERTING RESULTS Must use another package to assert results Common assertion library is Chai (https://www.chaijs.com/api/bdd/) const { expect } = require(‘chai’)’; driver.getTitle().then(function(title) { expect(title).to.equal(‘Google’) }); Use python’s built in assertion library assert something in some element Also can use external package to assert results Popular assertion human readable library is pyhamcrest from hamcrest import * assert_that(driver.title, equal_to(‘Google’))
FIND ELEMENTS ON A PAGE var webdriver = require(‘selenium-webdriver’), By = webdriver.By driver.findElement(By.name(‘delete’)) driver.findElements(By.xpath(“//*[@class=‘delete’]/button”) from selenium.webdriver.common.by import By driver.find_element(By.ID, “delete”) driver.find_elements(By.CSS_SELECTOR, “div[data-test-key=tasks]
COMMON SELENIUM COMMANDS – ELEMENT RELATED driver.findElement(By.name(‘delete’)) driver.findElements(By.xpath(“//*[@class=‘delete’]/button”) driver.find_element(By.ID, “delete”).click() newTask = driver.find_element(By.CSS_SELECTOR, “div[data-test-key=newTaskInput] newTask.send_keys(‘Some new task’)
SELENIUM API DOCUMENTATION • JavaScript • https://seleniumhq.github.io/selenium/docs/api/javascript/index.html • Python • https://selenium-python.readthedocs.io/
WRITE OUR FIRST “TEST” CREATE A NEW TASK WITH A DUE DATE OF TOMORROW MARK TASK AS COMPLETED DELETE A NEWLY CREATED TASK https://rb.gy/3881b0
HOW DID IT GO? • What should we do differently? • Is the app testable? • Is the app automatable? • Can these tests be extended for future usage?
BREAK TIME Back in 10 minutes?
GREAT, WE AUTOMATED SOMETHINGS, NOW WHAT? • Page objects • Test Framework • Waiting for elements state
CENTRALIZE YOUR LOCATORS AND APP FUNCTIONS • Use Page Object Framework • Objects representing a web page or component • What are they made up of? • Locators for that specific page/component • Interaction methods for that specific page/component • Why Do Them? • Future proof your automation code • Make your automation code easily reusable
HOW CAN WE STRUCTURE OUR PAGE OBJECTS • Create Tasks • Todo list • Todo list filtering • Header
PAGE OBJECT EXAMPLES https://rb.gy/3881b0
STOP WRITING ONE MASSIVE “TEST” • Use a test framework • Allows you to create a test suite rather than just automation lines of code • Usually include reporting frameworks