Using “switch” to combine Cucumberjs step functions

Those who write automated tests all know that we commonly end up repeating code, especially as web pages tend to contain many common elements. Instead of ending up with blocks of step code that vary very little, using Switch is a neat way to combine steps. Switch checks for a certain value, then ascribes variables with certain values based on that.

this.Given(/^I should see quantity (.*) for product (.*) on the (.*) page$/, function (quantity, productid, sitepage, callback) {
var url, i;
switch (sitepage) {
case 'hardware section':
url = '';
i = 11;
case 'product page':
url = '';
i = 9;
case 'shopping cart':
url = '';
i = 5;
browser.get(settings.url(url)).then(function () {
var product = element(by.cssContainingText('tr',productid))

No Comments

You can leave the first : )