Skip to content

Commit 755bb93

Browse files
Completed simple example
1 parent 07019b9 commit 755bb93

File tree

8 files changed

+91
-70
lines changed

8 files changed

+91
-70
lines changed

Features/bootstrap/MainContext.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ public function pageOpen($page)
3939
*/
4040
public function errorMessageVisible($message)
4141
{
42-
42+
if ( $this->page->errorPane->getText() !== $message ) {
43+
throw new Exception('Error message "' . $message . '" not visible!');
44+
};
4345
}
4446

4547
/**
46-
* @Given /^the user waits for ([0-9]+) seconds$/
48+
* @Given /^I wait for ([0-9]+) seconds$/
4749
*/
4850
public function waitFor($seconds)
4951
{

Features/login.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Feature: Login
88
Given I'm on 'Login Page'
99
When I login with 'username' and 'wrong password'
1010
Then I should be on 'Login page'
11-
And I should see 'invalid username or password' error message
11+
And I should see 'Invalid username or password!' error message
1212

1313
@javascript @login @successful-login
1414
Scenario: Successful login of user

Fixtures/index.html

-52
This file was deleted.

Fixtures/index.php

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<html>
2+
<head>
3+
<!-- Latest compiled and minified CSS -->
4+
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
5+
<!-- Optional theme -->
6+
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
7+
<!-- additional css -->
8+
<link rel="stylesheet" href="additional.css">
9+
<!-- Latest compiled and minified JavaScript -->
10+
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
11+
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
12+
</head>
13+
<body>
14+
<div class="row margin-top margin-bottom">
15+
<form id="login-form" role="form" class="col-md-4 col-md-offset-4 panel panel-default" action="login.php" method="POST">
16+
<div class="panel-body">
17+
<?php if ( isset($_GET['error']) ): ?>
18+
<div class="alert alert-danger" role="alert">Invalid username or password!</div>
19+
<?php endif; ?>
20+
<div class="form-group">
21+
<label for="username">Username</label>
22+
<input type="text" class="form-control" name="username" id="username">
23+
</div>
24+
<div class="form-group">
25+
<label for="password">Password</label>
26+
<input type="password" class="form-control" name="password" id="password">
27+
</div>
28+
<input type="submit" class="btn btn-default" value="Login">
29+
</div>
30+
</form>
31+
</div>
32+
<hr>
33+
<div class="row">
34+
<div class="col-md-5 col-md-offset-1">
35+
<h3>Caption Column 1</h3>
36+
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et
37+
dolore
38+
magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
39+
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur
40+
sadipscing
41+
elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
42+
vero
43+
eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
44+
ipsum
45+
dolor sit amet.
46+
</div>
47+
<div class="col-md-5">
48+
<h3>Caption Column 2</h3>
49+
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et
50+
dolore
51+
magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd
52+
gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur
53+
sadipscing
54+
elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
55+
vero
56+
eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
57+
ipsum
58+
dolor sit amet.
59+
</div>
60+
</div>
61+
</div>
62+
</body>
63+
</html>

Fixtures/login.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@
99
*/
1010

1111
if ( empty($_POST) ) {
12-
header('Location: index.html');
12+
header('Location: /?error');
13+
die();
1314
}
1415

15-
if ( $_POST['username'] != 'user' ) {
16-
header('Location: index.html');
16+
if ( $_POST['username'] !== 'username' ) {
17+
header('Location: /?error');
18+
die();
1719
}
1820

19-
if ( $_POST['password'] != 'validpassword' ) {
20-
header('Location: index.html');
21+
if ( $_POST['password'] !== 'password' ) {
22+
header('Location: /?error');
23+
die();
2124
}
2225

23-
header('Location: account.html');
26+
header('Location: /account.html');

composer.json

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@
77
"behat/behat": "~3.0",
88
"behat/mink-extension": "~2.0",
99
"mindplay/annotations": "~1.2@dev",
10-
"qa-tools/qa-tools": "dev-121-page-matcher",
11-
"qa-tools/behat-extension": "dev-cleanup"
10+
"qa-tools/qa-tools": "dev-develop",
11+
"qa-tools/behat-extension": "dev-develop"
1212
},
1313
"repositories": [
14-
{
15-
"type": "vcs",
16-
"url": "https://github.com/evangelion1204/qa-tools.git"
17-
},
1814
{
1915
"type": "vcs",
2016
"url": "https://github.com/evangelion1204/behat-extension.git"

src/QATools/Example/Pages/AccountPage.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Class LoginPage.
1919
*
2020
* @page-url('/account.html')
21-
* @page-url-match('/account.html')
21+
* @page-url-match('path' => '/account.html')
2222
*/
2323
class AccountPage extends TypifiedPage
2424
{

src/QATools/Example/Pages/LoginPage.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212

1313

1414
use QATools\QATools\HtmlElements\Element\Form;
15+
use QATools\QATools\HtmlElements\Element\TextBlock;
1516
use QATools\QATools\HtmlElements\TypifiedPage;
1617

1718
/**
1819
* Class LoginPage.
1920
*
2021
* @page-url('/')
21-
* @page-match-url('/')
22+
* @page-url-match('path' => '/')
2223
*/
2324
class LoginPage extends TypifiedPage
2425
{
@@ -29,7 +30,15 @@ class LoginPage extends TypifiedPage
2930
* @var Form
3031
* @find-by('id' => 'login-form')
3132
*/
32-
protected $loginForm;
33+
public $loginForm;
34+
35+
/**
36+
* The error label.
37+
*
38+
* @var TextBlock
39+
* @find-by('css' => '.alert')
40+
*/
41+
public $errorPane;
3342

3443
/**
3544
* Does the login.

0 commit comments

Comments
 (0)