2014年5月7日星期三

Undocumented features of grunt-mocha-webdriver

There are always neat packages in developer communities to help you as long as you can find them. Today my example is grunt-mocha-webdriver. Yes! you get it (from the name): it can help if you use gruntjs, mocha and selenium webdriver in your web application project or testing project.

Getting started

Make sure you want to keep reading if you:

  • want to test your web applications
  • manage child processes for testing in Gruntfile.js and it's a boring job
  • maintain custom test driver, like injecting environmental options into test suites
  • want to have options on selenium service providers
Or just read the ****ing source code directly if you're rock star developer and jump into the code section directly. 

Note: I'm not providing free test minutes backdoor to saucelabs.com nor browserstack.com...If you ever think about it, please go to their popular free trial page.

Read doc

Follow the readme file of grunt-mocha-webdriver to pick it up in minutes. Then keep reading.

Check out additional features

#1: I like saucelabs.com...but I dislike creating tunnel (it doesn't work all the time)
You can use the following options to treat saucelabs.com as a normal selenium service provider plus online videos of test session:


grunt.initConfig({
    mochaWebdriver: {
        saucelabs: {
           options: {
               hostname: "ondemand.saucelabs.com",
               port: 80,
               identifier: null,
               browsers: [...],
               ...
           }
        }
    }
});


When means it will connect to saucelabs.com but no tunnel created. Don't forget exporting your username and access key to environment.

Yes, you can, I'm not kidding and it works very well. in the same way as #1, you need to provide the configuration information (no tunnel created):


grunt.initConfig({
    mochaWebdriver: {
        browserstack: {
           options: {
               hostname: "hub.browserstack.com",
               port: 80,
               identifier: null,
               browsers: [{

                   browserName: "internet explorer",
                   platform: "WINDOWS",
                   version: "10.0",
                   "browserstack.user": process.env.BROWSERSTACK_USER,
                   "browserstack.key":  process.env.BROWSERSTACK_KEY
               },
               ...
               ]
           }
        }
    }
});

Then you can enjoy the full list of browser/platform combinations from browserstack.com.

So far, you still need tunnel to test application started at local machine, I didn't have good experience on testing over tunnel yet.

Finally, don't blame me if your Gruntfile.js becomes too long :)

没有评论: