MOBILE-4061 behat: Native handle of skip on boarding
parent
92d4a6a16b
commit
97862f40f5
|
@ -470,7 +470,6 @@ class behat_app extends behat_base {
|
||||||
*/
|
*/
|
||||||
protected function prepare_browser(array $options = []) {
|
protected function prepare_browser(array $options = []) {
|
||||||
$restart = $options['restart'] ?? true;
|
$restart = $options['restart'] ?? true;
|
||||||
$skiponboarding = $options['skiponboarding'] ?? true;
|
|
||||||
|
|
||||||
if ($restart) {
|
if ($restart) {
|
||||||
if ($this->apprunning) {
|
if ($this->apprunning) {
|
||||||
|
@ -509,32 +508,23 @@ class behat_app extends behat_base {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Init Behat JavaScript runtime.
|
// Init Behat JavaScript runtime.
|
||||||
$this->execute_script('window.behatInit();');
|
|
||||||
|
$initOptions = new StdClass();
|
||||||
|
$initOptions->skipOnBoarding = $options['skiponboarding'] ?? true;
|
||||||
|
$initOptions->configOverrides = $this->appconfig;
|
||||||
|
|
||||||
|
$this->execute_script('window.behatInit(' . json_encode($initOptions) . ');');
|
||||||
} catch (Exception $error) {
|
} catch (Exception $error) {
|
||||||
throw new DriverException('Moodle app not running or not running on Automated mode.');
|
throw new DriverException('Moodle app not running or not running on Automated mode.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($restart) {
|
if ($restart) {
|
||||||
// Assert initial page.
|
// Assert initial page.
|
||||||
$this->spin(function($context) use ($skiponboarding) {
|
$this->spin(function($context) {
|
||||||
$page = $context->getSession()->getPage();
|
$page = $context->getSession()->getPage();
|
||||||
$element = $page->find('xpath', '//page-core-login-site//input[@name="url"]');
|
$element = $page->find('xpath', '//page-core-login-site//input[@name="url"]');
|
||||||
|
|
||||||
if ($element) {
|
if ($element) {
|
||||||
if (!$skiponboarding) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for the onboarding modal to open, if any.
|
|
||||||
$this->wait_for_pending_js();
|
|
||||||
|
|
||||||
$element = $page->find('xpath', '//core-login-site-onboarding');
|
|
||||||
|
|
||||||
if ($element) {
|
|
||||||
$this->i_press_in_the_app('"Skip"');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Login screen found.
|
// Login screen found.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -548,12 +538,6 @@ class behat_app extends behat_base {
|
||||||
}, false, 60);
|
}, false, 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare testing config.
|
|
||||||
$configoverrides = json_encode($this->appconfig);
|
|
||||||
|
|
||||||
$this->evaluate_script("document.cookie='MoodleAppConfig=$configoverrides'");
|
|
||||||
$this->evaluate_script("configProvider.patchEnvironment($configoverrides)");
|
|
||||||
|
|
||||||
// Continue only after JS finishes.
|
// Continue only after JS finishes.
|
||||||
$this->wait_for_pending_js();
|
$this->wait_for_pending_js();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,14 @@ Feature: Test basic usage of login in app
|
||||||
| student2 | C1 | student |
|
| student2 | C1 | student |
|
||||||
| teacher1 | C1 | editingteacher |
|
| teacher1 | C1 | editingteacher |
|
||||||
|
|
||||||
|
Scenario: Skip on boarding
|
||||||
|
When I launch the app runtime
|
||||||
|
Then I should find "Welcome to the Moodle App!" in the app
|
||||||
|
|
||||||
|
When I press "Skip" in the app
|
||||||
|
Then I should not find "Skip" in the app
|
||||||
|
And I should find "Connect to Moodle" in the app
|
||||||
|
|
||||||
Scenario: Add a new account in the app & Site name in displayed when adding a new account
|
Scenario: Add a new account in the app & Site name in displayed when adding a new account
|
||||||
When I enter the app
|
When I enter the app
|
||||||
And I press the back button in the app
|
And I press the back button in the app
|
||||||
|
|
|
@ -15,13 +15,21 @@
|
||||||
import { TestsBehatDomUtils } from './behat-dom';
|
import { TestsBehatDomUtils } from './behat-dom';
|
||||||
import { TestsBehatBlocking } from './behat-blocking';
|
import { TestsBehatBlocking } from './behat-blocking';
|
||||||
import { CoreCustomURLSchemes } from '@services/urlschemes';
|
import { CoreCustomURLSchemes } from '@services/urlschemes';
|
||||||
|
import { CoreLoginHelperProvider } from '@features/login/services/login-helper';
|
||||||
|
import { CoreConfig } from '@services/config';
|
||||||
|
import { EnvironmentConfig } from '@/types/config';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Behat runtime servive with public API.
|
* Behat runtime servive with public API.
|
||||||
*/
|
*/
|
||||||
export class TestsBehatRuntime {
|
export class TestsBehatRuntime {
|
||||||
|
|
||||||
static init(): void {
|
/**
|
||||||
|
* Init behat functions and set options like skipping onboarding.
|
||||||
|
*
|
||||||
|
* @param options Options to set on the app.
|
||||||
|
*/
|
||||||
|
static init(options?: TestsBehatInitOptions): void {
|
||||||
TestsBehatBlocking.init();
|
TestsBehatBlocking.init();
|
||||||
|
|
||||||
(window as BehatTestsWindow).behat = {
|
(window as BehatTestsWindow).behat = {
|
||||||
|
@ -38,6 +46,20 @@ export class TestsBehatRuntime {
|
||||||
setField: TestsBehatRuntime.setField,
|
setField: TestsBehatRuntime.setField,
|
||||||
handleCustomURL: TestsBehatRuntime.handleCustomURL,
|
handleCustomURL: TestsBehatRuntime.handleCustomURL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!options) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.skipOnBoarding === true) {
|
||||||
|
CoreConfig.set(CoreLoginHelperProvider.ONBOARDING_DONE, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.configOverrides) {
|
||||||
|
// Set the cookie so it's maintained between reloads.
|
||||||
|
document.cookie = 'MoodleAppConfig=' + JSON.stringify(options.configOverrides);
|
||||||
|
CoreConfig.patchEnvironment(options.configOverrides);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -407,3 +429,8 @@ export type TestBehatElementLocator = {
|
||||||
near?: TestBehatElementLocator;
|
near?: TestBehatElementLocator;
|
||||||
selector?: string;
|
selector?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type TestsBehatInitOptions = {
|
||||||
|
skipOnBoarding?: boolean;
|
||||||
|
configOverrides?: Partial<EnvironmentConfig>;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue