[ticket/14947] Create new webdriver instance for every test

PHPUnit seems to have emptied the webdriver between every test, which
causes curl errors. A new webdriver instance will now be created for
every test file. This does not cause a lot of overhead for ui tests.

PHPBB3-14947
This commit is contained in:
Marc Alexander 2017-01-02 20:39:41 +01:00
parent e88aecd3b4
commit 429225027e
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
3 changed files with 46 additions and 44 deletions

View file

@ -78,15 +78,12 @@ class phpbb_ui_test_case extends phpbb_test_case
self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.'); self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.');
} }
if (!self::$webDriver)
{
try { try {
$capabilities = DesiredCapabilities::firefox(); $capabilities = DesiredCapabilities::firefox();
self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities); self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities);
} catch (WebDriverCurlException $e) { } catch (WebDriverCurlException $e) {
self::markTestSkipped('PhantomJS webserver is not running.'); self::markTestSkipped('PhantomJS webserver is not running.');
} }
}
if (!self::$already_installed) if (!self::$already_installed)
{ {
@ -146,9 +143,14 @@ class phpbb_ui_test_case extends phpbb_test_case
} }
} }
static public function visit($path) public function getDriver()
{ {
self::$webDriver->get(self::$root_url . $path); return self::$webDriver;
}
public function visit($path)
{
$this->getDriver()->get(self::$root_url . $path);
} }
static protected function recreate_database($config) static protected function recreate_database($config)
@ -157,14 +159,14 @@ class phpbb_ui_test_case extends phpbb_test_case
$db_conn_mgr->recreate_db(); $db_conn_mgr->recreate_db();
} }
static public function find_element($type, $value) public function find_element($type, $value)
{ {
return self::$webDriver->findElement(WebDriverBy::$type($value)); return $this->getDriver()->findElement(WebDriverBy::$type($value));
} }
static public function submit($type = 'id', $value = 'submit') public function submit($type = 'id', $value = 'submit')
{ {
$element = self::find_element($type, $value); $element = $this->find_element($type, $value);
$element->click(); $element->click();
} }
@ -305,21 +307,21 @@ class phpbb_ui_test_case extends phpbb_test_case
$ext_path = str_replace('/', '%2F', $extension); $ext_path = str_replace('/', '%2F', $extension);
$this->visit('adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=' . $ext_path . '&sid=' . $this->sid); $this->visit('adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=' . $ext_path . '&sid=' . $this->sid);
$this->assertNotEmpty(count(self::find_element('cssSelector', '.submit-buttons'))); $this->assertNotEmpty(count($this->find_element('cssSelector', '.submit-buttons')));
self::find_element('cssSelector', "input[value='Enable']")->submit(); $this->find_element('cssSelector', "input[value='Enable']")->submit();
$this->add_lang('acp/extensions'); $this->add_lang('acp/extensions');
try try
{ {
$meta_refresh = self::find_element('cssSelector', 'meta[http-equiv="refresh"]'); $meta_refresh = $this->find_element('cssSelector', 'meta[http-equiv="refresh"]');
// Wait for extension to be fully enabled // Wait for extension to be fully enabled
while (sizeof($meta_refresh)) while (sizeof($meta_refresh))
{ {
preg_match('#url=.+/(adm+.+)#', $meta_refresh->getAttribute('content'), $match); preg_match('#url=.+/(adm+.+)#', $meta_refresh->getAttribute('content'), $match);
self::$webDriver->execute(array('method' => 'post', 'url' => $match[1])); $this->getDriver()->execute(array('method' => 'post', 'url' => $match[1]));
$meta_refresh = self::find_element('cssSelector', 'meta[http-equiv="refresh"]'); $meta_refresh = $this->find_element('cssSelector', 'meta[http-equiv="refresh"]');
} }
} }
catch (\Facebook\WebDriver\Exception\NoSuchElementException $e) catch (\Facebook\WebDriver\Exception\NoSuchElementException $e)
@ -327,7 +329,7 @@ class phpbb_ui_test_case extends phpbb_test_case
// Probably no refresh triggered // Probably no refresh triggered
} }
$this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', self::find_element('cssSelector', 'div.successbox')->getText()); $this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', $this->find_element('cssSelector', 'div.successbox')->getText());
$this->logout(); $this->logout();
} }
@ -415,7 +417,7 @@ class phpbb_ui_test_case extends phpbb_test_case
} }
$this->visit('ucp.php?sid=' . $this->sid . '&mode=logout'); $this->visit('ucp.php?sid=' . $this->sid . '&mode=logout');
$this->assertContains($this->lang('REGISTER'), self::$webDriver->getPageSource()); $this->assertContains($this->lang('REGISTER'), $this->getDriver()->getPageSource());
unset($this->sid); unset($this->sid);
} }
@ -435,17 +437,17 @@ class phpbb_ui_test_case extends phpbb_test_case
return; return;
} }
self::$webDriver->manage()->deleteAllCookies(); $this->getDriver()->manage()->deleteAllCookies();
$this->visit('adm/index.php?sid=' . $this->sid); $this->visit('adm/index.php?sid=' . $this->sid);
$this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), self::$webDriver->getPageSource()); $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), $this->getDriver()->getPageSource());
self::find_element('cssSelector', 'input[name=username]')->clear()->sendKeys($username); $this->find_element('cssSelector', 'input[name=username]')->clear()->sendKeys($username);
self::find_element('cssSelector', 'input[type=password]')->sendKeys($username . $username); $this->find_element('cssSelector', 'input[type=password]')->sendKeys($username . $username);
self::find_element('cssSelector', 'input[name=login]')->click(); $this->find_element('cssSelector', 'input[name=login]')->click();
$this->assertContains($this->lang('ADMIN_PANEL'), $this->find_element('cssSelector', 'h1')->getText()); $this->assertContains($this->lang('ADMIN_PANEL'), $this->find_element('cssSelector', 'h1')->getText());
$cookies = self::$webDriver->manage()->getCookies(); $cookies = $this->getDriver()->manage()->getCookies();
// The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie
foreach ($cookies as $cookie) foreach ($cookies as $cookie)
@ -550,19 +552,19 @@ class phpbb_ui_test_case extends phpbb_test_case
{ {
$this->add_lang('ucp'); $this->add_lang('ucp');
self::$webDriver->manage()->deleteAllCookies(); $this->getDriver()->manage()->deleteAllCookies();
$this->visit('ucp.php'); $this->visit('ucp.php');
$this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), self::$webDriver->getPageSource()); $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $this->getDriver()->getPageSource());
self::$webDriver->manage()->deleteAllCookies(); $this->getDriver()->manage()->deleteAllCookies();
self::find_element('cssSelector', 'input[name=username]')->sendKeys($username); $this->find_element('cssSelector', 'input[name=username]')->sendKeys($username);
self::find_element('cssSelector', 'input[name=password]')->sendKeys($username . $username); $this->find_element('cssSelector', 'input[name=password]')->sendKeys($username . $username);
self::find_element('cssSelector', 'input[name=login]')->click(); $this->find_element('cssSelector', 'input[name=login]')->click();
$this->assertNotContains($this->lang('LOGIN'), $this->find_element('className', 'navbar')->getText()); $this->assertNotContains($this->lang('LOGIN'), $this->find_element('className', 'navbar')->getText());
$cookies = self::$webDriver->manage()->getCookies(); $cookies = $this->getDriver()->manage()->getCookies();
// The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie
foreach ($cookies as $cookie) foreach ($cookies as $cookie)
@ -586,6 +588,6 @@ class phpbb_ui_test_case extends phpbb_test_case
// Change the Path to your own settings // Change the Path to your own settings
$screenshot = time() . ".png"; $screenshot = time() . ".png";
self::$webDriver->takeScreenshot($screenshot); $this->getDriver()->takeScreenshot($screenshot);
} }
} }

