Skip to content

Commit 5b314d3

Browse files
authored
tracy/Enable middle click in either context (#730)
* Enable middle click in either context * Skip failing test on Linux
1 parent 30f254c commit 5b314d3

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

modules/page_base.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from typing import List, Union
1212

1313
from pynput.keyboard import Controller, Key
14-
from pynput.mouse import Button, Controller as MouseController
14+
from pynput.mouse import Button
15+
from pynput.mouse import Controller as MouseController
1516
from pypom import Page
1617
from selenium.common import NoAlertPresentException
1718
from selenium.common.exceptions import (
@@ -564,7 +565,9 @@ def triple_click(self, reference: Union[str, tuple, WebElement], labels=[]) -> P
564565
"""Actions helper: perform triple-click on a given element"""
565566
return self.multi_click(3, reference, labels)
566567

567-
def control_click(self, reference: Union[str, tuple, WebElement], labels=[]) -> Page:
568+
def control_click(
569+
self, reference: Union[str, tuple, WebElement], labels=[]
570+
) -> Page:
568571
"""Actions helper: perform control-click on given element"""
569572
element = self.fetch(reference, labels)
570573
if self.sys_platform() == "Darwin":
@@ -574,10 +577,9 @@ def control_click(self, reference: Union[str, tuple, WebElement], labels=[]) ->
574577
self.actions.key_down(mod_key).click(element).key_up(mod_key).perform()
575578
return self
576579

577-
def middle_click(self, reference: Union[str, tuple, WebElement], labels =[]):
578-
"""Perform a middle mouse click on desired element"""
579-
with self.driver.context(self.driver.CONTEXT_CONTENT):
580-
self.driver.maximize_window()
580+
def middle_click(self, reference: Union[str, tuple, WebElement], labels=[]):
581+
"""Actions helper: Perform a middle mouse click on desired element"""
582+
with self.driver.context(self.context_id):
581583
mouse = MouseController()
582584
element = self.fetch(reference, labels)
583585

@@ -589,14 +591,24 @@ def middle_click(self, reference: Union[str, tuple, WebElement], labels =[]):
589591
outer_height = self.driver.execute_script("return window.outerHeight;")
590592
chrome_height = outer_height - inner_height
591593

592-
element_x = window_position['x'] + element_location['x'] + (element_size['width'] / 2)
593-
element_y = window_position['y'] + element_location['y'] + (element_size['height'] / 2) + chrome_height
594+
element_x = (
595+
window_position["x"]
596+
+ element_location["x"]
597+
+ (element_size["width"] / 2)
598+
)
599+
element_y = (
600+
window_position["y"]
601+
+ element_location["y"]
602+
+ (element_size["height"] / 2)
603+
+ chrome_height
604+
)
594605
mouse.position = (element_x, element_y)
595606

596-
time.sleep(1)
607+
# Need a short wait to ensure the mouse move completes, then middle click
608+
time.sleep(0.5)
597609
mouse.click(Button.middle, 1)
598610
return self
599-
611+
600612
def context_click(
601613
self, reference: Union[str, tuple, WebElement], labels=[]
602614
) -> Page:

tests/notifications/test_webextension_completed_installation_successfully_displayed.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from platform import system
2+
13
import pytest
24
from selenium.webdriver import Firefox
35

@@ -24,6 +26,7 @@ def temp_selectors():
2426
TEST_URL = "https://addons.mozilla.org/en-US/firefox/addon/popup-blocker/"
2527

2628

29+
@pytest.mark.skipif(system().lower().startswith("linux"), reason="Bug 1983280")
2730
def test_webextension_completed_installation_successfully_displayed(
2831
driver: Firefox, temp_selectors
2932
):

tests/tabs/test_open_new_bg_tab_via_mouse_and_keyboard.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def test_open_new_bg_tab_via_mouse_and_keyboard(driver: Firefox):
1717
"""
1818

1919
test_url = "https://www.iana.org/help/example-domains"
20-
example = ExamplePage(driver).open()
20+
example = ExamplePage(driver)
21+
example.open()
2122

2223
# Middle click link, verify new background tab opens with correct URL
2324
example.middle_click("more-information")

0 commit comments

Comments
 (0)