Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Keyboard Support Improvements #1053

Merged
merged 14 commits into from
Sep 4, 2023
Merged

[7.x] Keyboard Support Improvements #1053

merged 14 commits into from
Sep 4, 2023

Conversation

crynobone
Copy link
Member

@crynobone crynobone commented Aug 28, 2023

Before

$key = PHP_OS_FAMILY === 'Darwin' ? \Facebook\WebDriver\WebDriverKeys::COMMAND : \Facebook\WebDriver\WebDriverKeys::CONTROL;

$this->browse(function (Browser $browser) use ($key) {
    $browser
        ->visit('/first')
        // ...
        ->tap(function (Browser $browser) use ($key) {
            $browser->driver->getKeyboard()->pressKey($key);
        })
        ->click('@link.to.second')
        ->tap(function (Browser $browser) use ($key) {
            $browser->driver->getKeyboard()->releaseKey($key);
        })
        // ...
    ;
});

After

$key = PHP_OS_FAMILY === 'Darwin' ? \Facebook\WebDriver\WebDriverKeys::COMMAND : \Facebook\WebDriver\WebDriverKeys::CONTROL;

$this->browse(function (Browser $browser) use ($key) {
    $browser
        ->visit('/first')
        // ...
        ->usesKeyboard(function (Keyboard $keyboard) use ($key) {
            $keyboard->press($key);
            $keyboard->browser->click('@link.to.second');
            $keyboard->release($key);
        }) 
        // or alternatively
        ->controlClick('@link.to.second')
        // ...
    ;
});

crynobone and others added 8 commits August 28, 2023 12:31
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@crynobone crynobone changed the title Uses keyboard [7.x] Keyboard Support Improvements Aug 28, 2023
@crynobone crynobone marked this pull request as ready for review August 28, 2023 05:02
@crynobone crynobone marked this pull request as draft August 28, 2023 05:02
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@crynobone crynobone marked this pull request as ready for review August 29, 2023 04:54
crynobone and others added 2 commits August 29, 2023 16:44
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
public function controlClick($selector = null)
{
return $this->withKeyboard(function (Keyboard $keyboard) use ($selector) {
$key = OperatingSystem::onMac() ? WebDriverKeys::META : WebDriverKeys::CONTROL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite follow this part. On my macOS keyboard I have a control key and a "meta" / command key. Why do we use the meta key for Mac here if some Mac keyboards have an actual control key?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COMMAND and META represent the same keystroke in Mac : https://github.com/php-webdriver/php-webdriver/blob/a1578689290055586f1ee51eaf0ec9d52895bb6d/lib/WebDriverKeys.php#L90

The primary issue here is that Windows uses Control+click while Mac uses Command+click to trigger open in new tab. Similar issue can occur for action combo such as copy text etc.

@taylorotwell taylorotwell merged commit d9c722c into 7.x Sep 4, 2023
@taylorotwell taylorotwell deleted the uses-keyboard branch September 4, 2023 15:59
crynobone added a commit to laravel/docs that referenced this pull request Sep 6, 2023
PR: laravel/dusk#1053

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
crynobone added a commit to laravel/docs that referenced this pull request Sep 6, 2023
PR: laravel/dusk#1053

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
taylorotwell added a commit to laravel/docs that referenced this pull request Sep 6, 2023
* [10.x] Dusk - Add Keyboard Support Improvements documentation

PR: laravel/dusk#1053

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* formatting

* formatting

---------

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Co-authored-by: Taylor Otwell <taylor@laravel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants