Skip to content

Commit

Permalink
Merge pull request #13 from alexpott/FIX-firefox-drag
Browse files Browse the repository at this point in the history
Draging (which involves a click) also needs to scroll into view
  • Loading branch information
justafish authored Aug 8, 2024
2 parents f2dcde0 + fff9d26 commit 4f679e6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
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());
}

}

0 comments on commit 4f679e6

Please sign in to comment.