Skip to content
This repository was archived by the owner on Aug 5, 2020. It is now read-only.

Commit 0f46312

Browse files
committed
Merge pull request #50 from mobify/update-readme
Update readme
2 parents 17df279 + cf33ab7 commit 0f46312

File tree

5 files changed

+361
-2
lines changed

5 files changed

+361
-2
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
charset = utf-8
9+
indent_style = space
10+
indent_size = 4
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.github/CONTRIBUTING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Contributing to nightwatch-commands
2+
3+
## Bugs, Feature Requests
4+
Submit an [issue](https://github.com/mobify/nightwatch-commands/issues).
5+
6+
## Pull Requests
7+
8+
1. Make a new branch from `develop`.
9+
1. Please ensure that you have [EditorConfig](http://editorconfig.org/) installed to ensure code consistency.
10+
1. Do your work.
11+
1. Update the README.
12+
1. Run `grunt lint` and fix any issues.
13+
1. Open a PR against `develop`.

.github/ISSUE_TEMPLATE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### Summary
2+
3+
### Expected behaviour
4+
5+
### Actual behaviour
6+
7+
### Steps to reproduce

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Status: **Ready for Review** or **Open for Visibility**
2+
Owner:
3+
Reviewers: @ellenmobify @marlowpayne @mobify-derrick
4+
5+
## Changes
6+
- (change1)
7+
- (change2)
8+
9+
## Todos:
10+
- [] Passed linting check (run `grunt lint`)
11+
- [] Updated README
12+
- [] Updated CHANGELOG
13+
14+
### Feedback:
15+
_none so far_
16+
17+
## How To Test
18+
- Checkout this branch
19+
- `npm install`
20+
- `npm link`
21+
- `grunt lint`
22+
- (notes)

README.md

Lines changed: 306 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ nightwatch-commands
55

66
A set of Mobify specific custom commands for Nightwatch.js
77

8-
Full Documentation: http://adaptivejs.mobify.com/v2.0/docs/custom-nightwatchjs-api/
9-
108
### Download
119
To begin, clone this repository. `cd` into your chosen folder, and run the following:
1210
`npm install`
@@ -15,3 +13,309 @@ To begin, clone this repository. `cd` into your chosen folder, and run the follo
1513
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.
1614

1715
Linting may be run with the `grunt lint` command. Code is also linted automatically on [CircleCI](https://circleci.com/).
16+
17+
## Assertions
18+
19+
#### elementsCount(selector, expected, message, callback)
20+
21+
The `elementsCount` assertion checks if the given selector is present the number of times that is expected for that selector to appear.
22+
23+
Parameter Name | Parameter Type | Description
24+
------------- | -------------- | -----------
25+
selector | String | The CSS/Xpath selector to locate the element.
26+
expected | Number | The expected number of times for the attribute to appear.
27+
message | String | _optional_ The message to output.
28+
callback | Function | _optional_ A function to call after the current command finishes execution.
29+
30+
```
31+
this.demoTest = function (browser) {
32+
browser.assert.elementsCount('#x-root', 1);
33+
}
34+
```
35+
36+
#### elementsPresent(selector, message, callback)
37+
38+
The `elementsPresent` assertion checks if the given selectors are present. It returns a list of the missing selectors.
39+
40+
Parameter Name | Parameter Type | Description
41+
------------- | -------------- | -----------
42+
selector | String | The CSS/Xpath selector to locate the element.
43+
message | String | _optional_ The message to output.
44+
callback | Function | _optional_ A function to call after the current command finishes execution.
45+
46+
```
47+
this.demoTest = function (browser) {
48+
browser.assert.elementsPresent('#x-root', '#x-header', '#x-footer');
49+
};
50+
```
51+
52+
#### elementsVisible(selector, message, callback)
53+
54+
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.
60+
61+
```
62+
this.demoTest = function (browser) {
63+
browser.assert.elementsVisible('#x-root', '#x-head');
64+
};
65+
```
66+
67+
#### templateName(expected, message, callback)
68+
69+
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.
242+
243+
```
244+
this.demoTest = function (browser) {
245+
browser.waitForAnimation();
246+
};
247+
```
248+
249+
#### waitForCondition(condition, milliSeconds, timeout, message, callback)
250+
251+
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.
260+
261+
```
262+
this.demoTest = function (browser) {
263+
return browser.waitForCondition('return $.active;', 8000, function(result) {
264+
if (typeof callback === 'function') {
265+
callback.call(browser, result);
266+
}
267+
});
268+
};
269+
```
270+
271+
#### waitForUrl(url, milliseconds, timeout, messages, callback)
272+
273+
The `waitForUrl` command waits until the page URL is equal to the specified `url`.
274+
275+
Parameter Name | Parameter Type | Description
276+
------------- | -------------- | -----------
277+
url | String | Expected URL
278+
milliSeconds | Number | _optional_ The number of milliseconds to poll before timeout.
279+
timeout | Number | _optional_ The number of milliseconds between each poll.
280+
message | String | _optional_ The message to output.
281+
callback | Function | _optional_ A function to call after the current command finishes execution.
282+
283+
```
284+
this.demoTest = function (browser) {
285+
browser.waitForUrl('http://www.google.ca/');
286+
};
287+
```
288+
289+
#### waitForUrlToContain(url, milliseconds, timeout, messages, callback)
290+
291+
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.
316+
317+
```
318+
this.demoTest = function (browser) {
319+
browser.waitUntilMobified();
320+
};
321+
```

0 commit comments

Comments
 (0)