This repository has been archived by the owner on Aug 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from mobify/explicit-preview
Explicit preview
- Loading branch information
Showing
4 changed files
with
33 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,48 @@ | ||
/** | ||
* 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/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. | ||
* a given bundle. The site URL and bundle URL should be passed in. 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) { | ||
* browser.preview(); | ||
* }; | ||
* ``` | ||
* or with a URL | ||
* | ||
* Usage: | ||
* ``` | ||
* this.demoTest = function (client) { | ||
* browser.preview('http://my-awesome-project.com'); | ||
* browser.preview('https://www.merlinspotions.com', 'https://localhost:8443/loader.js'); | ||
* }; | ||
* ``` | ||
* | ||
* @method attributeEquals | ||
* @param {string} [URL] (optional) The URL to be previewed. | ||
* @param {function} callback The function to be called on completion. | ||
* @api assertions | ||
* @method preview | ||
* @param {string} [url] Corresponds to the Site URL field on https://preview.mobify.com | ||
* @param {string} [bundle] Corresponds to the Bundle Location field on https://preview.mobify.com | ||
* @param {function} [callback] Optional callback function to be called when the command finishes. | ||
* @api commands | ||
*/ | ||
|
||
var path = require('path'); | ||
var qs = require('querystring'); | ||
|
||
exports.command = function(url, callback) { | ||
exports.command = function(url, bundle, callback) { | ||
var browser = this; | ||
|
||
try { | ||
var siteConfig = 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. Looking for site.js...'); | ||
} | ||
} | ||
|
||
try { | ||
var siteConfig = require(path.join(path.resolve('./'), '/tests/system/site.js')); | ||
} catch (e) { | ||
if (e instanceof Error && e.code === 'MODULE_NOT_FOUND') { | ||
console.log('Not using optional /tests/system/site.js.'); | ||
} | ||
if (arguments.length < 2) { | ||
throw new Error('Usage: browser.preview(url, bundle, callback)'); | ||
} | ||
|
||
try { | ||
var siteConfig = require(path.join(path.resolve('./'), '/system/site.js')); | ||
} catch (e) { | ||
if (e instanceof Error && e.code === 'MODULE_NOT_FOUND') { | ||
console.log('Not using optional /system/site.js.'); | ||
} | ||
if (typeof bundle === 'function') { | ||
callback = bundle; | ||
bundle = null; | ||
} | ||
|
||
if (siteConfig) { | ||
var site = siteConfig.profiles[siteConfig.activeProfile]; | ||
var bundleUrl = bundle || 'https://localhost:8443/loader.js'; | ||
|
||
if (typeof url === 'function') { | ||
callback = url; | ||
url = site.siteUrl; | ||
} | ||
var params = qs.stringify({'url': url, 'site_folder': bundleUrl}); | ||
|
||
// 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 (!url.match(/^http/)) { | ||
throw new Error('Site URL must be correctly formatted'); | ||
} | ||
|
||
// 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 bundleUrl = site.bundleUrl || 'https://localhost:8443/adaptive.js'; | ||
|
||
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); | ||
} | ||
}); | ||
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); | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters