Skip to content

Instantly share code, notes, and snippets.

@sankargorthi
Created October 12, 2012 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sankargorthi/3881618 to your computer and use it in GitHub Desktop.
Save sankargorthi/3881618 to your computer and use it in GitHub Desktop.
The world gist
Feature: Mailing Wizard
In order to send a Mailing
As an Administrator
I need to be able to create a Mailing
Scenario: Check the first tab has fields
Given I am on the Mailing Wizard
When I am on the first tab
Then I should see a "Mailing Name" input
And I should see a "Description" input
And I should see a "Campaign" drop down
And I should see a "Planned Launch Date" input
And I should see a "Mailing Priority" drop down
And I should see a "Next" button
And halt the test
Scenario: Write an actual test case
Given I am on the Mailing Wizard
When I am on the first tab
And the following data is filled in
| SMA-MAILING-NAME | Cucumber Mailing | Text |
| SMA-MAILING-DESCRIPTION | A lengthy description for my mailing | Text |
| Campaign | c1 | Select |
| Planned Launch Date | Thursday Oct 18, 2012 | Date |
| Mailing Priority | Normal | Select |
And I click on the "SMA-MAILING-SAVE" button
Then I should not see a validation error
#And halt the test
var soda = require("soda"),
assert = require("assert"),
util = require("util");
var browser = soda.createClient({
host: 'localhost'
, port: 4444
, url: 'https://192.168.29.196/'
, browser: 'firefox'
});
browser.on('command', function(cmd, args){
console.log(' \x1b[33m%s\x1b[0m: %s', cmd, args.join(', '));
});
var myMailingWizardStepDefinitions = function() {
var world = this.World = require("../support/world.js").World;
function fillInText(name, value) {
return ".runScript(\"(function() {" +
"dojo.query('." + name + "').forEach(function(el) {" +
"dijit.getEnclosingWidget(el).set('value', '" + value + new Date().getTime() + "');" +
"});" +
"} ());\")";
//(function($) {
//$('.' + name.trim() + ' input').val(value.trim())
}
this.Given(/^I am on the Mailing Wizard$/, function(callback) {
browser
.chain
.session()
.getEval("window.resizeTo(1280, 1024); window.moveTo(0, 0);")
.open('/sm')
.waitForElementPresent('j_password')
.type('organization', 'admin')
.type('username', 'admin')
.type('j_password', 'admin')
.click("submit")
.waitForTextPresent("Home", 60)
.runScript("(function() {" +
"sm.app.mailing.StandardMailingMgr.createStandardMailing(true)" +
"}());")
.waitForTextPresent("Steps:")
.end(function(err){
if (err) callback.fail(err);
else callback();
});
});
this.When(/^I am on the first tab$/, function(callback) {
browser
.chain
.runScript("(function($){" +
"$('.wizardList .step:first').click();" +
"}(jQuery));")
.waitForTextPresent("Mailing Name")
.waitForElementPresent("widget_dijit_form_TextBox_0")
.waitForElementPresent("widget_dijit_form_TextBox_1")
.end(function(err){
if (err) callback.fail(err);
else callback();
});
});
this.Then(/^I should see a "([^"]*)" input$/, function(name, callback) {
browser
.chain
.waitForTextPresent(name, 60)
.end(function(err) {
if (err) callback.fail(err);
else callback();
});
});
this.Then(/^I should see a "([^"]*)" drop down$/, function(name, callback) {
// express the regexp above with the code you wish you had
browser
.chain
.waitForTextPresent(name, 60)
.end(function(err) {
if (err) callback.fail(err);
else callback();
});
});
this.Then(/^I should see a "([^"]*)" button$/, function(name, callback) {
browser
.chain
.waitForTextPresent("Next")
.click('css=.SMA-MAILING-NEXT span span')
//.runScript("(function($) { $('.SMA-MAILING-NEXT').click();}(jQuery)")
.waitForTextPresent("Mailing Recipient Count")
.end(function(err) {
//browser.testComplete(function(){
if (err) callback.fail(err);
else callback();
//});
});
});
this.Then(/^halt the test$/, function(callback) {
browser.testComplete(function() {callback()});
});
this.When(/^the following data is filled in$/, function(table, callback) {
var data = table.raw();
var commands = [];
for(var i = 0; i < data.length; i++) {
var el = data[i];
if (el[2] && el[2].trim() === "Text") {
commands.push(fillInText(el[0], el[1]));
}
}
// Must eval this as we can't loop through browser.chain calls.
// The browser calls are asynchronous and it would be too difficult to
// call the callback after determining if the last loop has successfully fired.
// Selenium will also fail if browser.* API calls are made while others are being
// executed
eval("browser.chain" + commands.join("") + ".end(function(err) { if (err) {callback.fail(err);} callback()})");
});
this.When(/^I click on the "([^"]*)" button$/, function(button, callback) {
browser
.chain
.waitForElementPresent("css=." + button + " span span", 10)
.click("css=." + button + " span span")
.end(function(err) {
if (err) callback.fail()
else callback()
});
});
this.Then(/^I should not see a validation error$/, function(callback) {
// express the regexp above with the code you wish you had
callback();
});
};
module.exports = myMailingWizardStepDefinitions;
var World = function World(callback) {
callback();
};
exports.World = World;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment