-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathWebDriverDemoShootout.php
142 lines (120 loc) · 4.16 KB
/
WebDriverDemoShootout.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
require_once 'vendor/autoload.php';
class WebDriverDemoShootout extends Sauce\Sausage\WebDriverTestCase
{
protected $base_url = 'http://tutorialapp.saucelabs.com';
public static $browsers = array(
// run FF15 on Vista on Sauce
array(
'browserName' => 'firefox',
'desiredCapabilities' => array(
'version' => '15',
'platform' => 'VISTA'
)
)
);
protected function randomUser()
{
$id = uniqid();
return array(
'username' => "fakeuser_$id",
'password' => 'testpass',
'name' => "Fake $id",
'email' => "$id@fake.com"
);
}
protected function doLogin($username, $password)
{
$this->url('/');
$this->byName('login')->value($username);
$this->byName('password')->value($password);
$this->byCss('input.login')->click();
$this->assertTextPresent("Logged in successfully", $this->byId('message'));
}
protected function doLogout()
{
$this->url('/logout');
$this->assertTextPresent("Logged out successfully", $this->byId('message'));
}
protected function doRegister($user, $logout = false)
{
$user['confirm_password'] = isset($user['confirm_password']) ?
$user['confirm_password'] : $user['password'];
$this->url('/register');
$this->byId('username')->value($user['username']);
$this->byId('password')->value($user['password']);
$this->byId('confirm_password')->value($user['confirm_password']);
$this->byId('name')->value($user['name']);
$this->byId('email')->value($user['email']);
$this->byId('form.submitted')->click();
if ($logout)
$this->doLogout();
}
public function setUpPage()
{
$this->url('http://tutorialapp.saucelabs.com');
}
public function testLoginFailsWithBadCredentials()
{
$fake_username = uniqid();
$fake_password = uniqid();
$this->url('/');
$this->byName('login')->value($fake_username);
$this->byName('password')->value($fake_password);
$this->byCss('input.login')->click();
$this->assertTextPresent("Failed to login.", $this->byId('message'));
}
public function testLogin()
{
$user = $this->randomUser();
$this->doRegister($user, true);
$this->doLogin($user['username'], $user['password']);
}
public function testLogout()
{
$this->doRegister($this->randomUser(), true);
}
public function testRegister()
{
$user = $this->randomUser();
$this->doRegister($user);
$logged_in_text = "You are logged in as {$user['username']}";
$this->assertTextPresent($logged_in_text);
}
public function testRegisterFailsWithoutUsername()
{
$user = $this->randomUser();
$user['username'] = '';
$this->doRegister($user);
$this->assertTextPresent("Please enter a value");
}
public function testRegisterFailsWithoutName()
{
$user = $this->randomUser();
$user['name'] = '';
$this->doRegister($user);
$this->assertTextPresent("Please enter a value");
}
public function testRegisterFailsWithMismatchedPasswords()
{
$user = $this->randomUser();
$user['confirm_password'] = uniqid();
$this->doRegister($user);
$this->assertTextPresent("Fields do not match");
}
public function testRegisterFailsWithBadEmail()
{
$user = $this->randomUser();
$user['email'] = 'test';
$this->doRegister($user);
$this->assertTextPresent("An email address must contain a single @");
$this->byId('email')->clear();
$this->byId('email')->value('@bob.com');
$this->byId('form.submitted')->click();
$this->assertTextPresent("The username portion of the email address is invalid");
$this->byId('email')->clear();
$this->byId('email')->value('test@bob');
$this->byId('form.submitted')->click();
$this->assertTextPresent("The domain portion of the email address is invalid");
}
}