In order to test my application using protractor, I created a scenario. The application begins with a non-angular login page and then progresses to an angular page after logging in.
Here is the javascript code snippet that was utilized:
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var expect = chai.expect;
var myStepDefinitionsWrapper = function () {
this.Given(/^that I login with valid user credentials$/, function (callback) {
console.log("I'm in before URL");
browser.driver.get('http://localhost:8000/#');
console.log("I'm in after URL");
browser.driver.wait(function() {
console.log("I'm in Wait");
return browser.driver.isElementPresent(by.xpath("//input[contains(@placeholder,'Username')]"));
},10000);
browser.driver.findElement(by.xpath("//input[contains(@placeholder,'Username')]")).then(function(username) {
console.log("I'm in Username");
username.sendKeys("welby");
});
browser.driver.findElement(by.xpath("//input[contains(@type,'password')]")).then(function(password) {
console.log("I'm in Password");
password.sendKeys("asdf");
});
browser.driver.findElement(by.xpath("//button[@type='submit']")).click();
console.log("I'm after click");
callback();
});
this.When(/^I click perform button in Tasks window$/, function (callback) {
browser.waitForAngular();
element(by.xpath("//*[text()[contains(.,'Smith, Sally')]]/following::td[2]/button[text()='Perform']")).click();
console.log("Clicked Perform");
callback();
});
}
Output:
"C:\Program Files (x86)\JetBrains\WebStorm 10.0.4\bin\runnerw.exe" "C:\Program Files (x86)\nodejs\node.exe" node_modules\protractor\lib\cli.js E2E\protractor-conf.js Using the selenium server at http://127.0.0.1:4444/wd/hub [launcher] Running 1 instances of WebDriver
- I'm in before URL
- I'm in after URL
- I'm after click
- Clicked Perform
1 scenario (1 passed) 3 steps (3 passed)
[launcher] 0 instance(s) of WebDriver still running [launcher] chrome #1 passed
Process finished with exit code 0