forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: incorporate traits into e2e ci testing (openemr#7757)
- Loading branch information
1 parent
968ba9c
commit 402c607
Showing
10 changed files
with
334 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/** | ||
* BaseTrait trait | ||
* | ||
* @package OpenEMR | ||
* @link https://www.open-emr.org | ||
* @author Brady Miller <[email protected]> | ||
* @copyright Copyright (c) 2024 Brady Miller <[email protected]> | ||
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenEMR\Tests\E2e\Base; | ||
|
||
use OpenEMR\Tests\E2e\Xpaths\XpathsConstants; | ||
|
||
trait BaseTrait | ||
{ | ||
protected function base(): void | ||
{ | ||
$e2eBaseUrl = getenv("OPENEMR_BASE_URL_E2E", true) ?: "http://localhost"; | ||
$this->client = static::createPantherClient(['external_base_uri' => $e2eBaseUrl]); | ||
$this->client->manage()->window()->maximize(); | ||
} | ||
|
||
protected function switchToIFrame($selector): void | ||
{ | ||
$iframe = $this->client->findElement($selector); | ||
$this->client->switchTo()->frame($iframe); | ||
$this->crawler = $this->client->refreshCrawler(); | ||
} | ||
|
||
protected function assertActiveTab($text): void | ||
{ | ||
$startTime = (int) (microtime(true) * 1000); | ||
while (strpos($this->crawler->filterXPath(XpathsConstants::ACTIVE_TAB)->text(), "Loading") === 0) { | ||
if (($startTime + 10000) < ((int) (microtime(true) * 1000))) { | ||
$this->fail("Timeout waiting for tab [$text]"); | ||
} | ||
usleep(100); | ||
} | ||
$this->assertSame($text, $this->crawler->filterXPath(XpathsConstants::ACTIVE_TAB)->text(), "[$text] tab load FAILED"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,35 @@ | ||
<?php | ||
|
||
/** | ||
* CheckMainMenuLinksTest class | ||
* | ||
* @package OpenEMR | ||
* @link https://www.open-emr.org | ||
* @author Brady Miller <[email protected]> | ||
* @copyright Copyright (c) 2024 Brady Miller <[email protected]> | ||
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenEMR\Tests\E2e; | ||
|
||
use OpenEMR\Tests\E2e\Base\BaseTrait; | ||
use OpenEMR\Tests\E2e\Login\LoginTrait; | ||
use Symfony\Component\Panther\PantherTestCase; | ||
use Symfony\Component\Panther\Client; | ||
|
||
class CheckMainMenuLinksTest extends PantherTestCase | ||
{ | ||
/** | ||
* The base url used for e2e (end to end) browser testing. | ||
*/ | ||
private $e2eBaseUrl; | ||
use BaseTrait; | ||
use LoginTrait; | ||
|
||
private $client; | ||
private $crawler; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->e2eBaseUrl = getenv("OPENEMR_BASE_URL_E2E", true) ?: "http://localhost"; | ||
} | ||
|
||
public function testLogin(): void | ||
{ | ||
$openEmrPage = $this->e2eBaseUrl; | ||
$this->client = static::createPantherClient(['external_base_uri' => $openEmrPage]); | ||
$this->client->manage()->window()->maximize(); | ||
try { | ||
$this->login('admin', 'pass'); | ||
} catch (\Throwable $e) { | ||
// Close client | ||
$this->client->quit(); | ||
// re-throw the exception | ||
throw $e; | ||
} | ||
// Close client | ||
$this->client->quit(); | ||
} | ||
protected $client; | ||
protected $crawler; | ||
|
||
/** | ||
* @dataProvider menuLinkProvider | ||
* @depends testLogin | ||
* @depends testLoginAuthorized | ||
*/ | ||
public function testCheckMenuLink(string $menuLink, string $expectedTabTitle): void | ||
{ | ||
|
@@ -50,9 +38,7 @@ public function testCheckMenuLink(string $menuLink, string $expectedTabTitle): v | |
// a high enough version of nodejs) | ||
$this->markTestSkipped('Test skipped because this environment does not support high enough nodejs version.'); | ||
} | ||
$openEmrPage = $this->e2eBaseUrl; | ||
$this->client = static::createPantherClient(['external_base_uri' => $openEmrPage]); | ||
$this->client->manage()->window()->maximize(); | ||
$this->base(); | ||
try { | ||
$this->login('admin', 'pass'); | ||
// check if the menu cog is showing. if so, then click it. | ||
|
@@ -89,9 +75,7 @@ public function testCheckMenuLink(string $menuLink, string $expectedTabTitle): v | |
$counter++; | ||
} | ||
// wait for the tab title to be shown | ||
$this->client->waitForElementToContain("//div[@id='tabs_div']/div/div[not(contains(concat(' ',normalize-space(@class),' '),' tabsNoHover '))]", $expectedTabTitle); | ||
// Perform the final assertion | ||
$this->assertSame($expectedTabTitle, $this->crawler->filterXPath("//div[@id='tabs_div']/div/div[not(contains(concat(' ',normalize-space(@class),' '),' tabsNoHover '))]")->text(), 'Page load FAILED'); | ||
$this->assertActiveTab($expectedTabTitle); | ||
} catch (\Throwable $e) { | ||
// Close client | ||
$this->client->quit(); | ||
|
@@ -200,16 +184,4 @@ public static function menuLinkProvider() | |
'Miscellaneous -> New Documents menu link' => ['Miscellaneous||New Documents', 'Documents'] | ||
]; | ||
} | ||
|
||
private function login(string $name, string $password): void | ||
{ | ||
// login | ||
$this->crawler = $this->client->request('GET', '/interface/login/login.php?site=default'); | ||
$form = $this->crawler->filter('#login_form')->form(); | ||
$form['authUser'] = $name; | ||
$form['clearPass'] = $password; | ||
$this->crawler = $this->client->submit($form); | ||
$title = $this->client->getTitle(); | ||
$this->assertSame('OpenEMR', $title, 'Login FAILED'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* CheckUserMenuLinksTest class | ||
* | ||
* @package OpenEMR | ||
* @link https://www.open-emr.org | ||
* @author Brady Miller <[email protected]> | ||
* @copyright Copyright (c) 2024 Brady Miller <[email protected]> | ||
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenEMR\Tests\E2e; | ||
|
||
use OpenEMR\Tests\E2e\Base\BaseTrait; | ||
use OpenEMR\Tests\E2e\Login\LoginTrait; | ||
use Symfony\Component\Panther\PantherTestCase; | ||
use Symfony\Component\Panther\Client; | ||
|
||
class CheckUserMenuLinksTest extends PantherTestCase | ||
{ | ||
/** | ||
* The base url used for e2e (end to end) browser testing. | ||
*/ | ||
private $e2eBaseUrl; | ||
use BaseTrait; | ||
use LoginTrait; | ||
|
||
private $client; | ||
private $crawler; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->e2eBaseUrl = getenv("OPENEMR_BASE_URL_E2E", true) ?: "http://localhost"; | ||
} | ||
|
||
public function testLogin(): void | ||
{ | ||
$openEmrPage = $this->e2eBaseUrl; | ||
$this->client = static::createPantherClient(['external_base_uri' => $openEmrPage]); | ||
$this->client->manage()->window()->maximize(); | ||
try { | ||
$this->login('admin', 'pass'); | ||
} catch (\Throwable $e) { | ||
// Close client | ||
$this->client->quit(); | ||
// re-throw the exception | ||
throw $e; | ||
} | ||
// Close client | ||
$this->client->quit(); | ||
} | ||
protected $client; | ||
protected $crawler; | ||
|
||
/** | ||
* @dataProvider menuLinkProvider | ||
* @depends testLogin | ||
* @depends testLoginAuthorized | ||
*/ | ||
public function testCheckUserMenuLink(string $menutreeicon, string $menuLinkItem, string $expectedTabTitle): void | ||
{ | ||
$openEmrPage = $this->e2eBaseUrl; | ||
$this->client = static::createPantherClient(['external_base_uri' => $openEmrPage]); | ||
$this->client->manage()->window()->maximize(); | ||
$this->base(); | ||
try { | ||
$this->login('admin', 'pass'); | ||
// got to and click the user menu link | ||
|
@@ -67,9 +53,7 @@ public function testCheckUserMenuLink(string $menutreeicon, string $menuLinkItem | |
$title = $this->client->getTitle(); | ||
$this->assertSame('OpenEMR Login', $title, 'Logout FAILED'); | ||
} else { | ||
$this->client->waitForElementToContain("//div[@id='tabs_div']/div/div[not(contains(concat(' ',normalize-space(@class),' '),' tabsNoHover '))]", $expectedTabTitle); | ||
// Perform the final assertion | ||
$this->assertSame($expectedTabTitle, $this->crawler->filterXPath("//div[@id='tabs_div']/div/div[not(contains(concat(' ',normalize-space(@class),' '),' tabsNoHover '))]")->text(), 'Page load FAILED'); | ||
$this->assertActiveTab($expectedTabTitle); | ||
} | ||
} catch (\Throwable $e) { | ||
// Close client | ||
|
@@ -91,16 +75,4 @@ public static function menuLinkProvider() | |
'Logout user menu link' => ['fa-sign-out-alt', 'Logout', 'OpenEMR Login'] | ||
]; | ||
} | ||
|
||
private function login(string $name, string $password): void | ||
{ | ||
// login | ||
$this->crawler = $this->client->request('GET', '/interface/login/login.php?site=default'); | ||
$form = $this->crawler->filter('#login_form')->form(); | ||
$form['authUser'] = $name; | ||
$form['clearPass'] = $password; | ||
$this->crawler = $this->client->submit($form); | ||
$title = $this->client->getTitle(); | ||
$this->assertSame('OpenEMR', $title, 'Login FAILED'); | ||
} | ||
} |
Oops, something went wrong.