Skip to content

Commit 432d1d3

Browse files
author
Alexander Obuhovich
committed
Move example code from HomePage classes into the unit tests
1 parent d24dfb8 commit 432d1d3

6 files changed

Lines changed: 224 additions & 34 deletions

File tree

tests/BEM/DemoTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace tests\BEM;
4+
5+
6+
use tests\BEM\pages\HomePage;
7+
8+
class DemoTest extends AbstractQAToolsTestCase
9+
{
10+
11+
public function testExample()
12+
{
13+
$homePage = new HomePage($this->pageFactory);
14+
$homePage->open();
15+
16+
$errorMessage = $homePage->loginViaSandbox('user-a', 'password-a');
17+
}
18+
}

tests/BEM/pages/HomePage.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@ class HomePage extends BEMPage {
2626
*/
2727
protected $myTest = '';
2828

29-
public function examplePageMethod()
29+
/**
30+
* Performs login using elements from sidebox.
31+
*
32+
* @param string $username Username.
33+
* @param string $password Password.
34+
*
35+
* @return string
36+
*/
37+
public function loginViaSandbox($username, $password)
3038
{
31-
// html block login
32-
$error_message = $this->loginSidebox->login('user-b', 'password-b')->getLoginErrorMessage();
39+
return $this->loginSidebox->login($username, $password)->getLoginErrorMessage();
3340
}
41+
3442
}

tests/HtmlElements/DemoTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace tests\HtmlElements;
4+
5+
6+
use tests\AbstractQAToolsTestCase;
7+
use tests\HtmlElements\pages\HomePage;
8+
9+
class DemoTest extends AbstractQAToolsTestCase
10+
{
11+
12+
public function testExample()
13+
{
14+
$homePage = new HomePage($this->pageFactory);
15+
$homePage->open();
16+
17+
$homePage->changeCurrency('EUR');
18+
19+
$homePage->changeLanguage('Russian');
20+
21+
foreach ( $homePage->getRadioGroup() as $radioButton ) {
22+
if ( $radioButton->isSelected() ) {
23+
echo 'yes';
24+
}
25+
}
26+
27+
$homePage->selectRadioButton(4);
28+
29+
$homePage->loginInline('user-a', 'password-a');
30+
31+
$errorMessage1 = $homePage->loginViaSidebox('user-a', 'password-a');
32+
33+
$errorMessage2 = $homePage->loginViaSidebar('user-a', 'password-a');
34+
35+
$name1 = $homePage->getAutoGeneratedElementName();
36+
37+
$name2 = $homePage->getOverrideElementName();
38+
}
39+
}

tests/HtmlElements/pages/HomePage.php

