Permalink
Browse files

Added debug mechanism so you can watch the screenshots as it places t…

…he order.
  • Loading branch information...
1 parent 4d518dd commit e3b4169d57622b4bf8bad4c1817a92416c11daa9 @travist committed Oct 9, 2014
Showing with 96 additions and 14 deletions.
  1. +96 −14 lib/makemeasandwich.js
View
@@ -50,24 +50,60 @@ var get = function(param, value, done) {
// Load the configuration from -o first, else default config if exists
config.argv().env();
-var configFileCLI = config.get('o');
-var configFileDefault;
-if(process.platform == 'win32'){
- configFileDefault = process.cwd().split(path.sep)[0] + path.sep + 'mmas' + path.sep + 'config.json';
-} else {
- configFileDefault = path.sep + 'etc' + path.sep + 'mmas' + path.sep + 'config.json';
+
+var configFile = config.get('o');
+if (configFile) {
+ config.file({file: configFile});
}
+else {
+ if(process.platform == 'win32'){
+ configFile = process.cwd().split(path.sep)[0] + path.sep + 'mmas' + path.sep + 'config.json';
+ } else {
+ configFile = path.sep + 'etc' + path.sep + 'mmas' + path.sep + 'config.json';
+ }
-if (configFileCLI) {
- config.file({file:configFileCLI});
-} else {
- fs.exists(configFileDefault, function(exists){
+ fs.exists(configFile, function(exists) {
if(exists){
- config.file({file:configFileDefault});
+ config.file({file:configFile});
}
});
}
+/**
+ * Method to capture and ensure the screenshots directory exists.
+ */
+var capture = function(fileName) {
+ // Return the async function.
+ return function(done) {
+
+ // The directory to store the screenshots.
+ var dir = __dirname + '/../screenshots';
+
+ // Check that the directory exists.
+ fs.exists(dir, function(exists) {
+ if (exists) {
+ $.capture(dir + '/' + fileName + '.png', done);
+ }
+ else {
+ fs.mkdir(dir, function(err) {
+ if (err) return done(err);
+ $.capture(dir + '/' + fileName + '.png', done);
+ });
+ }
+ });
+ }
+}
+
+/**
+ * A method to capture the debug name.
+ */
+var debugCapture = function(fileName) {
+ if (config.get('debug')) {
+ return capture(fileName);
+ }
+ return function(done) { done(); }
+};
+
// Start the prompt.
prompt.start();
@@ -209,11 +245,16 @@ var login = function(done) {
print('Logging in.'),
$.go(false, 'visit', 'https://online.jimmyjohns.com/#/login'),
$.go(false, 'waitForElement', '#email'),
+ debugCapture('login1'),
setInput('#email', 'email'),
+ debugCapture('login2'),
setInput('#loginPassword', {name: 'pass', hidden: true}),
+ debugCapture('login3'),
$('#loginButton').go(false, 'click'),
$.go(false, 'waitForElement', 'p.welcomeMsg'),
- print('Successfully logged in.')
+ debugCapture('login4'),
+ print('Successfully logged in.'),
+ sleep(3000)
], done);
};
@@ -226,19 +267,30 @@ var newDelivery = function(done) {
async.series([
print('Filling out delivery information.'),
$.go(false, 'visit', 'https://online.jimmyjohns.com/#/deliveryaddress'),
+ debugCapture('delivery1'),
$.go(false, 'waitForElement', '#companyInput'),
+ debugCapture('delivery2'),
setInput('#companyInput', 'company', true),
+ debugCapture('delivery3'),
setInput('#addressInput', 'address'),
+ debugCapture('delivery4'),
setInput('#aptNoInput', 'apt/suite', true),
+ debugCapture('delivery5'),
setInput('#cityInput', 'city'),
+ debugCapture('delivery6'),
selectVal('#stateSelect', 'state'),
+ debugCapture('delivery7'),
setInput('#zip', 'zip'),
+ debugCapture('delivery8'),
sleep(1000),
$('#verifyAddressBtn').go(false, 'click'),
$.go(false, 'waitForElement', '#confirmDeliveryAddressBtn'),
+ debugCapture('delivery9'),
sleep(1000),
$('#confirmDeliveryAddressBtn').go(false, 'click'),
+ debugCapture('delivery10'),
$.go(false, 'waitForElement', 'a.menuTab'),
+ debugCapture('delivery11'),
print('Sucessfully filled out delivery information.'),
], done);
};
@@ -298,21 +350,32 @@ var customizeOrder = function(done) {
print('Customizing order...'),
sleep(2000),
$.go(false, 'waitForElement', '#textInput'),
+ debugCapture('customize1'),
setInput('#textInput', 'who'),
+ debugCapture('customize2'),
selectVal('#select_2944', 'bread'),
+ debugCapture('customize3'),
$.go(false, 'waitForElement', 'span:contains("Cut in half")'),
+ debugCapture('customize4'),
function(done) {
if (config.get('cut')) {
$('#chk_3894').click(done);
}
},
+ debugCapture('customize5'),
selectVal('#select_3963', 'drink'),
+ debugCapture('customize6'),
selectVal('#select_3882', 'chips'),
+ debugCapture('customize7'),
selectVal('#select_3992', 'cookie'),
+ debugCapture('customize8'),
selectVal('#select_3943', 'pickle'),
+ debugCapture('customize9'),
selectIngredient('Tomato'),
+ debugCapture('customize10'),
$('*:contains("Add To Order")').go(false, 'click'),
$.go(false, 'waitForElement', '*:contains("Your Order For Delivery")'),
+ debugCapture('customize11'),
print('Done customizing order.'),
], done);
};
@@ -415,33 +478,52 @@ var checkout = function(done) {
async.series([
print('Checking out...'),
$.go(false, 'waitForElement', 'a#gotoCheckoutBtn'),
+ debugCapture('checkout1'),
$('a#gotoCheckoutBtn').go(false, 'click'),
$.go(false, 'waitForElement', '#selectPaymentType'),
+ debugCapture('checkout2'),
selectVal('#selectPaymentType', 'Credit Card', true),
$.go(false, 'waitForElement', 'div#cards'),
+ debugCapture('checkout3'),
selectCard,
+ debugCapture('checkout4'),
selectVal('#selectPaymentType', 'Credit Card', true),
+ debugCapture('checkout5'),
enterCardNumber,
+ debugCapture('checkout6'),
enterCardExpire,
+ debugCapture('checkout7'),
enterCardCode,
+ debugCapture('checkout8'),
enterCardName,
+ debugCapture('checkout9'),
setInput('#tipAmount', 'tip'),
+ debugCapture('checkout10'),
setInput('#billingAddress', 'billing_address'),
+ debugCapture('checkout11'),
setInput('#billingCity', 'billing_city'),
+ debugCapture('checkout12'),
selectVal('#stateSelect', 'billing_state'),
+ debugCapture('checkout13'),
setInput('#billingZip', 'billing_zip'),
+ debugCapture('checkout14'),
$('*:contains("Review Order")').go(false, 'click'),
$.go(false, 'waitForElement', '*:contains("Review & Place Order")'),
+ debugCapture('checkout15'),
setInput('#companyInput', 'company', true),
+ debugCapture('checkout16'),
setInput('#aptNoInput', 'apt/suite', true),
+ debugCapture('checkout17'),
setInput('#gateCode', 'gate_code', true),
+ debugCapture('checkout18'),
setInput('#deliveryInstructions', 'delivery_instructions', true),
sleep(1000),
+ debugCapture('checkout19'),
print('Placing order...'),
$('*:contains("Place Order")').go(false, 'click'),
$.go(false, 'waitForElement', '*:contains("Thank you for your order")'),
- $.go('capture', __dirname + '/complete.png'),
- print('Delivery on its way! Order details at ' + __dirname + '/complete.png')
+ capture('complete'),
+ print('Delivery on its way! Order details at ' + __dirname + '/../screenshots/complete.png')
], done);
};

0 comments on commit e3b4169

Please sign in to comment.