View file

@ -25,19 +25,19 @@ class ui_permission_roles_test extends phpbb_ui_test_case
$this->visit('adm/index.php?i=acp_permissions&mode=setting_forum_local&sid=' . $this->sid); $this->visit('adm/index.php?i=acp_permissions&mode=setting_forum_local&sid=' . $this->sid);
// Select forums // Select forums
$elements = self::find_element('cssSelector', 'select#forum') $elements = $this->find_element('cssSelector', 'select#forum')
->findElements(\Facebook\WebDriver\WebDriverBy::tagName('option')); ->findElements(\Facebook\WebDriver\WebDriverBy::tagName('option'));
foreach ($elements as $element) foreach ($elements as $element)
{ {
$element->click(); $element->click();
} }
self::find_element('cssSelector', 'form#select_victim') $this->find_element('cssSelector', 'form#select_victim')
->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('input[type=submit]')) ->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('input[type=submit]'))
->click(); ->click();
// Select administrators and guests // Select administrators and guests
$groups_form = self::find_element('cssSelector', 'form#groups'); $groups_form = $this->find_element('cssSelector', 'form#groups');
$elements = $groups_form $elements = $groups_form
->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('select')) ->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('select'))
->findElements(\Facebook\WebDriver\WebDriverBy::tagName('option')); ->findElements(\Facebook\WebDriver\WebDriverBy::tagName('option'));
@ -51,7 +51,7 @@ class ui_permission_roles_test extends phpbb_ui_test_case
} }
$groups_form->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('input[name=submit_edit_options]'))->click(); $groups_form->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('input[name=submit_edit_options]'))->click();
$first_fieldset = self::find_element('cssSelector', '#perm11'); $first_fieldset = $this->find_element('cssSelector', '#perm11');
$this->assertEquals('none', $first_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('div.dropdown'))->getCSSValue('display')); $this->assertEquals('none', $first_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('div.dropdown'))->getCSSValue('display'));
$first_fieldset $first_fieldset
->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('span.dropdown-toggle')) ->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('span.dropdown-toggle'))
@ -74,14 +74,14 @@ class ui_permission_roles_test extends phpbb_ui_test_case
$this->assertEquals($this->lang('ROLE_FORUM_LIMITED'), $first_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('span.dropdown-toggle'))->getText()); $this->assertEquals($this->lang('ROLE_FORUM_LIMITED'), $first_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('span.dropdown-toggle'))->getText());
// Check that admin settings didn't get changed // Check that admin settings didn't get changed
$second_fieldset = self::find_element('cssSelector', '#perm10'); $second_fieldset = $this->find_element('cssSelector', '#perm10');
$this->assertEquals('none', $second_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('div.dropdown'))->getCSSValue('display')); $this->assertEquals('none', $second_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('div.dropdown'))->getCSSValue('display'));
// Full access = 14 // Full access = 14
$this->assertEquals(14, $second_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('input[type=hidden]'))->getAttribute('value')); $this->assertEquals(14, $second_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('input[type=hidden]'))->getAttribute('value'));
$this->assertEquals($this->lang('ROLE_FORUM_FULL'), $second_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('span.dropdown-toggle'))->getText()); $this->assertEquals($this->lang('ROLE_FORUM_FULL'), $second_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('span.dropdown-toggle'))->getText());
// Check that category settings were not modified // Check that category settings were not modified
$category_fieldset = self::find_element('cssSelector', '#perm00'); $category_fieldset = $this->find_element('cssSelector', '#perm00');
$this->assertEquals('none', $category_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('div.dropdown'))->getCSSValue('display')); $this->assertEquals('none', $category_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('div.dropdown'))->getCSSValue('display'));
// No settings // No settings
$this->assertEquals('', $category_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('input[type=hidden]'))->getAttribute('value')); $this->assertEquals('', $category_fieldset->findElement(\Facebook\WebDriver\WebDriverBy::cssSelector('input[type=hidden]'))->getAttribute('value'));

View file

@ -19,8 +19,8 @@ class quick_links_test extends phpbb_ui_test_case
public function test_quick_links() public function test_quick_links()
{ {
$this->visit('index.php'); $this->visit('index.php');
$this->assertEmpty(self::find_element('className', 'dropdown')->getText()); $this->assertEmpty($this->find_element('className', 'dropdown')->getText());
self::find_element('className', 'dropdown-toggle')->click(); $this->find_element('className', 'dropdown-toggle')->click();
$this->assertNotNull(self::find_element('className', 'dropdown')->getText()); $this->assertNotNull($this->find_element('className', 'dropdown')->getText());
} }
} }