Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 143 lines (120 sloc) 4.261 kb
e67d919 @jlipps add shootout test file
authored
1 <?php
2
3 require_once 'vendor/autoload.php';
4
5 class WebDriverDemoShootout extends Sauce\Sausage\WebDriverTestCase
6 {
c320562 @jlipps fix url logic
authored
7
8 protected $base_url = 'http://tutorialapp.saucelabs.com';
9
e67d919 @jlipps add shootout test file
authored
10 public static $browsers = array(
3a670ce @jlipps run the browsers on sauce!
authored
11 // run FF15 on Vista on Sauce
e67d919 @jlipps add shootout test file
authored
12 array(
3a670ce @jlipps run the browsers on sauce!
authored
13 'browserName' => 'firefox',
14 'desiredCapabilities' => array(
15 'version' => '15',
16 'platform' => 'VISTA'
17 )
6c9670b @jlipps syntax fixes
authored
18 )
e67d919 @jlipps add shootout test file
authored
19 );
20
21 protected function randomUser()
22 {
23 $id = uniqid();
24 return array(
25 'username' => "fakeuser_$id",
26 'password' => 'testpass',
27 'name' => "Fake $id",
28 'email' => "$id@fake.com"
29 );
30 }
31
e8ba970 @jlipps writing more tests for shootout
authored
32 protected function doLogin($username, $password)
e67d919 @jlipps add shootout test file
authored
33 {
e8ba970 @jlipps writing more tests for shootout
authored
34 $this->url('/');
35 $this->byName('login')->value($username);
36 $this->byName('password')->value($password);
37 $this->byCss('input.login')->click();
38
39 $this->assertTextPresent("Logged in successfully", $this->byId('message'));
40 }
41
42 protected function doLogout()
43 {
44 $this->url('/logout');
45 $this->assertTextPresent("Logged out successfully", $this->byId('message'));
46 }
47
48 protected function doRegister($user, $logout = false)
49 {
50 $user['confirm_password'] = isset($user['confirm_password']) ?
51 $user['confirm_password'] : $user['password'];
37475aa @jlipps add baseurl handling for url()
authored
52 $this->url('/register');
53 $this->byId('username')->value($user['username']);
54 $this->byId('password')->value($user['password']);
e8ba970 @jlipps writing more tests for shootout
authored
55 $this->byId('confirm_password')->value($user['confirm_password']);
37475aa @jlipps add baseurl handling for url()
authored
56 $this->byId('name')->value($user['name']);
57 $this->byId('email')->value($user['email']);
e8ba970 @jlipps writing more tests for shootout
authored
58 $this->byId('form.submitted')->click();
59
60 if ($logout)
61 $this->doLogout();
e67d919 @jlipps add shootout test file
authored
62 }
63
acfca6c @jlipps use new setUpPage instead of setUp to set url for all tests
authored
64 public function setUpPage()
e67d919 @jlipps add shootout test file
authored
65 {
acfca6c @jlipps use new setUpPage instead of setUp to set url for all tests
authored
66 $this->url('http://tutorialapp.saucelabs.com');
e67d919 @jlipps add shootout test file
authored
67 }
68
37475aa @jlipps add baseurl handling for url()
authored
69 public function testLoginFailsWithBadCredentials()
e67d919 @jlipps add shootout test file
authored
70 {
71 $fake_username = uniqid();
72 $fake_password = uniqid();
73
569d1f6 @jlipps make sure url gets opened
authored
74 $this->url('/');
e67d919 @jlipps add shootout test file
authored
75 $this->byName('login')->value($fake_username);
76 $this->byName('password')->value($fake_password);
e8ba970 @jlipps writing more tests for shootout
authored
77 $this->byCss('input.login')->click();
e67d919 @jlipps add shootout test file
authored
78
79 $this->assertTextPresent("Failed to login.", $this->byId('message'));
80 }
37475aa @jlipps add baseurl handling for url()
authored
81
e8ba970 @jlipps writing more tests for shootout
authored
82 public function testLogin()
83 {
84 $user = $this->randomUser();
85 $this->doRegister($user, true);
86 $this->doLogin($user['username'], $user['password']);
87 }
88
0ba152e @jlipps use paratest instead of paraunit
authored
89 public function testLogout()
90 {
91 $this->doRegister($this->randomUser(), true);
92 }
93
37475aa @jlipps add baseurl handling for url()
authored
94 public function testRegister()
95 {
96 $user = $this->randomUser();
97 $this->doRegister($user);
98 $logged_in_text = "You are logged in as {$user['username']}";
99 $this->assertTextPresent($logged_in_text);
100 }
101
e8ba970 @jlipps writing more tests for shootout
authored
102 public function testRegisterFailsWithoutUsername()
103 {
104 $user = $this->randomUser();
105 $user['username'] = '';
106 $this->doRegister($user);
107 $this->assertTextPresent("Please enter a value");
108 }
109
110 public function testRegisterFailsWithoutName()
111 {
112 $user = $this->randomUser();
113 $user['name'] = '';
114 $this->doRegister($user);
115 $this->assertTextPresent("Please enter a value");
116 }
117
118 public function testRegisterFailsWithMismatchedPasswords()
119 {
120 $user = $this->randomUser();
121 $user['confirm_password'] = uniqid();
122 $this->doRegister($user);
123 $this->assertTextPresent("Fields do not match");
124 }
125
126 public function testRegisterFailsWithBadEmail()
127 {
128 $user = $this->randomUser();
129 $user['email'] = 'test';
130 $this->doRegister($user);
131 $this->assertTextPresent("An email address must contain a single @");
132 $this->byId('email')->clear();
133 $this->byId('email')->value('@bob.com');
134 $this->byId('form.submitted')->click();
135 $this->assertTextPresent("The username portion of the email address is invalid");
136 $this->byId('email')->clear();
137 $this->byId('email')->value('test@bob');
138 $this->byId('form.submitted')->click();
139 $this->assertTextPresent("The domain portion of the email address is invalid");
140 }
141
e67d919 @jlipps add shootout test file
authored
142 }
Something went wrong with that request. Please try again.