Exercise 10

info

This is an in-class exercise. An exercise page like this one will contain a brief description but is intended to be supplemented by discussion during our meeting time. Complete the exercise to the best of your ability in the time given. Feel free to talk with other students as you work, and do not be afraid to ask questions. Aim to complete as much as possible during our meeting and continue to work at home to finish, but you need not hand it in.

Learning Objectives#

Objectives

This exercise should help you practice with:

  • GUI testing
  • Selenium tool

Answer the following questions#

  • What are the pros and cons of manual GUI Testing?
  • What are the pros and cons of capture-then-replay GUI testing?
  • What is Page Object Desing Pattern? Read this.
  • What is the most efficient way (i.e., requires least DOM traversal) of selecting/locating an html item? What is the worst?

Task 1#

  1. Create a Gradle Java project as usual! Make sure the following dependencies exist in build.gradle to import Selenium and other required APIs:
testImplementation 'org.seleniumhq.selenium:selenium-java:4.29.0'
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.17'

Follow the instructions in here to start using Selenium in Java. Then, write separate test-cases/web-automations using Selenium Web Driver to automate each of the followings:

  • Visit https://www.allrecipes.com/ -> locate the search bar -> type in tiramisu -> click search -> verify the title of the page contains the word tiramisu
  • Visit https://www.allrecipes.com/ -> click on Meals -> Click on Lunch -> verify the word "Sandwich" exists somewhere in the page.
  • Visit https://www.allrecipes.com/ -> take a screen shot and save it in a file named allrecipescom.png
  1. Now, refactor your code to use Page Object design pattern. Read this page to learn about this design pattern. Specifically, create a class named "MainPage" in which you have all your selectors of the main page (i.e., https://www.allrecipes.com/) as well as a method named search that takes a String named query as input and conducts a search with the query string.

Task 2 (Optional)#

To practice with Selenium IDE, try to replicate the above test cases on Selenium IDE. You can install Selenium IDE as a Chrome Plugin from here and learn about it here.