MDL-63977 Behat: Organise app functions in window.behat object
parent
165c117bca
commit
c5ce5618ab
|
@ -389,7 +389,7 @@
|
||||||
* @param {string} button Type of button to press
|
* @param {string} button Type of button to press
|
||||||
* @return {string} OK if successful, or ERROR: followed by message
|
* @return {string} OK if successful, or ERROR: followed by message
|
||||||
*/
|
*/
|
||||||
window.behatPressStandard = function(button) {
|
var behatPressStandard = function(button) {
|
||||||
log('Action - Click standard button: ' + button);
|
log('Action - Click standard button: ' + button);
|
||||||
var selector;
|
var selector;
|
||||||
switch (button) {
|
switch (button) {
|
||||||
|
@ -438,7 +438,7 @@
|
||||||
*
|
*
|
||||||
* @return {string} OK if successful, or ERROR: followed by message
|
* @return {string} OK if successful, or ERROR: followed by message
|
||||||
*/
|
*/
|
||||||
window.behatClosePopup = function() {
|
var behatClosePopup = function() {
|
||||||
log('Action - Close popup');
|
log('Action - Close popup');
|
||||||
|
|
||||||
var backdrops = Array.from(document.querySelectorAll('ion-backdrop'));
|
var backdrops = Array.from(document.querySelectorAll('ion-backdrop'));
|
||||||
|
@ -474,7 +474,7 @@
|
||||||
* @param {string} near Optional 'near' text - if specified, must have a single match on page
|
* @param {string} near Optional 'near' text - if specified, must have a single match on page
|
||||||
* @return {string} OK if successful, or ERROR: followed by message
|
* @return {string} OK if successful, or ERROR: followed by message
|
||||||
*/
|
*/
|
||||||
window.behatPress = function(text, near) {
|
var behatPress = function(text, near) {
|
||||||
log('Action - Press ' + text + (near === undefined ? '' : ' - near ' + near));
|
log('Action - Press ' + text + (near === undefined ? '' : ' - near ' + near));
|
||||||
|
|
||||||
var found;
|
var found;
|
||||||
|
@ -510,7 +510,7 @@
|
||||||
*
|
*
|
||||||
* @return {string} OK: followed by header text if successful, or ERROR: followed by message.
|
* @return {string} OK: followed by header text if successful, or ERROR: followed by message.
|
||||||
*/
|
*/
|
||||||
window.behatGetHeader = function() {
|
var behatGetHeader = function() {
|
||||||
log('Action - Get header');
|
log('Action - Get header');
|
||||||
|
|
||||||
var result = null;
|
var result = null;
|
||||||
|
@ -541,7 +541,7 @@
|
||||||
* @param {string} value New value
|
* @param {string} value New value
|
||||||
* @return {string} OK or ERROR: followed by message
|
* @return {string} OK or ERROR: followed by message
|
||||||
*/
|
*/
|
||||||
window.behatSetField = function(field, value) {
|
var behatSetField = function(field, value) {
|
||||||
log('Action - Set field ' + field + ' to: ' + value);
|
log('Action - Set field ' + field + ' to: ' + value);
|
||||||
|
|
||||||
// Find input(s) with given placeholder.
|
// Find input(s) with given placeholder.
|
||||||
|
@ -635,4 +635,13 @@
|
||||||
|
|
||||||
return 'OK';
|
return 'OK';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Make some functions publicly available for Behat to call.
|
||||||
|
window.behat = {
|
||||||
|
pressStandard : behatPressStandard,
|
||||||
|
closePopup : behatClosePopup,
|
||||||
|
press : behatPress,
|
||||||
|
setField : behatSetField,
|
||||||
|
getHeader : behatGetHeader,
|
||||||
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -358,7 +358,7 @@ class behat_app extends behat_base {
|
||||||
*/
|
*/
|
||||||
public function i_press_the_standard_button_in_the_app(string $button) {
|
public function i_press_the_standard_button_in_the_app(string $button) {
|
||||||
$this->spin(function($context, $args) use ($button) {
|
$this->spin(function($context, $args) use ($button) {
|
||||||
$result = $this->getSession()->evaluateScript('return window.behatPressStandard("' .
|
$result = $this->getSession()->evaluateScript('return window.behat.pressStandard("' .
|
||||||
$button . '");');
|
$button . '");');
|
||||||
if ($result !== 'OK') {
|
if ($result !== 'OK') {
|
||||||
throw new DriverException('Error pressing standard button - ' . $result);
|
throw new DriverException('Error pressing standard button - ' . $result);
|
||||||
|
@ -376,7 +376,7 @@ class behat_app extends behat_base {
|
||||||
*/
|
*/
|
||||||
public function i_close_the_popup_in_the_app() {
|
public function i_close_the_popup_in_the_app() {
|
||||||
$this->spin(function($context, $args) {
|
$this->spin(function($context, $args) {
|
||||||
$result = $this->getSession()->evaluateScript('return window.behatClosePopup();');
|
$result = $this->getSession()->evaluateScript('return window.behat.closePopup();');
|
||||||
if ($result !== 'OK') {
|
if ($result !== 'OK') {
|
||||||
throw new DriverException('Error closing popup - ' . $result);
|
throw new DriverException('Error closing popup - ' . $result);
|
||||||
}
|
}
|
||||||
|
@ -434,7 +434,7 @@ class behat_app extends behat_base {
|
||||||
} else {
|
} else {
|
||||||
$nearbit = '';
|
$nearbit = '';
|
||||||
}
|
}
|
||||||
$result = $context->getSession()->evaluateScript('return window.behatPress("' .
|
$result = $context->getSession()->evaluateScript('return window.behat.press("' .
|
||||||
addslashes_js($text) . '"' . $nearbit .');');
|
addslashes_js($text) . '"' . $nearbit .');');
|
||||||
if ($result !== 'OK') {
|
if ($result !== 'OK') {
|
||||||
throw new DriverException('Error pressing item - ' . $result);
|
throw new DriverException('Error pressing item - ' . $result);
|
||||||
|
@ -457,7 +457,7 @@ class behat_app extends behat_base {
|
||||||
*/
|
*/
|
||||||
public function i_set_the_field_in_the_app(string $field, string $value) {
|
public function i_set_the_field_in_the_app(string $field, string $value) {
|
||||||
$this->spin(function($context, $args) use ($field, $value) {
|
$this->spin(function($context, $args) use ($field, $value) {
|
||||||
$result = $this->getSession()->evaluateScript('return window.behatSetField("' .
|
$result = $this->getSession()->evaluateScript('return window.behat.setField("' .
|
||||||
addslashes_js($field) . '", "' . addslashes_js($value) . '");');
|
addslashes_js($field) . '", "' . addslashes_js($value) . '");');
|
||||||
if ($result !== 'OK') {
|
if ($result !== 'OK') {
|
||||||
throw new DriverException('Error setting field - ' . $result);
|
throw new DriverException('Error setting field - ' . $result);
|
||||||
|
@ -479,7 +479,7 @@ class behat_app extends behat_base {
|
||||||
*/
|
*/
|
||||||
public function the_header_should_be_in_the_app(string $text) {
|
public function the_header_should_be_in_the_app(string $text) {
|
||||||
$result = $this->spin(function($context, $args) {
|
$result = $this->spin(function($context, $args) {
|
||||||
$result = $this->getSession()->evaluateScript('return window.behatGetHeader();');
|
$result = $this->getSession()->evaluateScript('return window.behat.getHeader();');
|
||||||
if (substr($result, 0, 3) !== 'OK:') {
|
if (substr($result, 0, 3) !== 'OK:') {
|
||||||
throw new DriverException('Error getting header - ' . $result);
|
throw new DriverException('Error getting header - ' . $result);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue