diff --git a/commands/preview.js b/commands/preview.js index 4e1f103..634a127 100644 --- a/commands/preview.js +++ b/commands/preview.js @@ -1,9 +1,11 @@ /** * Preview will use preview.mobify.com to open a website and allow you to preview * a given bundle. The bundle and base URL will need to be set in the the - * `tests/integration/site.json` file. Additionally, you can pass a URL as an + * `tests/system/site.json` file. Additionally, you can pass a URL as an * argument when you call preview(). Upon completion, waitUntilMobified * is called, to be sure that the adaptation is complete. +* + * If `site.json` does not exist, this command will just go to the specified URL. * * ``` * this.demoTest = function (client) { @@ -24,52 +26,65 @@ * @api assertions */ - var path = require('path'); -var site = require(path.join(path.resolve('./'), '/tests/system/site.json')); -var qs = require('querystring'); -site = site.profiles[site.activeProfile]; +try { + var site = require(path.join(path.resolve('./'), '/tests/system/site.json')); +} catch (e) { + if (e instanceof Error && e.code === 'MODULE_NOT_FOUND') { + console.log('Not using optional site.json...'); + } +} +var qs = require('querystring'); exports.command = function(url, callback) { var browser = this; - if (typeof url === 'function') { - callback = url; - url = site.siteUrl; - } + if (site) { + site = site.profiles[site.activeProfile]; - // First checks for the URL, otherwise uses the site.siteURL, then makes sure - // that there is an http prefix. The preveiw function doesn't need this, but - // the browser.get() method does. - url = url || site.siteUrl; + if (typeof url === 'function') { + callback = url; + url = site.siteUrl; + } - if (!url.match(/^http/)) { - throw new Error('Site URL must be correctly formatted'); - } + // First checks for the URL, otherwise uses the site.siteURL, then makes sure + // that there is an http prefix. The preview function doesn't need this, but + // the browser.get() method does. + url = url || site.siteUrl; - // If the production flag is set, just runs a `get()` on the URL. - if (site.production) { - return browser.get(url, function(result) { - if (typeof callback === 'function') { - callback.call(browser, result); - } - }); - } + if (!url.match(/^http/)) { + throw new Error('Site URL must be correctly formatted'); + } - var bundleUrl = site.bundleUrl || 'http://localhost:8080'; + // If the production flag is set, just runs a `get()` on the URL. + if (site.production) { + return browser.get(url, function(result) { + if (typeof callback === 'function') { + callback.call(browser, result); + } + }); + } - var params = qs.stringify({'url': url, 'site_folder': bundleUrl}); + var bundleUrl = site.bundleUrl || 'https://localhost:8443/adaptive.js'; - return browser.url('https://preview.mobify.com?' + params) - .waitForElementPresent('#authorize', 10000, function() { - this.click('#authorize', function() { - browser.waitUntilMobified(10000, function(result) { - if (typeof callback === 'function') { - callback.call(browser, result); - } + var params = qs.stringify({'url': url, 'site_folder': bundleUrl}); + + return browser.url('https://preview.mobify.com?' + params) + .waitForElementPresent('#authorize', 10000, function() { + this.click('#authorize', function() { + browser.waitUntilMobified(10000, function(result) { + if (typeof callback === 'function') { + callback.call(browser, result); + } + }); }); }); + } else { + return browser.url(url, function(result) { + if (typeof callback === 'function') { + callback.call(browser, result); + } }); - -}; + } +}; \ No newline at end of file diff --git a/package.json b/package.json index 42c7c40..61539ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nightwatch-commands", - "version": "1.3.0", + "version": "1.3.1", "description": "A set of Mobify specific custom commands for Nightwatch.js", "repository": { "type": "git",