From 3971e36a16a702477aea355d603319083b6f86a5 Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Sun, 12 Sep 2021 18:11:33 +0300 Subject: [PATCH 1/5] Typo --- src/Actions/Action.php | 1 + src/Actions/Click.php | 2 +- src/Actions/Keyboard.php | 2 +- src/Actions/Wait.php | 2 +- src/Contracts/Actionable.php | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Actions/Action.php b/src/Actions/Action.php index 905d0f3..d151d69 100644 --- a/src/Actions/Action.php +++ b/src/Actions/Action.php @@ -13,6 +13,7 @@ abstract class Action */ public static function new(): Actionable { + /** @var Actionable $this */ return new static(...func_get_args()); } } diff --git a/src/Actions/Click.php b/src/Actions/Click.php index 26ff3e5..8f66e24 100644 --- a/src/Actions/Click.php +++ b/src/Actions/Click.php @@ -43,7 +43,7 @@ public function __construct(string $selector, int $amount = 1, string $button = } /** - * Format to an array that can instructm and be read + * Format to an array that can instruct and be read * by the JS script to perform a specific action. * * @return array diff --git a/src/Actions/Keyboard.php b/src/Actions/Keyboard.php index 2be6b3a..0875ed2 100644 --- a/src/Actions/Keyboard.php +++ b/src/Actions/Keyboard.php @@ -73,7 +73,7 @@ public function on(string $selector) } /** - * Format to an array that can instructm and be read + * Format to an array that can instruct and be read * by the JS script to perform a specific action. * * @return array diff --git a/src/Actions/Wait.php b/src/Actions/Wait.php index 2851fbd..8fb64d1 100644 --- a/src/Actions/Wait.php +++ b/src/Actions/Wait.php @@ -25,7 +25,7 @@ public function __construct(int $seconds) } /** - * Format to an array that can instructm and be read + * Format to an array that can instruct and be read * by the JS script to perform a specific action. * * @return array diff --git a/src/Contracts/Actionable.php b/src/Contracts/Actionable.php index 1150dd0..3da4f3f 100644 --- a/src/Contracts/Actionable.php +++ b/src/Contracts/Actionable.php @@ -5,7 +5,7 @@ interface Actionable { /** - * Format to an array that can instructm and be read + * Format to an array that can instruct and be read * by the JS script to perform a specific action. * * @return array From a833971bb3e7ff745cb3228d6ede0218c2bd209f Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Sun, 12 Sep 2021 18:13:01 +0300 Subject: [PATCH 2/5] Added ->waitForSelector() --- server.js | 4 ++++ src/Actions/WaitForSelector.php | 42 +++++++++++++++++++++++++++++++++ src/Concerns/HasTimeActions.php | 13 ++++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/Actions/WaitForSelector.php diff --git a/server.js b/server.js index 3250735..252fc59 100644 --- a/server.js +++ b/server.js @@ -167,6 +167,10 @@ app.use('/healthcheck', require('express-healthcheck')()); if (action.name === 'wait') { await page.waitForTimeout(action.seconds * 1000); } + + if (action.name === 'wait-for-selector') { + await page.waitForSelector(action.selector, { timeout: action.seconds * 1000 }); + } }, Promise.resolve()); diff --git a/src/Actions/WaitForSelector.php b/src/Actions/WaitForSelector.php new file mode 100644 index 0000000..44322bd --- /dev/null +++ b/src/Actions/WaitForSelector.php @@ -0,0 +1,42 @@ +selector = $selector; + } + + /** + * Format to an array that can instruct and be read + * by the JS script to perform a specific action. + * + * @return array + */ + public function format(): array + { + return [ + 'name' => 'wait-for-selector', + 'selector' => $this->selector, + 'seconds' => $this->seconds, + ]; + } +} diff --git a/src/Concerns/HasTimeActions.php b/src/Concerns/HasTimeActions.php index f0b682b..e1a1572 100644 --- a/src/Concerns/HasTimeActions.php +++ b/src/Concerns/HasTimeActions.php @@ -3,6 +3,7 @@ namespace RenokiCo\Clusteer\Concerns; use RenokiCo\Clusteer\Actions\Wait; +use RenokiCo\Clusteer\Actions\WaitForSelector; trait HasTimeActions { @@ -16,4 +17,16 @@ public function wait(int $seconds) { return $this->action(Wait::new($seconds)); } + + /** + * Wait for a certain amount of seconds. + * + * @param string $selector + * @param int $seconds + * @return $this + */ + public function waitForSelector(string $selector, int $seconds) + { + return $this->action(WaitForSelector::new($selector, $seconds)); + } } From 10b7ab79eb6003987584284c26d5909df4caa6df Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Sun, 12 Sep 2021 18:13:16 +0300 Subject: [PATCH 3/5] Removed Node 10, PHP 7.3 Added Node 16 --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 138b385..c89e672 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,13 +19,12 @@ jobs: strategy: matrix: php: - - '7.3' - '7.4' - '8.0' node: - - '10' - '12' - '14' + - '16' laravel: - 7.* - 8.* From 30d0e57c00b0cb51d6ae0bfc13be246c4d74b12e Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Fri, 1 Oct 2021 22:27:29 +0300 Subject: [PATCH 4/5] testing --- tests/CrawlingTest.php | 13 +++++++++++++ tests/fixtures/tester.html | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/tests/CrawlingTest.php b/tests/CrawlingTest.php index 0511f0f..a2f3ffb 100644 --- a/tests/CrawlingTest.php +++ b/tests/CrawlingTest.php @@ -116,4 +116,17 @@ public function test_screenshot() file_put_contents('artifacts/test_screenshot.jpeg', $content); } + + public function test_wait_for_selector() + { + $clusteer = Clusteer::to('http://localhost:8000') + ->leftClick('#button-trigger-selector') + ->waitForSelector('#selector', 10) + ->withHtml() + ->get(); + + $this->assertTrue( + Str::contains($clusteer->getHtml(), 'Selector shown :)') + ); + } } diff --git a/tests/fixtures/tester.html b/tests/fixtures/tester.html index 3a39e1a..62c9487 100644 --- a/tests/fixtures/tester.html +++ b/tests/fixtures/tester.html @@ -20,6 +20,12 @@ > Click me with random mouse buttons +
@@ -44,6 +50,9 @@
Cookies enabled: {{ cookiesEnabled() ? 'Yes' : 'No' }}
+
+ Selector shown :) +
@@ -56,6 +65,7 @@ leftClicked: false, middleClicked: false, typedText: '', + showSelector: false, }, created() { window.addEventListener('keydown', (e) => { @@ -79,6 +89,11 @@ return cookieEnabled; }, + createWaitForTimeoutTrigger() { + setTimeout(() => { + this.showSelector = true; + }, 5000); + } }, }); From b2692f2cfd77791564cd44b654a336dd68556265 Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Fri, 1 Oct 2021 22:30:25 +0300 Subject: [PATCH 5/5] csfixing --- src/Actions/Keyboard.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Actions/Keyboard.php b/src/Actions/Keyboard.php index 0875ed2..8fd08b7 100644 --- a/src/Actions/Keyboard.php +++ b/src/Actions/Keyboard.php @@ -25,6 +25,7 @@ class Keyboard extends Action implements Actionable * Can be 'type', 'down', 'up', 'press'. * * @var string + * * @see https://pptr.dev/#?product=Puppeteer&version=v5.3.1&show=api-class-keyboard */ protected $mode = 'type';