Skip to content

Rework and fix smoke test for browser tabs #712

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

Closed
wants to merge 2 commits into from
Closed
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
34 changes: 34 additions & 0 deletions modules/page_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import List, Union

from pynput.keyboard import Controller, Key
from pynput.mouse import Button, Controller
from pypom import Page
from selenium.common import NoAlertPresentException
from selenium.common.exceptions import (
Expand Down Expand Up @@ -558,6 +559,39 @@ def triple_click(self, reference: Union[str, tuple, WebElement], labels=[]) -> P
"""Actions helper: perform triple-click on a given element"""
return self.multi_click(3, reference, labels)

def control_click(self, reference: Union[str, tuple, WebElement], labels=[]) -> Page:
"""Actions helper: perform control-click on given element"""
element = self.fetch(reference, labels)
if self.sys_platform() == "Darwin":
mod_key = Keys.COMMAND
else:
mod_key = Keys.CONTROL
self.actions.key_down(mod_key).click(element).key_up(mod_key).perform()
return self

def middle_click(self, reference: Union[str, tuple, WebElement], labels =[]):
"""Perform a middle mouse click on desired element"""
with self.driver.context(self.driver.CONTEXT_CONTENT):
self.driver.maximize_window()
mouse = Controller()
element = self.fetch(reference, labels)

element_location = element.location
element_size = element.size
window_position = self.driver.get_window_position()

inner_height = self.driver.execute_script("return window.innerHeight;")
outer_height = self.driver.execute_script("return window.outerHeight;")
chrome_height = outer_height - inner_height

element_x = window_position['x'] + element_location['x'] + (element_size['width'] / 2)
element_y = window_position['y'] + element_location['y'] + (element_size['height'] / 2) + chrome_height
mouse.position = (element_x, element_y)

time.sleep(1)
mouse.click(Button.middle, 1)
return self

def context_click(
self, reference: Union[str, tuple, WebElement], labels=[]
) -> Page:
Expand Down
39 changes: 39 additions & 0 deletions tests/tabs/test_open_new_bg_tab_via_mouse_and_keyboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pytest
from selenium.webdriver import Firefox
from selenium.webdriver.common.by import By

from modules.page_object import ExamplePage


@pytest.fixture()
def test_case():
return "134455"


@pytest.mark.headed
def test_open_new_bg_tab_via_mouse_and_keyboard(driver: Firefox):
"""
C134455 - Verify that opening hyperlink with mouse or keyboard
shortcuts creates new background tabs
"""

test_url = "https://www.iana.org/help/example-domains"
example = ExamplePage(driver).open()

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

assert driver.current_url == test_url

# Close new tab, switch back to original example page
driver.close()
example.switch_to_new_tab()

# Control click link, verify new background tab opens with correct URL
example.control_click("more-information")
example.wait_for_num_tabs(2)
example.switch_to_new_tab()

assert driver.current_url == test_url