diff --git a/module/VuFind/src/VuFindTest/Unit/MinkTestCase.php b/module/VuFind/src/VuFindTest/Unit/MinkTestCase.php index 2b8e67dd5b41b6e09d38c37632f6162bd30ffd5e..acfca0197c25909f75979dffef6d7d496e3c023d 100644 --- a/module/VuFind/src/VuFindTest/Unit/MinkTestCase.php +++ b/module/VuFind/src/VuFindTest/Unit/MinkTestCase.php @@ -243,6 +243,36 @@ abstract class MinkTestCase extends DbTestCase return $result; } + /** + * Set a value within an element selected via CSS; retry if set fails + * due to browser bugs. + * + * @param Element $page Page element + * @param string $selector CSS selector + * @param string $value Value to set + * @param int $timeout Wait timeout for CSS selection (in ms) + * @param int $retries Retry count for set loop + * + * @return mixed + */ + protected function findCssAndSetValue(Element $page, $selector, $value, + $timeout = 1000, $retries = 6 + ) { + $field = $this->findCss($page, $selector, $timeout); + + // Workaround for Chromedriver bug; sometimes setting a value + // doesn't work on the first try. + for ($i = 0; $i < $retries; $i++) { + $field->setValue($value); + // Did it work? If so, we're done and can leave.... + if ($field->getValue() === $value) { + return; + } + } + + throw new \Exception('Failed to set value after ' . $retries . ' attempts.'); + } + /** * Retrieve a link and assert that it exists before returning it. * diff --git a/module/VuFind/src/VuFindTest/Unit/UserCreationTrait.php b/module/VuFind/src/VuFindTest/Unit/UserCreationTrait.php index 09d1e11a6e56fcd3820d5008d269bd1ee3646f4e..1c25b85d6c8dfd18de13b3cdb00639291e5a0d36 100644 --- a/module/VuFind/src/VuFindTest/Unit/UserCreationTrait.php +++ b/module/VuFind/src/VuFindTest/Unit/UserCreationTrait.php @@ -103,8 +103,8 @@ trait UserCreationTrait ]; foreach ($defaults as $field => $default) { - $element = $this->findCss($page, '#account_' . $field); - $element->setValue( + $this->findCssAndSetValue( + $page, '#account_' . $field, isset($overrides[$field]) ? $overrides[$field] : $default ); } @@ -126,16 +126,14 @@ trait UserCreationTrait ) { $prefix = ($inModal ? '.modal-body ' : '') . $prefix; if (null !== $username) { - $usernameField = $this->findCss($page, $prefix . '[name="username"]'); - // Workaround for Chromedriver bug; sometimes setting the username - // doesn't work on the first try. - while ($usernameField->getValue() !== $username) { - $usernameField->setValue($username); - } + $this->findCssAndSetValue( + $page, $prefix . '[name="username"]', $username + ); } if (null !== $password) { - $passwordField = $this->findCss($page, $prefix . '[name="password"]'); - $passwordField->setValue($password); + $this->findCssAndSetValue( + $page, $prefix . '[name="password"]', $password + ); } } @@ -154,12 +152,9 @@ trait UserCreationTrait $inModal = false, $prefix = '#newpassword ' ) { $prefix = ($inModal ? '.modal-body ' : '') . $prefix; - $usernameField = $this->findCss($page, $prefix . '[name="oldpwd"]'); - $usernameField->setValue($old); - $passwordField = $this->findCss($page, $prefix . '[name="password"]'); - $passwordField->setValue($new); - $password2Field = $this->findCss($page, $prefix . '[name="password2"]'); - $password2Field->setValue($new); + $this->findCssAndSetValue($page, $prefix . '[name="oldpwd"]', $old); + $this->findCssAndSetValue($page, $prefix . '[name="password"]', $new); + $this->findCssAndSetValue($page, $prefix . '[name="password2"]', $new); } /** diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php index cec527d08bbd57ea7849a9de1cab6b33810b7190..72a914d47bc55cfade91d67f77aebc941cb61de8 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/BulkTest.php @@ -136,6 +136,7 @@ class BulkTest extends \VuFindTest\Unit\MinkTestCase // First try clicking without selecting anything: $button->click(); + $this->snooze(); $this->checkForNonSelectedMessage($page); $page->find('css', '.modal-body .btn')->click(); $this->snooze(); @@ -151,10 +152,11 @@ class BulkTest extends \VuFindTest\Unit\MinkTestCase $this->fillInAccountForm($page); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); - $this->findCss($page, '.modal #email_from')->setValue('asdf@asdf.com'); - $this->findCss($page, '.modal #email_message')->setValue('message'); - $this->findCss($page, '.modal #email_to') - ->setValue('demian.katz@villanova.edu'); + $this->findCssAndSetValue($page, '.modal #email_from', 'asdf@asdf.com'); + $this->findCssAndSetValue($page, '.modal #email_message', 'message'); + $this->findCssAndSetValue( + $page, '.modal #email_to', 'demian.katz@villanova.edu' + ); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->snooze(); /* TODO: add back this check when everything is working (as of this @@ -180,6 +182,7 @@ class BulkTest extends \VuFindTest\Unit\MinkTestCase // First try clicking without selecting anything: $button->click(); + $this->snooze(); $this->checkForNonSelectedMessage($page); $page->find('css', '.modal-body .btn')->click(); $this->snooze(); @@ -226,6 +229,7 @@ class BulkTest extends \VuFindTest\Unit\MinkTestCase // First try clicking without selecting anything: $button->click(); + $this->snooze(); $this->checkForNonSelectedMessage($page); $page->find('css', '.modal-body .btn')->click(); $this->snooze(); @@ -260,6 +264,7 @@ class BulkTest extends \VuFindTest\Unit\MinkTestCase // First try clicking without selecting anything: $button->click(); + $this->snooze(); $this->checkForNonSelectedMessage($page); $page->find('css', '.modal-body .btn')->click(); $this->snooze(); diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CartTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CartTest.php index 689472beed02e23c67f3d7086ffa29f88452250b..cebca6e48dfa63de010092a8a29ad6682e9b16ea 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CartTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/CartTest.php @@ -200,6 +200,7 @@ class CartTest extends \VuFindTest\Unit\MinkTestCase $this->changeConfigs($extraConfigs); $page = $this->getSearchResultsPage(); + $this->snooze(); $this->addCurrentPageToCartUsingButtons($page); $this->assertEquals('2', $this->findCss($page, '#cartItems strong')->getText()); @@ -556,10 +557,11 @@ class CartTest extends \VuFindTest\Unit\MinkTestCase $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->snooze(); - $this->findCss($page, '.modal #email_from')->setValue('asdf@asdf.com'); - $this->findCss($page, '.modal #email_message')->setValue('message'); - $this->findCss($page, '.modal #email_to') - ->setValue('demian.katz@villanova.edu'); + $this->findCssAndSetValue($page, '.modal #email_from', 'asdf@asdf.com'); + $this->findCssAndSetValue($page, '.modal #email_message', 'message'); + $this->findCssAndSetValue( + $page, '.modal #email_to', 'demian.katz@villanova.edu' + ); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->snooze(); // Check for confirmation message diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/FavoritesTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/FavoritesTest.php index 226662f6bcb1878133bf03244fde5c8881fcd427..63b5fa1c2ab63d2f6d017f3df62042169389d3d3 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/FavoritesTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/FavoritesTest.php @@ -75,7 +75,7 @@ class FavoritesTest extends \VuFindTest\Unit\MinkTestCase $session = $this->getMinkSession(); $session->visit($this->getVuFindUrl() . '/Search/Home'); $page = $session->getPage(); - $this->findCss($page, '#searchForm_lookfor')->setValue('Dewey'); + $this->findCssAndSetValue($page, '#searchForm_lookfor', 'Dewey'); $this->findCss($page, '.btn.btn-primary')->click(); return $page; } @@ -128,7 +128,7 @@ class FavoritesTest extends \VuFindTest\Unit\MinkTestCase $this->findCss($page, '.modal-body .btn.btn-primary')->click(); // Correct - $this->findCss($page, '#account_email')->setValue('username1@ignore.com'); + $this->findCssAndSetValue($page, '#account_email', 'username1@ignore.com'); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->snooze(); $this->findCss($page, '#save_list'); @@ -138,12 +138,12 @@ class FavoritesTest extends \VuFindTest\Unit\MinkTestCase // Empty $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->snooze(); - $this->findCss($page, '#list_title')->setValue('Test List'); - $this->findCss($page, '#list_desc')->setValue('Just. THE BEST.'); + $this->findCssAndSetValue($page, '#list_title', 'Test List'); + $this->findCssAndSetValue($page, '#list_desc', 'Just. THE BEST.'); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->snooze(); $this->assertEquals($this->findCss($page, '#save_list option[selected]')->getHtml(), 'Test List'); - $this->findCss($page, '#add_mytags')->setValue('test1 test2 "test 3"'); + $this->findCssAndSetValue($page, '#add_mytags', 'test1 test2 "test 3"'); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->snooze(); $this->findCss($page, '.modal .alert.alert-success'); @@ -187,7 +187,7 @@ class FavoritesTest extends \VuFindTest\Unit\MinkTestCase // - One for the next test $this->findCss($page, '#make-list')->click(); $this->snooze(); - $this->findCss($page, '#list_title')->setValue('Future List'); + $this->findCssAndSetValue($page, '#list_title', 'Future List'); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->snooze(); $this->assertEquals( @@ -197,7 +197,7 @@ class FavoritesTest extends \VuFindTest\Unit\MinkTestCase // - One for now $this->findCss($page, '#make-list')->click(); $this->snooze(); - $this->findCss($page, '#list_title')->setValue('Login Test List'); + $this->findCssAndSetValue($page, '#list_title', 'Login Test List'); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->snooze(); $this->assertEquals( @@ -252,9 +252,9 @@ class FavoritesTest extends \VuFindTest\Unit\MinkTestCase $page, ['username' => 'username2', 'email' => 'blargasaurus'] ); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); - $this->findCss($page, '#account_email')->setValue('username2@ignore.com'); + $this->findCssAndSetValue($page, '#account_email', 'username2@ignore.com'); // Test taken username - $this->findCss($page, '#account_username')->setValue('username1'); + $this->findCssAndSetValue($page, '#account_username', 'username1'); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->findCss($page, '#account_firstname'); // Correct @@ -270,14 +270,14 @@ class FavoritesTest extends \VuFindTest\Unit\MinkTestCase // Empty $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->snooze(); - $this->findCss($page, '#list_title')->setValue('Test List'); - $this->findCss($page, '#list_desc')->setValue('Just. THE BEST.'); + $this->findCssAndSetValue($page, '#list_title', 'Test List'); + $this->findCssAndSetValue($page, '#list_desc', 'Just. THE BEST.'); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->assertEquals( $this->findCss($page, '#save_list option[selected]')->getHtml(), 'Test List' ); - $this->findCss($page, '#add_mytags')->setValue('test1 test2 "test 3"'); + $this->findCssAndSetValue($page, '#add_mytags', 'test1 test2 "test 3"'); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->snooze(); $this->findCss($page, '.alert.alert-success'); @@ -322,7 +322,7 @@ class FavoritesTest extends \VuFindTest\Unit\MinkTestCase // - One for the next test $this->findCss($page, '#make-list')->click(); $this->snooze(); - $this->findCss($page, '#list_title')->setValue('Future List'); + $this->findCssAndSetValue($page, '#list_title', 'Future List'); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->snooze(); $this->assertEquals( @@ -332,7 +332,7 @@ class FavoritesTest extends \VuFindTest\Unit\MinkTestCase // - One for now $this->findCss($page, '#make-list')->click(); $this->snooze(); - $this->findCss($page, '#list_title')->setValue('Login Test List'); + $this->findCssAndSetValue($page, '#list_title', 'Login Test List'); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->snooze(); $this->assertEquals( @@ -454,9 +454,9 @@ class FavoritesTest extends \VuFindTest\Unit\MinkTestCase // Now do it for real. $this->selectAllItemsInList($page); $button->click(); - $this->findCss($page, '.modal #email_to')->setValue('tester@vufind.org'); - $this->findCss($page, '.modal #email_from')->setValue('asdf@vufind.org'); - $this->findCss($page, '.modal #email_message')->setValue('message'); + $this->findCssAndSetValue($page, '.modal #email_to', 'tester@vufind.org'); + $this->findCssAndSetValue($page, '.modal #email_from', 'asdf@vufind.org'); + $this->findCssAndSetValue($page, '.modal #email_message', 'message'); $this->findCss($page, '.modal-body .btn.btn-primary')->click(); $this->snooze(); // Check for confirmation message