In the previous article, we created separate _bootstrap.php
files for MODX 2 and MODX 3. In this one, we'll start preparing to run our tests in both MODX 2 and MODX 3.

This article assumes that you've installed and configured Composer, Codeception, PhpUnit, MODX, Java, WebDriver, and ChromeDriver as described in earlier articles, and that you've created the acceptance test support files from those articles.
Separate PageObject Files
Because the locators available on MODX 3 Manager pages my not be the same as the ones we used for MODX 2, we need to create new PageObject
files for use only in MODX 3. First, though, we'll create a new PageObject
just for MODX 2 to avoid confusion.
This work will be done in the _build/tests/_support/Page/Acceptance
directory.
Create a new file in that directory called LoginPagemodx3.php
with this code:
<?php namespace Page\Acceptance; class LoginPagemodx3 { // include url of current page public static $managerUrl = 'manager/'; public static $usernameField = '#modx-login-username'; public static $passwordField = '#modx-login-password'; public static $username = 'JoeTester'; public static $password = 'TesterPassword'; public static $loginButton = '#modx-login-btn'; public static $userMenu = '#limenu-user'; // public static $logoutLink = "//a[contains(@href,'?a=security/logout')]"; public static $logoutLink = "#logout"; public static $yesButton = "//button[contains(text(), 'Yes')]"; /** * @var $tester \AcceptanceTester; */ protected $tester; public function __construct(\AcceptanceTester $I) { /* Set $this->tester to passed-in $I so it's available in other methods */ $this->tester = $I; } public function login($username = '', $password = '') { /** @var \AcceptanceTester $I */ $I = $this->tester; $username = empty($username) ? self::$username : $username; $password = empty($password) ? self::$password : $password; $I->amOnPage(self::$managerUrl); $I->fillField(self::$usernameField, $username); $I->fillField(self::$passwordField, $password); $I->click(self::$loginButton); return $this; } /** @throws \Exception */ public function logout() { /** @var \AcceptanceTester $I */ $I = $this->tester; $I->moveMouseOver(self::$userMenu); $I->click(self::$userMenu); $I->waitForElementVisible(self::$logoutLink, 3); $I->click(self::$logoutLink); $I->wait(1); $I->click(self::$yesButton); } }
Now create another file in that directory called ResourceTestPagemodx3
with this code:
<?php namespace Page\Acceptance; /** * Declare UI map for this page here. CSS or XPath allowed. * Examples: * public static $usernameField = '#username'; * public static $formSubmitButton = "#mainForm input[type=submit]"; * * IMPORTANT - Be sure not to put a carriage return * in a quoted section inside an identifier. */ class ResourceTestPagemodx3 { /* Resources tab */ public static $resourcesTab = "//li[@id='modx-leftbar-tabpanel__modx-resource-tree']"; public static $systemMenu = '#limenu-admin'; public static $acl_option = '#acls'; public static $privateUsersGroup = "//span[starts-with(text(),'PrivateUsers')]"; public static $updateUserGroupOption = // "//button[contains(text(), 'Update User Group')]"; "//span[starts-with(text(),'Edit User Group')]"; public static $permissionsTab = "//span[starts-with(@class,'x-tab-strip-text') and text()='Permissions']"; public static $resourceGroupAccessTab = "//span[contains(text(),'Resource Group Access')]"; public static $addResourceGroupButton = "//button[contains(text(),'Add Resource Group')]"; public static $resourceGroupInput = "//input[starts-with(@id,'modx-crgact') and contains(@id, 'resource-group')]"; public static $privateResourcesOption = "//div[text()='PrivateResources']"; public static $contextInput = "//input[starts-with(@id,'modx-crgact') and contains(@id, '-context')]"; public static $mgrOption = "//span[text()='(mgr)']"; public static $authorityInput = "//input[starts-with(@id,'modx-crgact') and contains(@id, 'authority')]"; public static $testUserOption = "//div[text()='TestUser - 15' and contains(@class,'x-combo-list-item')]"; public static $policyInput = "//*[starts-with(@id,'x-form-el-modx-crg') and contains(@id,'policy')]"; public static $resourceOption = "//div[text()='Resource']"; public static $addResourcePanelSaveButton = "//span[starts-with(@id,'ext-comp')]/em/button[text()='Save']"; /** * Basic route example for your current URL * You can append any additional parameter to URL * and use it in tests like: Page\Edit::route('/123-post'); */ public static function route($param) { return static::$URL.$param; } /** * @var \AcceptanceTester; */ protected $acceptanceTester; public function __construct(\AcceptanceTester $I) { $this->acceptanceTester = $I; } }
The two files are not that different than the originals, since most of the locators are the same in MODX 3. Still, it's nice to have these as separate files since MODX 3 is still an alpha version and they could change (one just did last week). Now, the trick is to make Codeception use the appropriate page files depending on the current environment. We'll see how to do that and create a new test file with a slight modification to make it work in both MODX 2 and MODX 3 in the next article.
Coming Up
In the next article, we'll look at running a single test in multiple versions of MODX (MODX2 and MODX3) using Codeception environments and some tweaks to the code.
For more information on how to use MODX to create a web site, see my web site Bob's Guides, or better yet, buy my book: MODX: The Official Guide.
Looking for high-quality, MODX-friendly hosting? As of May 2016, Bob's Guides is hosted at A2 hosting. (More information in the box below.)
Comments (0)
Please login to comment.