Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample Selenium script for load testing the XAF MainDemo. See http://blog.zerosharp.com/load-testing-xaf-part-2-selenium/ for more information.
// MainDemo_CycleThroughTabs.js
/*global test */
// Settings for Neustar:
// replace the following with the public address of the application server,
var targetHost = "http://zerosharp-maindemo.elasticbeanstalk.com/";
var virtualShare = "MainDemo.Web_deploy";
// Settings for debug webserver:
//var targetHost = "http://localtest.me:58404";
//var virtualShare = "";
// Settings for the build server or IIS:
//var targetHost = "http://localtest.me/";
//var virtualShare = "MainDemo.Web";
// Test parameters
var thinkTimeInSeconds = 3;
var timeout = 60000;
var step = 0;
// You an optionally set the simulated bandwidth for the script
// (max of 100KB/sec). A value of -1 means do not limit.
// E.g.,
// var bandwidthLimit = 50 * 1024 * 8; // 50KB/sec
var bandwidthLimit = -1;
var driver = test.openBrowser();
var selenium = driver.getSelenium();
// Support functions
function think() {
if (thinkTimeInSeconds > 0) {
if (!test.isValidation()) {
test.pause(thinkTimeInSeconds * 1000);
}
}
}
function waitForCallbacks() {
selenium.waitForCondition("(typeof selenium.browserbot.getUserWindow().xafHasPendingCallbacks === 'function') && (selenium.browserbot.getUserWindow().xafHasPendingCallbacks() === false);", timeout);
}
function stepLogin(username) {
step = step + 1;
test.beginStep("Step " + step.toString() + " - Login");
selenium.open(targetHost + virtualShare + "/Default.aspx");
think();
selenium.type("xpath=//input[contains(@id,'_xaf_dviUserName_Edit_I')]", username);
selenium.type("xpath=//input[contains(@id,'_xaf_dviPassword_Edit_I')]", "");
selenium.click("Logon_PopupActions_Menu_DXI0_T");
selenium.waitForPageToLoad(timeout);
waitForCallbacks();
selenium.assertElementPresent("Horizontal_VCC_VSL");
selenium.waitForText("Horizontal_VCC_VSL", "Contact");
test.endStep();
think();
}
function stepLogoff() {
var expectedSubstring;
step = step + 1;
test.beginStep("Step " + step.toString() + " - Logoff");
selenium.click("//li[@class='dxm-item']/div[@class='dxm-content dxm-hasText']//a[@class='dx dxalink' and text()='Log Off']/..");
selenium.waitForPageToLoad(timeout);
expectedSubstring = "Logout.html";
test.endStep();
}
function stepNavigateToTab(maintabCaption, tabCaption, viewCaption) {
// viewCaption is optional
viewCaption = (typeof viewCaption === "undefined") ? tabCaption : viewCaption;
step = step + 1;
test.beginStep("Step " + step.toString() + " - " + tabCaption);
selenium.waitForElementPresent("//td[@class='dxtc' and text()='" + maintabCaption + "']");
if (selenium.isVisible("//td[@class='dxtc' and text()='" + maintabCaption + "']")) {
selenium.click("//td[@class='dxtc' and text()='" + maintabCaption + "']");
}
selenium.waitForElementPresent("//div[@class='dxm-content dxm-hasText' and starts-with(@id, 'Horizontal_NTAC_PC_M')]//a[@class='dx dxalink' and contains(text(), '" + tabCaption + "')]/..");
selenium.click("//div[@class='dxm-content dxm-hasText' and starts-with(@id, 'Horizontal_NTAC_PC_M')]//a[@class='dx dxalink' and contains(text(), '" + tabCaption + "')]/..");
waitForCallbacks();
selenium.assertElementPresent("Horizontal_VCC_VSL");
selenium.assertText("Horizontal_VCC_VSL", viewCaption);
test.endStep();
think();
}
function initializetest() {
selenium.setTimeout(timeout);
if (bandwidthLimit > 0) {
test.setSimulatedBps(bandwidthLimit);
}
}
(function main() {
initializetest();
test.beginTransaction();
stepLogin("Sam");
//stepNavigateToTab("Default", "Contact");
stepNavigateToTab("Default", "Task");
stepNavigateToTab("Default", "Department");
stepNavigateToTab("Default", "Scheduler Event");
stepNavigateToTab("Default", "My Details", "User - Sam");
stepNavigateToTab("Default", "Note");
stepNavigateToTab("Default", "Payment");
stepNavigateToTab("Default", "Position");
stepNavigateToTab("Default", "Resume");
stepNavigateToTab("Default", "Role");
stepNavigateToTab("Default", "User");
stepNavigateToTab("Reports", "Analysis");
stepNavigateToTab("Reports", "Reports");
stepLogoff();
test.closeBrowser();
test.endTransaction();
}());
/*jslint
white: true,
onevar: true,
undef: true,
nomen: true,
regexp: true,
plusplus: true,
bitwise: true,
newcap: true,
maxerr: 50,
indent: 4
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment