Skip to content

Instantly share code, notes, and snippets.

@nottoseethesun
Created October 7, 2013 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nottoseethesun/6875609 to your computer and use it in GitHub Desktop.
Save nottoseethesun/6875609 to your computer and use it in GitHub Desktop.
[
{
"settings": [ "master" ],
"name" : "page-load",
"startProxyServer" : true,
"commonlib" : "./test-lib.js",
"config" :{
"baseUrl" : "https://uat.corp.bar.com"
},
"dataprovider" : {
"int" : {
"params" : {
"scenario": [
{
"page" : "$$config.baseUrl$$/foo"
},
{
"controller": "locator",
"params": {
"value": "#accountname",
"text": "foo_bar"
}
},
{
"controller": "locator",
"params": {
"value": "#accountpassword",
"text": "BarBat"
}
},
{
"controller" : "test-foo-load-controller",
"params": {
"test" : "./test-page-load-int.js",
"maxLoadTimeMS": 1000,
"loggerService": "17.198.70.192:3009/log-it.txt",
"deliveryMode": "uat"
}
}
]
},
"group" : "smoke"
}
}
},
{
"settings": [ "environment:development" ]
}
]
var util = require("util")
, log4js = require("yahoo-arrow").log4js
, Controller = require("yahoo-arrow").controller;
function PageLoadController(testConfig,args,driver) {
Controller.call(this, testConfig,args,driver);
this.logger = log4js.getLogger("PageLoadController");
}
util.inherits(PageLoadController, Controller);
PageLoadController.prototype.execute = function(callback) {
var that = this;
if(this.driver.webdriver){
var webdriver = this.driver.webdriver;
webdriver.findElement(webdriver.By.css( '#submitButton2' )).click();
this.testParams.start = (new Date()).getTime();
// @to-do: Refactor by leveraging the 'Promise' object better.
webdriver.waitForElementPresent(webdriver.By.css( '#fooBar .units' )).then( function() {
webdriver.findElement(webdriver.By.css( '#fooBar .units' )).click().then( function() {
webdriver.waitForElementPresent(webdriver.By.css( '.table .title' )).then( function() {
that.testParams.end = (new Date()).getTime();
that.driver.executeTest(that.testConfig, that.testParams, function(error, report) {
callback();
});
});
});
});
} else {
this.logger.fatal("Custom Controllers are currently only supported on Selenium Browsers");
callback("Custom Controllers are currently only supported on Selenium Browsers");
}
}
module.exports = PageLoadController;
/*
* Copyright (c) 2012, Yahoo! Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
/*
* The purpose of this class is to abstract the various tests you'd have on a typical web app page.
* There are several methods and each of them are abstracted in such a way as to
* not assume how the module was implemented.
*/
YUI.add("arrow-test-util", function(Y) {
var A = Y.Assert,
L = Y.Lang,
byCss;
Y.namespace("Arrow.Test.Foo").Util = {
exists: function( node ) {
A.isNotNull( node, 'Node is present: ' + node );
},
//Confirms the tabs are present
validateStructure: function(node, tabs, mods) {
for(tab in tabs) {
var tabNode = node.one(tabs[tab]);
A.isNotNull(tabNode, "tab is present: " + tabs[tab]);
}
//Confirms the first module displays correctly, with the associated content below it
for(mod in mods) {
var modNode = node.one(mods[mod]);
A.isNotNull(modNode, "module is present: " + mods[mod]);
if(0 == mod) {
A.areNotEqual(modNode.getStyle("display"), "none", "module should be displayed: " + mods[mod]);
} else {
A.areEqual(modNode.getStyle("display"), "none", "module should not be displayed: " + mods[mod]);
}
}
},
//Confirms each tab is represented as a link
validatePresence: function(node, tabNames) {
for(i in tabNames) {
var tabName = tabNames[i];
var link = node.oneLink(tabName);
A.isNotNull(link, "Tab must exist: " + tabName);
}
},
//Clicks through the tabs and makes sure they are displayed correctly
validateSelection: function(node, tabName, modName) {
var tabNode = node.one(tabName);
var modNode = node.one(modName);
A.areEqual(modNode.getStyle("display"), "none", "module should not be displayed: " + modName);
A.isNotNull(tabNode, "tab is present: " + tabName);
tabNode.simulate("click");
A.areNotEqual(modNode.getStyle("display"), "none", "module should be displayed: " + modName);
},
/**
* Defaults to a known working username/password.
*/
authToBarConnect: function( username, password ) {
var userNameBox = "#accountname",
passwBox = '#accountpassword',
sbmtBtn = '#submitButton2';
Y.one(userNameBox).setAttribute('value', username ? username : 'foo_bar');
Y.one(passwBox).setAttribute('value', password ? password : 'BarBat');
Y.one(sbmtBtn).simulate('click');
}
};
var Node = function() {};
Node.prototype.oneLink = function(linkText, tagName) {
if(!tagName) tagName = "a";
var useRegex = !L.isString(linkText);
var links = this.getElementsByTagName(tagName);
for(var i = 0; i < links.size(); i++) {
var link = links.item(i);
if(useRegex) {
if(linkText.test(link.get("text"))) {
return link;
}
} else if(linkText == link.get("text")) {
return link;
}
}
return null;
};
Y.augment(Y.Node, Node);
}, "0.1", { requires:["event", "node", "node-event-simulate", "test"]});
/*
* Copyright (c) 2012, Yahoo! Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
/*
* Like test_func.js, this is just another test as far as arrow is concerned
* The difference here is the expected values of test.
* It delegates actual testing to test-lib.js, which performs the actual assertions
*/
YUI.add("foo-test-int-tests", function (Y) {
var tl, suite;
// Get access to test-lib.js
tl = Y.Arrow.Test.Foo.Util;
// Create a test suite
suite = new Y.Test.Suite("Foo Integration Test Suite");
/*
* Add a new test, with one validation to the suite
* We are going to use the "validatePresence" method to check for specific values
* Note, the values we are passing are relevant to our "integration" page (tabview.html)
*/
suite.add(new Y.Test.Case({
"check loaded and load time": function() {
var params = this.testParams,
loadTime = params.end - params.start,
loadTimeSecs = loadTime / 1000,
tab = Y.one( '#fooBar .units .value' ),
tabValue = tab ? parseInt( tab.getHTML(), 10 ) : NaN,
imgGetter = new Image();
// log this to a service; @to-do: Move this to the controller (will require pinging from node).
imgGetter.src = 'http://' + params.loggerService + '?dir=foo-heartbeat&file=page-load-' + params.deliveryMode + '.txt&data=' + loadTimeSecs;
Y.assert( tabValue > 0, 'The tab data isn\'t loaded.' );
Y.assert( loadTime < params.maxLoadTimeMS, "The page should load in less than one second. " );
}
}));
//Never "run" the tests, simply add them to the suite. Arrow takes care of running them
Y.Test.Runner.add(suite);
}, "0.1", {requires:[ "test", "arrow-test-util", "node" ]});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment