Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d327757

Browse files
update day-26 post
1 parent e9dc8c7 commit d327757

File tree

1 file changed

+52
-46
lines changed

1 file changed

+52
-46
lines changed

‎day-26/post.md

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ module.exports = {
138138
// wait for page to load
139139
.waitForElementVisible('.navbar', 1000)
140140
// click on the login link
141-
.click('a[href="#/login"]')
141+
.click('a[href="/login"]')
142142

143143
browser.assert.urlContains('login');
144144
},
@@ -196,32 +196,36 @@ Writing this up in code is straight-forward too. Just like we did previously, le
196196

197197
```javascript
198198
module.exports = {
199-
'get to login page': (browser) => {
199+
"get to login page":browser => {
200200
browser
201+
// Load the page at the launch URL
201202
.url(browser.launchUrl)
202-
.waitForElementVisible('.navbar', 1000)
203-
.click('a[href="#/login"]')
203+
// wait for page to load
204+
.waitForElementVisible(".navbar", 1000)
205+
// click on the login link
206+
.click('a[href="/login"]');
204207

205-
browser.assert.urlContains('login');
208+
browser.assert.urlContains("login");
206209
},
207-
'logging in': (browser) => {
210+
"logging in":browser => {
208211
browser
209-
// set the input email to a valid email
210-
.setValue('input[type=email]', 'ari@fullstack.io')
212+
// set the input email to a valid username / password
213+
.setValue("input[type=text]", "admin")
214+
.setValue("input[type=password]", "secret")
211215
// submit the form
212-
.click('input[type=submit]')
216+
.click("input[type=submit]")
213217
// wait for the page to load
214-
.waitForElementVisible('.navbar', 1000)
218+
.waitForElementVisible(".navbar", 1000)
215219
// Get the text of the h1 tag
216-
.getText('.content h1', function(comp) {
217-
this.assert.equal(comp.value, 'Welcome home!')
218-
})
220+
.getText(".home h1", function(comp) {
221+
this.assert.equal(comp.value, "Welcome home!");
222+
});
219223

220-
browser.assert.urlContains(browser.launchUrl)
224+
browser.assert.urlContains(browser.launchUrl);
221225
},
222-
'logging out': (browser) => {},
223-
'close': (browser) => {},
224-
}
226+
"logging out":browser => {},
227+
close:browser => {}
228+
};
225229
```
226230

227231
Running these tests again (in the third terminal window):
@@ -235,55 +239,57 @@ nightwatch
235239
We can do a similar thing with the `logging out` step from our browser. To get a user to log out, we will:
236240

237241
1. `Find and click` on the logout link
238-
2. `Wait` for the content to load for the next page (which contains an "are you sure?"-style button).
239-
3. We'll `click` on the "I'm sure" button to log out
240-
4. We'll want to `wait for the content to load again
241-
5. We'll `assert` that t`he h1 tag contains the value we expect it to have
242-
6. And we'll make sure the page shows the Login button
242+
2. We'll want to `wait for the content to load again
243+
3. We'll `assert` that t`he h1 tag contains the value we expect it to have
244+
4. And we'll make sure the page shows the Login button
243245

244246
Let's implement this with comments inline:
245247

246248

247249
```javascript
248250
module.exports = {
249-
'get to login page': (browser) => {
251+
"get to login page":browser => {
250252
browser
253+
// Load the page at the launch URL
251254
.url(browser.launchUrl)
252-
.waitForElementVisible('.navbar', 1000)
253-
.click('a[href="#/login"]')
255+
// wait for page to load
256+
.waitForElementVisible(".navbar", 1000)
257+
// click on the login link
258+
.click('a[href="/login"]');
254259

255-
browser.assert.urlContains('login');
260+
browser.assert.urlContains("login");
256261
},
257-
'logging in': (browser) => {
262+
"logging in":browser => {
258263
browser
259-
.setValue('input[type=email]', 'ari@fullstack.io')
260-
.click('input[type=submit]')
261-
.waitForElementVisible('.navbar', 1000)
262-
.getText('.content h1', function(comp) {
263-
this.assert.equal(comp.value, 'Welcome home!')
264-
})
264+
// set the input email to a valid username / password
265+
.setValue("input[type=text]", "admin")
266+
.setValue("input[type=password]", "secret")
267+
// submit the form
268+
.click("input[type=submit]")
269+
// wait for the page to load
270+
.waitForElementVisible(".navbar", 1000)
271+
// Get the text of the h1 tag
272+
.getText(".home h1", function(comp) {
273+
this.assert.equal(comp.value, "Welcome home!");
274+
});
265275

266-
browser.assert.urlContains(browser.launchUrl)
276+
browser.assert.urlContains(browser.launchUrl);
267277
},
268-
'logging out': (browser) => {
278+
"logging out":browser => {
269279
browser
270280
// Find and click on the logout link
271-
.click('a[href="#/logout"]')
272-
// Wait for the content to load
273-
.waitForElementVisible('.content button', 1000)
274-
// Click on the button to logout
275-
.click('button')
281+
.click(".logout")
276282
// We'll wait for the next content to load
277-
.waitForElementVisible('h1', 1000)
283+
.waitForElementVisible("h1", 1000)
278284
// Get the text of the h1 tag
279-
.getText('h1', function(res) {
280-
this.assert.equal(res.value, 'Welcome home!')
285+
.getText("h1", function(res) {
286+
this.assert.equal(res.value, "You need to know the secret");
281287
})
282288
// Make sure the Login button shows now
283-
.waitForElementVisible('a[href="#/login"]', 1000);
289+
.waitForElementVisible('a[href="/login"]', 1000);
284290
},
285-
'close': (browser) => {},
286-
}
291+
close:browser => {}
292+
};
287293
```
288294

289295
As of now, you may have noticed that your chrome browsers haven't been closing when the tests have completed. This is because we haven't told selenium that we want the session to be complete. We can use the `end()` command on the `browser` object to close the connection. This is why we have the last and final step called `close`.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /