Be your own SaaS

You take a few products from open source, integrate, customise. It’s still called development, and it still requires skill – that is is you want your test framework to be stable and grow. It needs skill, as you need to minimise product-dependencies ongoing, or you can quickly get lost in spiral of dependency failures, as you update core framework.

You can chase rainbows for the ultimate test automation tool – there are those using open source, with same dire “all your problems are over” style taglines for their SaaS.

While you are chasing your rainbow, I will have built a framework and maintained it for resusability and open to all to use – tech and non-tech people alike. By trusting a third-party vendor or SaaS, you constrict your team immediately to work a certain way. It limits creativity and relevance.

UI/API Test Framework Github Repos

CucumberJS/Protractor

[embedGitHubReadme owner=”jaffamonkey” repo=”cucumberjs-protractor-kickstart”]

Behat/Mink

[embedGitHubReadme owner=”jaffamonkey” repo=”behat-3-kickstart”]

Jasmine/Protractor

[embedGitHubReadme owner=”jaffamonkey” repo=”protractor-jasmine”]

CucumberJS/Protractor(Basic)

[embedGitHubReadme owner=”jaffamonkey” repo=”cucumberjs-protractor-basic”]

Behat with Docker

[embedGitHubReadme owner=”jaffamonkey” repo=”docker-behat-1″]

Waiting for elements to appear/disappear with cucumberjs/protractor

The cucumberjs/protractor combination can be awkward, testing angularjs, and using chai-as-promised helped, but reliability still can become an issue. So I started to lean towards more purist protractor code in these circumstances, to get round issue that waits are not always intelligent in cucumberjs and chai-as-promised didnt always provide solution (but is still great extension!). This following code has proved a reliable wait function.


this.Given(/^I wait for something to finish$/, function () {
var expected = protractor.ExpectedConditions;
var el = element(by.(''));
return browser.wait(expected.visibilityOf(el));
// Or to check if element is not there, return browser.wait(expected.not(expected.presenceOf(el)))
});

Example (will complete promise on step, once there is no instance of the element):


this.Given(/^I wait for login success screen$/, function () {
var expected = protractor.ExpectedConditions;
var el = element(by.model('emailId'));
return browser.wait(expected.not(EC.presenceOf(el)));
});

Example 2 (checking on button state, using element attribute)


this.Given(/^I wait to click a currently disabled button$/, function () {
        var expected = protractor.ExpectedConditions;
        var el= element(by.css('[aria-disabled="false"]'));
        return browser.wait(expected .visibilityOf(el));
});

What is happening here is that protractor is waiting for the element to not be present on page, before complete current step action. Note presenceOf condition, which may/may not work, depending on the element you are searching for. Sometimes elements are not visible (i.e. on the UI) but are still visible in source. So to check for UI visibility, use visibilityOf instead.

Running Cucumberjs/Protractor tests using Phantomjs on Windows

Using gitbash ( from gitSCM) or similar Windows BASH emulation software:

  • npm install webdriver-manager
  • download window binary and extract somewhere
  • rename phantomjs.exe to phantomjs and copy to \Users[user id]AppDataRoamingnpm

Change capabilities in conf file:

capabilities: {
browserName: 'phantomjs',
debug: true
}

webdriver-manager start

DISCLAIMER: I am not syaing this is the right way – this is the way I got the damn set-up to work on Windows 😉

Form filling using tables (Cucumber/AngularJS/Chai/Protractor)

Rather than pollute your Gherkin with “I fill in …” lines, you can create your own Gherkin and code, using table format. Many make mistaken assumption that Gherkin is somehow fixed format. Yes, the Regex trigger is the “Given”, “When”, “Then”, “And”. But Gherkin is supposed to be based on natural language, so as long as you observe some programming principles to creating new Gherkin, create your own. It’s encouraged as there is no way the out-of-the-box Gherkin provided by BDD products will completely accommodate your project requirements.
Continue reading