Skip to content
Snippets Groups Projects
Commit f3e27404 authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

feature(account): choose

parent 732dbc59
No related branches found
No related tags found
1 merge request!2feature(account): choose
Pipeline #244266 passed
## [1.0.1] - 2023-08-17
### Fixed
- account choose
## [1.0.0] - 2023-08-17 ## [1.0.0] - 2023-08-17
### Added ### Added
- initial version - initial version
...@@ -12,20 +12,67 @@ class Shopify extends WebDriver ...@@ -12,20 +12,67 @@ class Shopify extends WebDriver
public function loginAsAdmin(): void public function loginAsAdmin(): void
{ {
$i = $this; $i = $this;
$isPl = false;
if ($i->loadSessionSnapshot('admin')) { if ($i->loadSessionSnapshot('admin')) {
return; return;
} }
$i->amOnUrl($this->config['admin_url']); $i->amOnUrl($this->config['admin_url']);
try { try {
$i->moveMouseOver('body', rand(1, 100), rand(1, 100)); $this->amLoggedInAsAdmin($i);
$i->seeInCurrentUrl(parse_url($this->config['admin_url'], PHP_URL_PATH));
} catch (Exception $e) { } catch (Exception $e) {
try {
$i->wait(rand(1, 2)); $i->wait(rand(1, 2));
$i->see('Choose an account');
$i->click($this->config['admin_username']);
} catch (Exception $e) {
$this->loginWithGoogle($i);
}
}
$i->wait(rand(1, 5));
$i->saveSessionSnapshot('admin');
}
public function amOnPage($page): void
{
parent::amOnPage($page);
$this->loginOnFront();
}
public function loginOnFront(): void
{
$i = $this;
try {
$i->seeInCurrentUrl('password');
$i->fillField('password', $this->config['store_password']);
$i->click('button[type=submit]');
} catch (Exception $e) {
// do nothing
}
}
/**
* @param Shopify $i
*
* @return void
*/
private function amLoggedInAsAdmin(Shopify $i): void
{
$i->moveMouseOver('body', rand(1, 100), rand(1, 100));
$i->seeInCurrentUrl(parse_url($this->config['admin_url'], PHP_URL_PATH));
}
/**
* @param Shopify $i
*
* @return void
* @throws Exception
*/
private function loginWithGoogle(Shopify $i): void
{
$isPl = false;
try { try {
$i->waitForText('Continue with Google', 10); $i->waitForText('Continue with Google', 5);
} catch (Exception $e) { } catch (Exception $e) {
$i->waitForText('Kontynuuj z Google', 30); $i->waitForText('Kontynuuj z Google', 5);
$isPl = true; $isPl = true;
} }
$i->click($isPl ? 'Kontynuuj z Google' : 'Continue with Google'); $i->click($isPl ? 'Kontynuuj z Google' : 'Continue with Google');
...@@ -35,10 +82,24 @@ class Shopify extends WebDriver ...@@ -35,10 +82,24 @@ class Shopify extends WebDriver
} catch (Exception $e) { } catch (Exception $e) {
try { try {
$i->waitForText($this->config['admin_username']); $i->waitForText($this->config['admin_username']);
$i->clickWithLeftButton(Locator::find('div', ['data-email' => $this->config['admin_username']])); $i->clickWithLeftButton(Locator::find('div',
['data-email' => $this->config['admin_username']]));
$i->seeInCurrentUrl(parse_url($this->config['admin_url'], PHP_URL_PATH)); $i->seeInCurrentUrl(parse_url($this->config['admin_url'], PHP_URL_PATH));
$i->dontSeeInCurrentUrl('google.com'); $i->dontSeeInCurrentUrl('google.com');
} catch (Exception $e) { } catch (Exception $e) {
$this->loginToGoogle($i, $isPl);
}
}
}
/**
* @param Shopify $i
* @param bool $isPl
*
* @return void
*/
private function loginToGoogle(Shopify $i, bool $isPl): void
{
$i->wait(rand(1, 5)); $i->wait(rand(1, 5));
$i->moveMouseOver('body', rand(1, 100), rand(1, 100)); $i->moveMouseOver('body', rand(1, 100), rand(1, 100));
try { try {
...@@ -56,28 +117,5 @@ class Shopify extends WebDriver ...@@ -56,28 +117,5 @@ class Shopify extends WebDriver
$i->click($isPl ? 'Dalej' : 'Next'); $i->click($isPl ? 'Dalej' : 'Next');
} }
} }
}
}
$i->wait(rand(1, 5));
$i->saveSessionSnapshot('admin');
}
public function amOnPage($page): void
{
parent::amOnPage($page);
$this->loginOnFront();
}
public function loginOnFront(): void
{
$i = $this;
try {
$i->seeInCurrentUrl('password');
$i->fillField('password', $this->config['store_password']);
$i->click('button[type=submit]');
} catch (Exception $e) {
// do nothing
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment