commit
e5e1ae6df8
|
@ -518,6 +518,9 @@
|
||||||
near: { text: 'Notifications' },
|
near: { text: 'Notifications' },
|
||||||
})[0];
|
})[0];
|
||||||
break;
|
break;
|
||||||
|
case 'page menu':
|
||||||
|
foundButton = findElementsBasedOnText({ text: 'Display options' })[0];
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return 'ERROR: Unsupported standard button type';
|
return 'ERROR: Unsupported standard button type';
|
||||||
}
|
}
|
||||||
|
|
|
@ -789,14 +789,16 @@ class behat_app extends behat_base {
|
||||||
/**
|
/**
|
||||||
* Check that the app opened a new browser tab.
|
* Check that the app opened a new browser tab.
|
||||||
*
|
*
|
||||||
* @Given /^the app should( not)? have opened a browser tab$/
|
* @Given /^the app should( not)? have opened a browser tab(?: with url "(?P<pattern>[^"]+)")?$/
|
||||||
* @param bool $not
|
* @param bool $not
|
||||||
|
* @param string $urlpattern
|
||||||
*/
|
*/
|
||||||
public function the_app_should_have_opened_a_browser_tab(bool $not = false) {
|
public function the_app_should_have_opened_a_browser_tab(bool $not = false, ?string $urlpattern = null) {
|
||||||
$this->spin(function() use ($not) {
|
$this->spin(function() use ($not, $urlpattern) {
|
||||||
$openedbrowsertab = count($this->getSession()->getWindowNames()) === 2;
|
$windownames = $this->getSession()->getWindowNames();
|
||||||
|
$openedbrowsertab = count($windownames) === 2;
|
||||||
|
|
||||||
if ($not === $openedbrowsertab) {
|
if ((!$not && !$openedbrowsertab) || ($not && $openedbrowsertab && is_null($urlpattern))) {
|
||||||
throw new ExpectationException(
|
throw new ExpectationException(
|
||||||
$not
|
$not
|
||||||
? 'Did not expect the app to have opened a browser tab'
|
? 'Did not expect the app to have opened a browser tab'
|
||||||
|
@ -805,6 +807,22 @@ class behat_app extends behat_base {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!is_null($urlpattern)) {
|
||||||
|
$this->getSession()->switchToWindow($windownames[1]);
|
||||||
|
$windowurl = $this->getSession()->getCurrentUrl();
|
||||||
|
$windowhaspattern = preg_match("/$urlpattern/", $windowurl);
|
||||||
|
$this->getSession()->switchToWindow($windownames[0]);
|
||||||
|
|
||||||
|
if ($not === $windowhaspattern) {
|
||||||
|
throw new ExpectationException(
|
||||||
|
$not
|
||||||
|
? "Did not expect the app to have opened a browser tab with pattern '$urlpattern'"
|
||||||
|
: "Browser tab url does not match pattern '$urlpattern', it is '$windowurl'",
|
||||||
|
$this->getSession()->getDriver()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -895,6 +913,11 @@ class behat_app extends behat_base {
|
||||||
if (count($names) !== 2) {
|
if (count($names) !== 2) {
|
||||||
throw new DriverException('Expected to see 2 tabs open, not ' . count($names));
|
throw new DriverException('Expected to see 2 tabs open, not ' . count($names));
|
||||||
}
|
}
|
||||||
|
// Make sure the browser tab is selected.
|
||||||
|
if ($this->getSession()->getWindowName() !== $names[1]) {
|
||||||
|
$this->getSession()->switchToWindow($names[1]);
|
||||||
|
}
|
||||||
|
|
||||||
$this->execute_script('window.close()');
|
$this->execute_script('window.close()');
|
||||||
$this->getSession()->switchToWindow($names[0]);
|
$this->getSession()->switchToWindow($names[0]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
@app @javascript
|
||||||
|
Feature: It opens external links properly.
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given the following "users" exist:
|
||||||
|
| username |
|
||||||
|
| student1 |
|
||||||
|
And the following "courses" exist:
|
||||||
|
| fullname | shortname |
|
||||||
|
| Course 1 | C1 |
|
||||||
|
And the following "course enrolments" exist:
|
||||||
|
| user | course | role |
|
||||||
|
| student1 | C1 | student |
|
||||||
|
And the following "activities" exist:
|
||||||
|
| activity | name | intro | course | idnumber |
|
||||||
|
| forum | Test forum | Test forum | C1 | forum |
|
||||||
|
And the following forum discussions exist in course "Course 1":
|
||||||
|
| forum | user | name | message |
|
||||||
|
| Test forum | student1 | Forum topic | See <a href="https://moodle.org/">moodle.org</a> |
|
||||||
|
|
||||||
|
Scenario: Click an external link
|
||||||
|
When I enter the app
|
||||||
|
And I log in as "student1"
|
||||||
|
And I press "Course 1" near "Course overview" in the app
|
||||||
|
And I press "Test forum" in the app
|
||||||
|
And I press "Forum topic" in the app
|
||||||
|
And I press "moodle.org" in the app
|
||||||
|
Then I should find "You are about to leave the app" in the app
|
||||||
|
|
||||||
|
When I press "Cancel" in the app
|
||||||
|
And I press "moodle.org" in the app
|
||||||
|
And I press "OK" in the app
|
||||||
|
Then the app should have opened a browser tab with url "moodle.org"
|
||||||
|
|
||||||
|
When I close the browser tab opened by the app
|
||||||
|
And I press the back button in the app
|
||||||
|
And I press the page menu button in the app
|
||||||
|
And I press "Open in browser" in the app
|
||||||
|
Then the app should have opened a browser tab
|
||||||
|
|
||||||
|
When I close the browser tab opened by the app
|
||||||
|
And I press "Forum topic" in the app
|
||||||
|
And I press "moodle.org" in the app
|
||||||
|
And I select "Don't show again." in the app
|
||||||
|
And I press "OK" in the app
|
||||||
|
And I close the browser tab opened by the app
|
||||||
|
And I press "moodle.org" in the app
|
||||||
|
Then the app should have opened a browser tab with url "moodle.org"
|
Loading…
Reference in New Issue