Lines changed: 111 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
*/
1515
class HomePage extends TypifiedPage {
1616

17-
/**
18-
*
19-
* @var WebElement
20-
* @find-by('name' => 'u.login-sidebox[-2][UserLogin]')
21-
*/
22-
protected $usernameInput;
23-
2417
/**
2518
*
2619
* @var WebElement
@@ -44,6 +37,20 @@ class HomePage extends TypifiedPage {
4437
*/
4538
protected $radioGroup;
4639

40+
/**
41+
*
42+
* @var WebElement
43+
* @find-by('name' => 'u.login-sidebox[-2][UserLogin]')
44+
*/
45+
protected $usernameInput;
46+
47+
/**
48+
*
49+
* @var WebElement
50+
* @find-by('name' => 'u.login-sidebox[-2][UserPassword]')
51+
*/
52+
protected $passwordInput;
53+
4754
/**
4855
* Login Button
4956
*
@@ -74,34 +81,112 @@ class HomePage extends TypifiedPage {
7481
*/
7582
protected $myTest = '';
7683

77-
public function examplePageMethod()
84+
/**
85+
* Changes currency.
86+
*
87+
* @param string $currency_code Currency code.
88+
*
89+
* @return void
90+
*/
91+
public function changeCurrency($currency_code)
7892
{
79-
// $this->currencyDropdown->setValue('EUR');
80-
$this->languageDropdown->selectByVisibleText('Russian');
93+
$this->currencyDropdown->setValue($currency_code);
94+
}
8195

96+
/**
97+
* Changes language.
98+
*
99+
* @param string $language_title Language title.
100+
*
101+
* @return void
102+
*/
103+
public function changeLanguage($language_title)
104+
{
105+
$this->languageDropdown->selectByText($language_title);
106+
}
107+
108+
/**
109+
* Returns radio button collection.
110+
*
111+
* @return RadioGroup
112+
*/
113+
public function getRadioGroup()
114+
{
82115
// Need `getObject` to iterate over current collection in proxy and not a list of collection.
83-
foreach ( $this->radioGroup->getObject() as $radioButton ) {
84-
if ( $radioButton->isSelected() ) {
85-
echo 'yes';
86-
}
87-
}
116+
return $this->radioGroup->getObject();
117+
}
88118

89-
$this->radioGroup->selectButtonByValue(4);
119+
/**
120+
* Selects radio button by value.
121+
*
122+
* @param mixed $value Value.
123+
*
124+
* @return void
125+
*/
126+
public function selectRadioButton($value)
127+
{
128+
$this->radioGroup->selectButtonByValue($value);
129+
}
90130

91-
// inline login
92-
$this->usernameInput->setValue('user-a');
131+
/**
132+
* Performs login using elements declared inline.
133+
*
134+
* @param string $username Username.
135+
* @param string $password Password.
136+
*
137+
* @return void
138+
*/
139+
public function loginInline($username, $password)
140+
{
141+
$this->usernameInput->setValue($username);
142+
$this->passwordInput->setValue($password);
93143
$this->loginButton->click();
144+
}
94145

95-
// html block login
96-
$error_message = $this->loginSidebox->login('user-b', 'password-b')->getLoginErrorMessage();
146+
/**
147+
* Performs login using elements from sidebox.
148+
*
149+
* @param string $username Username.
150+
* @param string $password Password.
151+
*
152+
* @return string
153+
*/
154+
public function loginViaSidebox($username, $password)
155+
{
156+
return $this->loginSidebox->login($username, $password)->getLoginErrorMessage();
157+
}
97158

98-
// nested html block login
99-
$error_message = $this->sidebar->login('user-b', 'password-b');
159+
/**
160+
* Performs login using elements sidebar, that uses sidebox.
161+
*
162+
* @param string $username Username.
163+
* @param string $password Password.
164+
*
165+
* @return string
166+
*/
167+
public function loginViaSidebar($username, $password)
168+
{
169+
return $this->sidebar->login($username, $password);
170+
}
100171

101-
// auto-generated name
102-
echo $this->sidebar->getName();
172+
/**
173+
* Returns auto-generated name of the element.
174+
*
175+
* @return string
176+
*/
177+
public function getAutoGeneratedElementName()
178+
{
179+
return $this->sidebar->getName();
180+
}
103181

104-
// override name
105-
echo $this->loginSidebox->getName();
182+
/**
183+
* Returns overridden name of the element.
184+
*
185+
* @return string
186+
*/
187+
public function getOverrideElementName()
188+
{
189+
return $this->loginSidebox->getName();
106190
}
191+
107192
}

tests/PageObject/DemoTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace tests\PageObject;
4+
5+
6+
use tests\PageObject\pages\HomePage;
7+
8+
class DemoTest extends AbstractQAToolsTestCase
9+
{
10+
11+
public function testExample()
12+
{
13+
$homePage = new HomePage($this->pageFactory);
14+
$homePage->open();
15+
16+
$homePage->setUsername('example user');
17+
18+
$homePage->changeCurrency('EUR');
19+
20+
foreach ( $homePage->getSelectCollection() as $select ) {
21+
$select->selectOption(/* ... */);
22+
}
23+
}
24+
}

tests/PageObject/pages/HomePage.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,29 @@ class HomePage extends Page {
3636
public function setUsername($username)
3737
{
3838
$this->inputByName->setValue($username);
39-
$this->selectByTagName->setValue('EUR');
39+
}
4040

41-
$this->inputByName->setValue('another user');
41+
/**
42+
* Changes currency.
43+
*
44+
* @param string $currency_code Currency code.
45+
*
46+
* @return void
47+
*/
48+
public function changeCurrency($currency_code)
49+
{
50+
$this->selectByTagName->setValue($currency_code);
51+
}
4252

53+
/**
54+
* Returns SELECT element collection.
55+
*
56+
* @return WebElementCollection
57+
*/
58+
public function getSelectCollection()
59+
{
4360
// Need `getObject` to iterate over current collection in proxy and not a list of collection.
44-
foreach ( $this->selectCollection->getObject() as $select ) {
45-
$select->selectOption(/* ... */);
46-
}
61+
return $this->selectCollection->getObject();
4762
}
63+
4864
}

0 commit comments

Comments
 (0)