Translate a BDD User Story to a Pester/Selenium Test

on Monday, October 28, 2019

This is a very simple example of taking a User Story that’s written in a BDD style given-when-then pattern and converting it into a Selenium based UI Test. To do this, I’m going to use Pester and a Selenium Powershell module (mentioned previously in Selenium & Powershell) to write the executable test.

So, let’s start out with a very common scenario, logging into a website. It’s not the greatest example as it’s generally assumed that development teams will need to ensure this functionality works and might not make it into requirements written by end users or driven by business value statements. But, here’s the simplified use case anyways:

Scenario: User logs in with valid credentials

Given that I am not logged in,

When I enter my username and password and click the Log In button,

Then I will be logged in and I will see the Search page.

So, let’s translate this to some example code:

Selenium & Powershell

on Monday, March 25, 2019

Selenium is sort of a pseudo-industry standard for UI browser testing. There are others tools available (like cypress.io), but Selenium is a really well known / popular. And that’s why it’s ported or made available into so many other languages. It’s made available in Powershell using the Selenium module by Adam Driscoll (he was the creator of the Powershell Tools for Visual Studio).

The documentation in the github readme.md is short, but its all you really need to get started. But, you quickly start to run into the same problems the rest of the Selenium community runs into (Selenium – How to wait until page is completely loaded [duplicate], Selenium wait for Ajax content to load – universal approach).

So, here’s a quick function to help wait for a particular element on a page to load.

And, here’s a sample Pester test using the function.


Creative Commons License
This site uses Alex Gorbatchev's SyntaxHighlighter, and hosted by herdingcode.com's Jon Galloway.