Skip to content

Tutorial Create a New Test

John edited this page Sep 10, 2015 · 4 revisions

#Scenario to be Automated

  • Open the AngularJS home page (https://angularjs.org)
  • Navigate to "The Basics" section
  • Enter "world" into the "Name:" text box where it says "Enter your name here"
  • Verify that the text below the text box includes the text "world" (it actually should say "Hello world!")

##Step 1 - Preparation and dependencies

##Step 2 - Create tests/AngularJSYourName.xlsx AngularJSYourName.xls.png

##Step 3 - Generate scripts and specifications in tests/AngularJSYourName/ Generate the .pro.js and .script.js files (run utilities/GenerateScriptnProJS.hta)

Excel2GenerateScriptnPro.png

##Step 4 - Update helpers/URLS.js Make sure that this line is in URLS.js:

dict.set('LIVE', 'https://angularjs.org/');

var Urls = (function () {
    function Urls() {}
    Urls.prototype.load = function (dict) {
        dict.set('SYSTEST', 'https://angularjs.org/');
        dict.set('LIVE', 'https://angularjs.org/');
        dict.set('UAT', 'https://angularjs.org/');
        dict.set('LOCAL', 'http://localhost');
        dict.set('LOCALHOST', 'http://localhost');
    };
    return Urls;
})();
module.exports = Urls;

##Step 5 - Add pages/AngularJSHomePage.js

var AngularJSHomePage = (function () {

    function AngularJSHomePage() {

        this.yourNameIn = element(by.model('yourName'));
        this.yourNameOut = element(by.binding('yourName'));
    }

    AngularJSHomePage.prototype.setYourName = function (Name) {
        this.yourNameIn.clear();
        this.yourNameIn.sendKeys(Name);
    };

    AngularJSHomePage.prototype.getYourName = function () {
        return this.yourNameOut.getText();
    };

    return AngularJSHomePage;

})();

module.exports = AngularJSHomePage;

##Step 6 - Add keywords/AngularJS.keywords.js

var key = require('keyword'); // keyword functionality
try { key(require('./AngularJS.private.keywords')); } catch(err) { console.log(err) }
try { key(require('./Just.private.keywords')); } catch(err) { }

var AngularJSKeywords = {
    "AngularJS.SetYourName":[
        "Just.GetValueFromParams", ["$1","name"],"=> $name",
        "AngularJSPrivate.SetYourName", ["$name"]
    ],

    "AngularJS.GetYourName":[
        "AngularJSPrivate.GetYourName", "=> $nameOut"
    ],

    "AngularJS.CheckYourName":[
        "Just.GetValueFromParams", ["$1","name"],"=> $nameIn",
        "AngularJSPrivate.GetYourName", "=> $nameOut",
        "AngularJSPrivate.CheckYourName", ["$nameIn", "$nameOut"], "=> $nameOut"
    ]
};

module.exports = AngularJSKeywords;

##Step 7 - Add keywords/AngularJS.private.keywords.js

var AngularJSHomePage = require("../pages/AngularJSHomePage");

var AngularJSPrivateKeywords = {

    "AngularJSPrivate.SetYourName": function(next, name) {
        var angularJSHomePage = new AngularJSHomePage();
        angularJSHomePage.setYourName(name);
        next();
    },

    "AngularJSPrivate.GetYourName": function(next) {
        var angularJSHomePage = new AngularJSHomePage();
        angularJSHomePage.getYourName().then(function (NameOut) {
            next(NameOut);
        });
    },

    "AngularJSPrivate.CheckYourName": function(next, nameIn, nameOut) {
        console.log("AngularJS.CheckYourName: " + nameOut + " contains " + nameIn);
        var angularJSHomePage = new AngularJSHomePage();
        expect(nameOut).toContain(nameIn);
        next();
    }
};

module.exports = AngularJSPrivateKeywords;

##Step 8 - Run webdriver Start a Bash command session by clicking on the Git Bash icon on the desktop GitBashDesktopIcon.png or on the Git Bash entry in the start menu to start a Git Bash command window session. Then enter webdriver-manager start at the $ prompt to start Selenium webdriver. (The very first time you do this you should run webdriver-manager update beforehand).

##Step 9 - Run the test Open another Git Bash session and change directory to the parent of the tests folder (../tests/) and run the following command.

protractor protractorConfig.js --params.testEnv=live --capabilities.browserName="chrome" --specs="tests\AngularJSYourName\*.pro.js"

Check the test run results (defaults to /temp/AutomatedTestResults/ but this can be changed in protractorConfig)

##Step 10 - Try this for parallel execution

protractor protractorConfig.js --params.testEnv=live --capabilities.browserName="chrome" --capabilities.shardTestFiles=true  --capabilities.maxInstances=99 --specs="tests\AngularJSYourName\*.pro.js"

Clone this wiki locally