|
1 | 1 | /** |
2 | 2 | * Preview will use preview.mobify.com to open a website and allow you to preview |
3 | | - * a given bundle. The bundle and base URL will need to be set in the the |
4 | | - * `tests/system/site.json` file. Additionally, you can pass a URL as an |
5 | | - * argument when you call preview(). Upon completion, waitUntilMobified |
6 | | - * is called, to be sure that the adaptation is complete. |
| 3 | + * a given bundle. The site URL and bundle URL should be passed in. Upon completion, waitUntilMobified is called, to be sure that the |
| 4 | + * adaptation is complete. |
7 | 5 | * |
8 | | - * If `site.json` does not exist, this command will just go to the specified URL. |
9 | | - * |
10 | | - * ``` |
11 | | - * this.demoTest = function (client) { |
12 | | - * browser.preview(); |
13 | | - * }; |
14 | | - * ``` |
15 | | - * or with a URL |
16 | | - * |
| 6 | + * Usage: |
17 | 7 | * ``` |
18 | 8 | * this.demoTest = function (client) { |
19 | | - * browser.preview('http://my-awesome-project.com'); |
| 9 | + * browser.preview('https://www.merlinspotions.com', 'https://localhost:8443/loader.js'); |
20 | 10 | * }; |
21 | 11 | * ``` |
22 | 12 | * |
23 | | - * @method attributeEquals |
24 | | - * @param {string} [URL] (optional) The URL to be previewed. |
25 | | - * @param {function} callback The function to be called on completion. |
26 | | - * @api assertions |
| 13 | + * @method preview |
| 14 | + * @param {string} [url] Corresponds to the Site URL field on https://preview.mobify.com |
| 15 | + * @param {string} [bundle] Corresponds to the Bundle Location field on https://preview.mobify.com |
| 16 | + * @param {function} [callback] Optional callback function to be called when the command finishes. |
| 17 | + * @api commands |
27 | 18 | */ |
28 | 19 |
|
29 | | -var path = require('path'); |
30 | 20 | var qs = require('querystring'); |
31 | 21 |
|
32 | | -exports.command = function(url, callback) { |
| 22 | +exports.command = function(url, bundle, callback) { |
33 | 23 | var browser = this; |
34 | 24 |
|
35 | | - try { |
36 | | - var siteConfig = require(path.join(path.resolve('./'), '/tests/system/site.json')); |
37 | | - } catch (e) { |
38 | | - if (e instanceof Error && e.code === 'MODULE_NOT_FOUND') { |
39 | | - console.log('Not using optional site.json. Looking for site.js...'); |
40 | | - } |
41 | | - } |
42 | | - |
43 | | - try { |
44 | | - var siteConfig = require(path.join(path.resolve('./'), '/tests/system/site.js')); |
45 | | - } catch (e) { |
46 | | - if (e instanceof Error && e.code === 'MODULE_NOT_FOUND') { |
47 | | - console.log('Not using optional /tests/system/site.js.'); |
48 | | - } |
| 25 | + if (arguments.length < 2) { |
| 26 | + throw new Error('Usage: browser.preview(url, bundle, callback)'); |
49 | 27 | } |
50 | 28 |
|
51 | | - try { |
52 | | - var siteConfig = require(path.join(path.resolve('./'), '/system/site.js')); |
53 | | - } catch (e) { |
54 | | - if (e instanceof Error && e.code === 'MODULE_NOT_FOUND') { |
55 | | - console.log('Not using optional /system/site.js.'); |
56 | | - } |
| 29 | + if (typeof bundle === 'function') { |
| 30 | + callback = bundle; |
| 31 | + bundle = null; |
57 | 32 | } |
58 | 33 |
|
59 | | - if (siteConfig) { |
60 | | - var site = siteConfig.profiles[siteConfig.activeProfile]; |
| 34 | + var bundleUrl = bundle || 'https://localhost:8443/loader.js'; |
61 | 35 |
|
62 | | - if (typeof url === 'function') { |
63 | | - callback = url; |
64 | | - url = site.siteUrl; |
65 | | - } |
| 36 | + var params = qs.stringify({'url': url, 'site_folder': bundleUrl}); |
66 | 37 |
|
67 | | - // First checks for the URL, otherwise uses the site.siteURL, then makes sure |
68 | | - // that there is an http prefix. The preview function doesn't need this, but |
69 | | - // the browser.get() method does. |
70 | | - url = url || site.siteUrl; |
71 | | - |
72 | | - if (!url.match(/^http/)) { |
73 | | - throw new Error('Site URL must be correctly formatted'); |
74 | | - } |
75 | | - |
76 | | - // If the production flag is set, just runs a `get()` on the URL. |
77 | | - if (site.production) { |
78 | | - return browser.get(url, function(result) { |
79 | | - if (typeof callback === 'function') { |
80 | | - callback.call(browser, result); |
81 | | - } |
82 | | - }); |
83 | | - } |
84 | | - |
85 | | - var bundleUrl = site.bundleUrl || 'https://localhost:8443/adaptive.js'; |
86 | | - |
87 | | - var params = qs.stringify({'url': url, 'site_folder': bundleUrl}); |
88 | | - |
89 | | - return browser.url('https://preview.mobify.com?' + params) |
90 | | - .waitForElementPresent('#authorize', 10000, function() { |
91 | | - this.click('#authorize', function() { |
92 | | - browser.waitUntilMobified(10000, function(result) { |
93 | | - if (typeof callback === 'function') { |
94 | | - callback.call(browser, result); |
95 | | - } |
96 | | - }); |
| 38 | + return browser.url('https://preview.mobify.com?' + params) |
| 39 | + .waitForElementPresent('#authorize', 10000, function() { |
| 40 | + this.click('#authorize', function() { |
| 41 | + browser.waitUntilMobified(10000, function(result) { |
| 42 | + if (typeof callback === 'function') { |
| 43 | + callback.call(browser, result); |
| 44 | + } |
97 | 45 | }); |
98 | 46 | }); |
99 | | - } else { |
100 | | - return browser.url(url, function(result) { |
101 | | - if (typeof callback === 'function') { |
102 | | - callback.call(browser, result); |
103 | | - } |
104 | 47 | }); |
105 | | - } |
106 | 48 | }; |
0 commit comments