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

Draging (which involves a click) also needs to scroll into view #13

Merged
merged 4 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1023,16 +1023,17 @@ public function dragTo(string $sourceXpath, string $destinationXpath)
$destination = $this->findElement($destinationXpath);

if ($this->isW3C()) {
$this->scrollElementIntoView($source);
$actions = array(
'actions' => [
[
'type' => 'pointer',
'id' => 'mouse1',
'parameters' => ['pointerType' => 'mouse'],
'actions' => [
['type' => 'pointerMove', 'duration' => 0, 'origin' => [Element::WEB_ELEMENT_ID => $this->findElement($sourceXpath)->getID()], 'x' => 0, 'y' => 0],
['type' => 'pointerMove', 'duration' => 0, 'origin' => [Element::WEB_ELEMENT_ID => $source->getID()], 'x' => 0, 'y' => 0],
['type' => 'pointerDown', "button" => 0],
['type' => 'pointerMove', 'duration' => 0, 'origin' => [Element::WEB_ELEMENT_ID => $this->findElement($destinationXpath)->getID()], 'x' => 0, 'y' => 0],
['type' => 'pointerMove', 'duration' => 0, 'origin' => [Element::WEB_ELEMENT_ID => $destination->getID()], 'x' => 0, 'y' => 0],
['type' => 'pointerUp', "button" => 0],
],
],
Expand Down
32 changes: 28 additions & 4 deletions tests/Custom/LargePageClickTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,40 @@ public function testLargePageClick(): void
$this->getSession()->visit($this->pathTo('/multi_input_form.html'));

// Add a large amount of br tags so that the button is not in view.
$this->makePageLong();

$page = $this->getSession()->getPage();
$page->pressButton('Register');
$this->assertStringContainsString('no file', $page->getContent());
}

public function testDragDrop(): void
{
$this->getSession()->visit($this->pathTo('/js_test.html'));
// Add a large amount of br tags so that the draggable area is not in
// view.
$this->makePageLong();

$webAssert = $this->getAssertSession();

$draggable = $webAssert->elementExists('css', '#draggable');
$droppable = $webAssert->elementExists('css', '#droppable');

$draggable->dragTo($droppable);
$this->assertSame('Dropped left!', $webAssert->elementExists('css', 'p', $droppable)->getText());
}

/**
* Makes the page really long by inserting br tags at the top.
*/
private function makePageLong(): void {
$large_page = str_repeat('<br />', 2000);
$script = <<<JS
const p = document.createElement("div");
p.innerHTML = "$large_page";
document.body.insertBefore(p, document.body.firstChild);
JS;
$this->getSession()->executeScript($script);

$page = $this->getSession()->getPage();
$page->pressButton('Register');
$this->assertStringContainsString('no file', $page->getContent());
}

}
Loading