Skip to content

Instantly share code, notes, and snippets.

@SimitTomar
Created November 26, 2015 14:25

Revisions

  1. SimitTomar created this gist Nov 26, 2015.
    45 changes: 45 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    @christian-bromann My question is around the Custom Commands. I went through the example given here: http://webdriver.io/guide/usage/customcommands.html

    Based on that created to JS files

    1) getUrlAndTitle.js: which contains the code for custom command:


    client.addCommand("getUrlAndTitle", function(customVar, cb) {
    this.url(function(err,urlResult) {
    this.getTitle(function(err,titleResult) {
    var specialResult = {url: urlResult.value, title: titleResult};
    cb(err,specialResult);
    console.log(customVar); // "a custom variable"
    })
    });
    });




    2) Test.js: which contains the step Definitions:


    this.Then(/^I Select an appropriate Title$/, {timeout: 30 * 1000}, function (next) {
    this.client
    .init()
    .getUrlAndTitle('a custom variable',function(err,result){
    console.log('entered getUrlAndTitle');
    })

    .then(function() {
    this.call(next);
    });
    });



    But the Issue is that I am not getting .getUrlAndTitle as a command when I do this.client. , I just typed it manually in the step definition to see the output. Of course, the corresponding step is failing.
    Is there anything that I am missing here, do I need to add the path of getUrlAndTitle.js in Test.js like

    var getUrlAndTitle = require('tests/acceptance/wdio/utilities/helper/getUrlAndTitle.js');

    or add the command in world.js

    Please suggest