Overview
Applied TestMethods

Applied TestMethods

Its goal is to take a look behind the curtain and see how such Bots work.

March 31, 2023
index

Overview of the Examples

Who watches the watchman?

Watchman Gif

Assignment

Prepare a comprehensive test that covers the functionality of the Tour of Heroes Web Application. Evaluate the functionality of the application and implement a test using Selenium for browser automation.

The assignment will be graded based on

  • Test Coverage
  • Code Quality
  • Documentation
  • Followed Test Practices

Prepairing the Project in VS Code

Prerequisites

  • Visual Studio Code with the python extension
  • some important packages

In Python it is common to import external libraries to call important functions. These libraries must be installed before they can be used. By installing Python it is now possible to execute the pip3 install NAMEOFPACKAGE or py -m pip install NAMEOFPACKAGE command in a terminal to install the needed libraries.

Installed Libraries

  • pip install beautifulsoup4
  • pip install selenium
  • pip install webdriver_manager

Execution

Setting up the webdriver:

To allow the driver to run on multiple OS like windows and IOS it is important to use the webdriver manager ChromeDriverManager().install

self.driver = webdriver.Chrome(ChromeDriverManager().install())

Using the Dev Tools:

Pressing F12 or Strg+Shift+i allows the user to open the dev tools on any web page and access the html code. Because selenium uses an web driver it has access to the html code as well and generates the possibility to find elements with different properties.

With the help of the combination of finding elements via ID or CLASS…

self.dashboardLink = self.driver.find_element(By.LINK_TEXT, "Dashboard")

… clicking buttons…

self.addHeroBtn = self.driver.find_element(By.CLASS_NAME, "add-button")
self.addHeroBtn.click()

… and pressing keys…

self.searchbar = self.driver.find_element(By.ID, "search-box")
self.searchbar.send_keys(wantedHeroName)

…it is possible to create any desired web scraper. In this specific case it is used to traverse through the provided web page remotely and tests the code quality.

The following possible interactions are beeing tested:

  • get all heroes
  • add a hero
  • search for a hero
  • delete a hero
  • show detailed information about a hero
  • change the name of a hero

To kill a Mockingbird

Mockingbird

Assignment

Write and test a class library used for managing item stock and orders in a warehouse. The IWarehouse interface is defined as such:

interface IWarehouse
{
bool HasProduct(string product);
int CurrentStock(string product);
void AddStock(string product, int amount);
void TakeStock(string product, int amount);
}
  • All methods throw for invalid product names (null or empty).
  • CurrentStock throws NoSuchProductException when called with a product for which HasProduct returns false.
  • TakeStock throws NoSuchProductException when called with a product for which HasProduct returns false.
  • TakeStock throws InsufficientStockException when called with an amount that exceeds what is currently stored. The Order class is used for filling individual orders from a warehouse.

Its interface is defined as such:

class Order
{
Order(string product, int amount);
bool IsFilled();
bool CanFillOrder(IWarehouse warehouse);
void Fill(IWarehouse warehouse);
}
  • The constructor throws for invalid product names (null or empty) and amounts < 1
  • IsFilled starts out with false and becomes true once Fill has been called successfully.
  • Fill rethrows any exceptions thrown by IWarehouse
  • Fill throws OrderAlreadyFilled when Fill is called for an order that has already been filled
  • CanFillOrder uses IWarehouse.HasProduct and IWarehouse.CurrentStock to check whether an order can be filled Implement and test both the Order class and an implementation of IWarehouse. When testing the Order class, use both your custom implementation of IWarehouse as well as Mock objects for testing the behaviour of Order.

Use MOQ or an equivalent Mocking library of your choice.