Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

cucumber-test

1.2.44 • Public • Published

Cucumber Test

Made easy - Cucumber testing using webdriver.io, instead of writing complicated test code that only developers can understand, Cucumber maps an ordinary language to code and allows to start with the test process in the early stages of your product development. cucumber-test is a fork of cucumber-boilerplate.

Quick start

  1. npm install -g cucumber-test selenium-standalone
  2. selenium-standalone install
  3. selenium-standalone start
  4. create folder features
  5. add file features/simple.feature
  6. run cct (or cct -b chrome,firefox,safari --timeout 40000 -i 3)

if step 2,3 show some warnings, might be behind proxy / VPN, please check section Behind proxy or vpn below.

Feature:
    Search on Google
 
Scenario: Navigate to Google
    Given I open the url "https://www.google.com"
    Then I expect that the title is "Google"
 
Scenario: Search cucumber-test
    When I set "cucumber-test" to the inputfield "[name=q]"
    And I expect that element "input.lsb" becomes visible
    And I click on the button "input.lsb"
    Then I expect that element "a[href='https://cucumber.io/']" becomes visible

Extended tags

Extended tags will simplify how to write cucumber with different browser & environment, those information are available on the browser object, utilize during execution of the cucumber file:

// Browsers
@__chrome            ><  @__non_chrome
@__safari            ><  @__non_safari
@__firefox           ><  @__non_firefox
@__microsoftedge     ><  @__non_microsoftedge
@__internetexplorer  ><  @__non_internetexplorer
 
// Mobile specific
@__android           ><  @__non_android
@__mobile            ><  @__non_mobile
@__ios               ><  @__non_ios
 
// url related
@__url           ex: =>  @__url:/search
@__mainUrl       ex: =>  @__mainUrl:/search
@__non_url       ex: =>  @__non_url:/search
@__non_mainUrl   ex: =>  @__non_mainUrl:/search
@__waitForUrl    ex: =>  @__waitForUrl:/search
 
// Selector, it can be css or xpath (without `@`)
@__$             ex: =>  @__$://*[class='dialog']//button
 
// cookies
@__cookies       ex: => @ __cookies:user=alex,locale=US
 
// for development
@__debug

Sample usage can be seen on the example below Search on Google, when it get executed on the desktop browser like chrome, firefox or IE, it will pickup scenario with:

@__non_safari @__non_mobile and the @__mobile will be filtered

and viceversa will happened when it get executed on mobile.

Appium

Android device

please check the developer tools security options, ensure them to be checked.

  • USB debugging
  • USB debugging(Security settings)
Feature: Search on Google
    Search should be on the google website
    and the first should be cucumber.io
 
Scenario: Navigate to Google
    Given I open the url "https://www.google.com"
    Then I expect that the title is "Google"
 
@__non_safari @__non_mobile
Scenario: Search cucumber-test on desktop browser
    When I set "cucumber-test" to the inputfield "[name=q]"
    And I expect that element "input.lsb" becomes visible
    And I click on the button "input.lsb"
    Then I expect that element "a[href='https://cucumber.io/']" becomes visible
 
@__mobile
Scenario: Search cucumber-test on mobile browser
    When I set "cucumber-test" to the inputfield "[name=q]"
    And I expect that element "[name=btnG]" becomes visible
    And I click on the button "[name=btnG]"
    Then I expect that element "a[href='https://cucumber.io/']" becomes visible
# Install appium server 
npm install -g appium appium-doctor
# run appium & connect your android device using USB 
appium
# check deviceName - adb devices & pass to deviceName:android version 
cct --android f344ee26:7.0

Fits (Feature in tight scenario)

Enhancement on how to write cucumber-test, this feature will make developer much faster to produce automation, as simpler to write the tests. -d / --dev is the option to trigger compiling from fits folder to feature folder.

When run in the jenkins job, usually folders are readonly, make sure -d is excluded from job.

flib/share.feature

Feature: Share Scenario
    To be share during automation
 
Scenario: Navigate to Google
    Given I open the url "https://www.google.com"
    Then I expect that the title is "Google"
 
@__non_mobile @__chrome @__non_url:localhost
Scenario: Search cucumber-test
    When I type "cucumber-test" to the inputfield "${g.q}"
    And I expect that element "${g.btnG}" becomes visible
    And I click on the button "${g.btnG}"
    Then I expect that element "a[href='https://cucumber.io/']" becomes visible
 
@__non_mobile @__non_chrome
Scenario: Search cucumber-test
    When I type "cucumber-test *" to the inputfield "${g.q}"
    And I expect that element "${g.btnG}" becomes visible
    And I click on the button "${g.btnG}"
    Then I expect that element "a[href='https://en.wikipedia.org/wiki/Cucumber_(software)']" becomes visible
 
@__mobile
Scenario: Search cucumber-test
    When I type "cucumber-test mobile" to the inputfield "${g.q}"
    And I expect that element "${g.btnM}" becomes visible
    And I click on the button "${g.btnM}"
    Then I expect that element "a[href='https://cucumber.io/']" becomes visible

fits/google/google.feature

Feature: Search on Google
    Search should be on the google website
    and the first should be cucumber.io
 
Scenario: Navigate to Google
Scenario: Search cucumber-test
 
$ cct -f google -b safari -d

Config & Variables

Setting up browsers capabilities and adding variables that can be use inside steps statement. Put config.js in the current folder (above features folder) where you will run cucumber-test.

config.js will automatically pickup by runner or you can provide the fullpath in CLI:

cct -f google --config ./config.js -b chrome
cct -f google -b chrome,safari,firefox

Integration with BrowserStack

Add these env variables from your BrowserStack user & key:

export BROWSERSTACK_ACCESS_KEY=xxXXXxXxXxXxxXxXXXxx
export BROWSERSTACK_USERNAME=cucumber-test
cct -c browserstack

Integration with SauceLabs

Add these env variables from your Saucelabs user & key:

export SAUCE_ACCESS_KEY=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
export SAUCE_USERNAME=cucumber-test
cct -c saucelabs:connect
cct -c saucelabs

Behind proxy or vpn:

export NODE_TLS_REJECT_UNAUTHORIZED=0
npm install -g selenium-standalone@latest
selenium-standalone install
selenium-standalone start
cct -t '@smoke'

This env vars can be keep into bash/zsh profile/rc

export NODE_TLS_REJECT_UNAUTHORIZED=0

Tips

Safari (technology preview) known problem

Safari Technology Preview is the best way to get the latest update of the webdriver included in Safari.

You must enable the "Allow Remote Automation", you need to launch Safari and go to the menu "Develop > Allow Remote Automation" & make sure that it is checked.

Hang or Error(from selenium-standalone): safaridriver could not launch because it is not configured correctly, need to open a terminal console and manually configure as a super user: "sudo safaridriver --enable".

Firefox known problem

cannot access dead object, the open ticket was filled on April 8, 2017. should be careful if plan to create scenario involved with iframe.

element#id is not supported in geckodriver, the open ticket was filled on Nov 2, 2017. see locator strategy in w3c.org.

Dev Mode

cd ~/.nvm/versions/node/v8.8.1/lib/node_modules
ln -s /Users/wharsojo/Dev/cucumber-test cucumber-test

License

MIT

install

npm i cucumber-test

Downloadsweekly downloads

2

version

1.2.44

license

MIT

repository

githubgithub

last publish

collaborators

  • avatar