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
Copy file name to clipboardExpand all lines: Readme.md
+22-58
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,12 @@
2
2
Nightmare
3
3
=========
4
4
5
-
Nightmare is a high level wrapper for [Electron](http://electron.atom.io/) (similar to phantomjs) that lets you automate browser tasks.
5
+
Nightmare is a high level browser automation library.
6
6
7
7
The goal is to expose just a few simple methods, and have an API that feels synchronous for each block of scripting, rather than deeply nested callbacks. It's designed for automating tasks across sites that don't have APIs.
8
8
9
+
Under the covers it uses [Electron](http://electron.atom.io/), which is similar to [PhantomJS](http://phantomjs.org/) but faster and more modern.
10
+
9
11
[Daydream](https://github.com/segmentio/daydream) is a complementary chrome extension built by [@stevenmiller888](https://github.com/stevenmiller888) that generates Nightmare scripts for you while you browse.
10
12
11
13
*[Examples](#examples)
@@ -14,7 +16,6 @@ The goal is to expose just a few simple methods, and have an API that feels sync
14
16
-[Interact with the page](#interact-with-the-page)
Or, here's how you might automate a nicely abstracted login + task on Swiftly:
63
-
64
-
```js
65
-
var Nightmare =require('nightmare');
66
-
var Swiftly =require('nightmare-swiftly');
67
-
var nightmare =Nightmare();
68
-
yieldnightmare()
69
-
.use(Swiftly.login(email, password))
70
-
.use(Swiftly.task(instructions, uploads, path));
71
-
```
72
-
73
-
And [here's the `nightmare-swiftly` plugin](https://github.com/segmentio/nightmare-swiftly).
74
-
75
55
You can see examples of every function [in the tests here](https://github.com/segmentio/nightmare/blob/master/test/index.js).
76
56
77
57
## API
@@ -121,31 +101,22 @@ Toggles the `selector` checkbox element.
121
101
#### .select(selector, option)
122
102
Changes the `selector` dropdown element to the option with attribute [value=`option`]
123
103
124
-
#### .upload(selector, path)
125
-
Specify the `path` to upload into a file input `selector` element.
126
-
127
104
#### .scrollTo(top, left)
128
105
Scrolls the page to desired position. `top` and `left` are always relative to the top left corner of the document.
129
106
130
107
#### .inject(type, file)
131
108
Inject a local `file` onto the current page. The file `type` must be either 'js' or 'css'.
132
109
133
-
#### .evaluate(fn, cb, arg1, arg2,...)
134
-
Invokes `fn` on the page with `arg1, arg2,...`. All the `args` are optional. On completion it passes the return value of `fn` as to `cb(res)`. Useful for extracting information from the page. Here's an example:
110
+
#### .evaluate(fn, arg1, arg2,...)
111
+
Invokes `fn` on the page with `arg1, arg2,...`. All the `args` are optional. On completion it returns the return value of `fn`. Useful for extracting information from the page. Here's an example:
135
112
136
113
```js
137
-
var p1 =1;
138
-
var p2 =2;
139
-
140
-
yield nightmare
141
-
.evaluate(function (param1, param2) {
142
-
// now we're executing inside the browser scope.
143
-
return param1 + param2;
144
-
}, function (result) {
145
-
// now we're inside Node scope again
146
-
console.log( result);
147
-
}, p1, p2 // <-- that's how you pass parameters from Node scope to browser scope
148
-
);
114
+
var selector ='h1';
115
+
var text =yield nightmare
116
+
.evaluate(function (selector) {
117
+
// now we're executing inside the browser scope.
118
+
returndocument.querySelector(selector).innerText;
119
+
}, selector); // <-- that's how you pass parameters from Node scope to browser scope
149
120
```
150
121
151
122
#### .wait()
@@ -245,13 +216,6 @@ yield nightmare
245
216
#### .headers(headers)
246
217
Set the request `headers`. You have to call this before calling `.goto()`.
247
218
248
-
## Plugins
249
-
250
-
Here's a list of plugins, pull request to add your own to the list :)
0 commit comments