From 7cdd82c4c2d0e524465712573d0a39af5d10e67b Mon Sep 17 00:00:00 2001 From: Grzegorz Rola <grola@seostudio.pl> Date: Thu, 17 Aug 2023 14:03:11 +0200 Subject: [PATCH] feature(init): init --- src/Shopify.php | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/Shopify.php b/src/Shopify.php index 4da3f9d..db6e113 100644 --- a/src/Shopify.php +++ b/src/Shopify.php @@ -1,8 +1,64 @@ <?php +declare(strict_types=1); + namespace Octolize\Shopify\Codeception; +use Exception; + class Shopify extends \Codeception\Module { + public function loginAsAdmin() + { + $i = $this->getModule('WebDriver'); + $isPl = false; + if ($i->loadSessionSnapshot('admin')) { + return; + } + $i->amOnUrl($this->config['admin_url']); + try { + $i->moveMouseOver('body', rand(1, 100), rand(1, 100)); + $i->seeInCurrentUrl(parse_url($this->config['admin_url'], PHP_URL_PATH)); + } catch (Exception $e) { + $i->wait(rand(1, 2)); + try { + $i->waitForText('Continue with Google', 10); + } catch (Exception $e) { + $i->waitForText('Kontynuuj z Google', 30); + $isPl = true; + } + $i->click($isPl?'Kontynuuj z Google':'Continue with Google'); + try { + $i->seeInCurrentUrl(parse_url($this->config['admin_url'], PHP_URL_PATH)); + $i->dontSeeInCurrentUrl('google.com'); + } catch (Exception $e) { + try { + $i->waitForText($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->dontSeeInCurrentUrl('google.com'); + } catch (Exception $e) { + $i->wait(rand(1, 5)); + $i->moveMouseOver('body', rand(1, 100), rand(1, 100)); + try { + $i->seeElement('input[name="identifier"]'); + $i->fillField('identifier', $this->config['admin_username']); + $i->click($isPl ? 'Dalej' : 'Next'); + $i->wait(rand(1, 5)); + $i->moveMouseOver('input[name=Passwd]', rand(1, 100), rand(1, 100)); + $i->fillField('Passwd', $this->config['google_password']); + $i->click($isPl ? 'Dalej' : 'Next'); + } catch (Exception $e) { + $i->wait(rand(1, 5)); + $i->moveMouseOver('body', rand(1, 100), rand(1, 100)); + $i->fillField('password', $this->config['google_password']); + $i->click($isPl ? 'Dalej' : 'Next'); + } + } + } + } + $i->saveSessionSnapshot('admin'); + } + } -- GitLab