You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 5, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+306-2Lines changed: 306 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,6 @@ nightwatch-commands
5
5
6
6
A set of Mobify specific custom commands for Nightwatch.js
7
7
8
-
Full Documentation: http://adaptivejs.mobify.com/v2.0/docs/custom-nightwatchjs-api/
9
-
10
8
### Download
11
9
To begin, clone this repository. `cd` into your chosen folder, and run the following:
12
10
`npm install`
@@ -15,3 +13,309 @@ To begin, clone this repository. `cd` into your chosen folder, and run the follo
15
13
JavaScript in this tool is linted with [ESLint](http://eslint.org/) according to our code [syntax and style standards](https://github.com/mobify/mobify-code-style) here at Mobify.
16
14
17
15
Linting may be run with the `grunt lint` command. Code is also linted automatically on [CircleCI](https://circleci.com/).
The `elementsVisible` assertion checks if one or more selectors are visible. It returns a list of one or more selectors that are not visible on the page.
55
+
56
+
Parameter Name | Parameter Type | Description
57
+
------------- | -------------- | -----------
58
+
selectors | String | The CSS/Xpath selector to locate the element.
59
+
callback | Function | _optional_ A function to call after the current command finishes execution.
The `templateName` assertion checks if the given template name is correct.
70
+
71
+
Parameter Name | Parameter Type | Description
72
+
------------- | -------------- | -----------
73
+
expected | String | The expected value of the attribute to check.
74
+
message | String | _optional_ A log message to display in the output. If the parameter is not specified, a default message is displayed.
75
+
callback | Function | _optional_ A function to call after the current command finishes execution.
76
+
77
+
```
78
+
this.demoTest = function (client) {
79
+
browser.assert.templateName('home');
80
+
};
81
+
```
82
+
83
+
## Commands
84
+
85
+
#### get(url, callback)
86
+
87
+
The `get` command combines the `url` and `waitUntilMobified` functions. This command uses the `browser.execute` function to run code within the client browser. It then waits for the `Mobify`or `Adaptive` object to be present on the page
88
+
89
+
Parameter Name | Parameter Type | Description
90
+
------------- | -------------- | -----------
91
+
url | String | The URL to load
92
+
callback | Function | _optional_ A function to call after the current command finishes execution.
93
+
94
+
```
95
+
this.demoTest = function (browser) {
96
+
browser.get('http://www.test.com');
97
+
};
98
+
```
99
+
100
+
#### getMobifyEvaluatedData(callback)
101
+
102
+
The `getMobifyEvaluatedData` command uses the `waitForCondition` method to retrieve the `Mobify.evaluatedData` from the client browser.
103
+
104
+
Input
105
+
106
+
Parameter Name | Parameter Type | Description
107
+
------------- | -------------- | -----------
108
+
callback | Function | _optional_ A function to call after the current command finishes execution.
109
+
110
+
Output
111
+
112
+
Parameter Name | Description
113
+
-------------- | -----------
114
+
Object | Returns the client object after `waitUntilMobified` executes on it with the specified parameters.
115
+
116
+
```
117
+
this.demoTest = function (browser) {
118
+
browser.getMobifyEvaluatedData();
119
+
};
120
+
```
121
+
122
+
#### htmlCapture(message, callback)
123
+
124
+
`htmlCapture` is a helper command that saves HTML to `tests/system/integration/fixtures`. This command was designed to collect and save HTML files for use in integration tests. This command is intended to be run using a Nightwatch environment with a desktop user agent, however, it can still be used to capture any HTML as required.
125
+
126
+
Parameter Name | Parameter Type | Description
127
+
------------- | -------------- | -----------
128
+
fileName | String | camelCased alphanumeric string ending with ".html", representing the name of the fixture
129
+
callback | Function | _optional_ A function to call after the current command finishes execution.
130
+
131
+
```
132
+
this.demoTest = function (browser) {
133
+
browser.htmlCapture('cart.html');
134
+
};
135
+
```
136
+
137
+
#### log(message, callback)
138
+
139
+
The `log` command prints a message to the console. Use this command to output messages in a test.
140
+
141
+
Parameter Name | Parameter Type | Description
142
+
------------- | -------------- | -----------
143
+
message | String | The message to log on the console.
144
+
callback | Function | _optional_ A function to call after the current command finishes execution.
145
+
146
+
```
147
+
this.demoTest = function (browser) {
148
+
browser.log('Testing submitting form');
149
+
};
150
+
```
151
+
152
+
#### navigate(selector, callback)
153
+
154
+
The `navigate` command initiates a `click` command on the supplied selector link, navigates to the URL, and then it initiates the `waitUntilMobified` function before it continues the chain of tests.
155
+
156
+
Parameter Name | Parameter Type | Description
157
+
------------- | -------------- | -----------
158
+
selector | String | The CSS selector to click on to navigate to the new URL.
159
+
callback | Function | _optional_ A function to call after the current command finishes execution.
160
+
161
+
```
162
+
this.demoTest = function (browser) {
163
+
browser.navigate('.myLink');
164
+
};
165
+
```
166
+
167
+
#### preview(url, callback)
168
+
169
+
The `preview` command uses http://preview.mobify.com to open a website to preview a given bundle. The bundle and the base URL need to be set in the `tests/system/site.json` file. Note that if the "production" flag is set in `site.json`, the bundle URL will be ignored. Pass in an optional URL as an argument to this command. Upon completion, `waitUntilMobified` is called to ensure that the mobile site adaptation is complete.
170
+
171
+
If the project does not have a `tests/system/site.json` file, this command is equivalent to the `url` protocol command.
172
+
173
+
Parameter Name | Parameter Type | Description
174
+
------------- | -------------- | -----------
175
+
url | String | _optional_ The URL to preview.
176
+
callback | Function | _optional_ A function to call after the current command finishes execution.
177
+
178
+
```
179
+
this.demoTest = function (browser) {
180
+
browser.preview();
181
+
};
182
+
183
+
this.demoTest = function (browser) {
184
+
browser.preview('http://my-awesome-project.com');
185
+
};
186
+
```
187
+
188
+
#### trigger(selector, type, callback)
189
+
190
+
The `trigger` command simulates a specified event type on the supplied DOM element specified by the selector parameter.
191
+
192
+
Parameter Name | Parameter Type | Description
193
+
------------- | -------------- | -----------
194
+
selector | String | The CSS/Xpath selector to locate the element.
195
+
type | String | The specified event type, for example `click` in the enabled JSON Wire Protocols.
196
+
callback | Function | _optional_ A function to call after the current command finishes execution.
197
+
198
+
```
199
+
this.demoTest = function (browser) {
200
+
browser.trigger('.myLink', click);
201
+
};
202
+
```
203
+
204
+
#### triggerTouch(selector, type, callback)
205
+
206
+
The `triggerTouch` command simulates a specified touch type event on the supplied DOM element. Use this command when Selenium's `click` does not register.
207
+
208
+
Parameter Name | Parameter Type | Description
209
+
------------- | -------------- | -----------
210
+
selector | String | The CSS/Xpath selector to locate the element.
211
+
type | String | The specified event type, for example `click` in the enabled JSON Wire Protocols.
212
+
callback | Function | _optional_ A function to call after the current command finishes execution.
213
+
214
+
```
215
+
this.demoTest = function (browser) {
216
+
browser.triggerTouch('.myLink', click);
217
+
};
218
+
```
219
+
220
+
#### waitForAjaxCompleted(callback)
221
+
222
+
The `waitForAjaxCompleted` command uses the `waitForCondition` function to execute code within the client browser. The command checks the value of `jQuery.active` to ensure that the number of active connections is 0.
223
+
224
+
Parameter Name | Parameter Type | Description
225
+
------------- | -------------- | -----------
226
+
callback | Function | _optional_ A function to call after the current command finishes execution.
227
+
228
+
```
229
+
this.demoTest = function (browser) {
230
+
browser.waitForAjaxCompleted();
231
+
};
232
+
```
233
+
234
+
#### waitForAnimation(milliSeconds, callback)
235
+
236
+
The `waitForAnimation` command suspends the test for the given time in milliseconds while it waits for animation to complete.
237
+
238
+
Parameter Name | Parameter Type | Description
239
+
------------- | -------------- | -----------
240
+
milliSeconds | Number | The number of millliseconds to wait.
241
+
callback | Function | _optional_ A function to call after the current command finishes execution.
The `waitForCondition` command receives a condition to check for, waits for a maximum time before timing out, and polls at a specified time interval. The condition returns either as a success or a timeout.
252
+
253
+
Parameter Name | Parameter Type | Description
254
+
------------- | -------------- | -----------
255
+
condition | Function | The condition to check against.
256
+
milliSeconds | Number | _optional_ The number of milliseconds to poll before timeout.
257
+
timeout | Number | _optional_ The number of milliseconds between each poll.
258
+
message | String | _optional_ The message to output.
259
+
callback | Function | _optional_ A function to call after the current command finishes execution.
The `waitForUrlToContain` command waits until the page URL contains the specified `url`.
292
+
293
+
Parameter Name | Parameter Type | Description
294
+
------------- | -------------- | -----------
295
+
url | String | A partial URL to match against.
296
+
milliSeconds | Number | _optional_ The number of milliseconds to poll before timeout.
297
+
timeout | Number | _optional_ The number of milliseconds between each poll.
298
+
message | String | _optional_ The message to output.
299
+
callback | Function | _optional_ A function to call after the current command finishes execution.
300
+
301
+
```
302
+
this.demoTest = function (browser) {
303
+
browser.waitForUrlToContain('google');
304
+
};
305
+
```
306
+
307
+
#### waitUntilMobified(milliSeconds, callback)
308
+
309
+
The `waitUntilMobified` command will use the `waitForCondition` command to poll for the Mobify or Adaptive object on the page to ensure that the adaptation is complete. Use this command to browse to a page or if the page reloads.
310
+
311
+
Parameter Name | Parameter Type | Description
312
+
------------- | -------------- | -----------
313
+
milliSeconds | Number | _optional_ The number of milliseconds to poll before timeout.
314
+
If not specified, the default timeout is 10,000 milliseconds.
315
+
callback | Function | _optional_ A function to call after the current command finishes execution.
0 commit comments