Last active
August 9, 2017 08:31
-
-
Save yucer/047036efa3b72195571572c7fbb6709d to your computer and use it in GitHub Desktop.
Marionette tests scripts for opening new tabs with legacy key combinations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This Source Code Form is subject to the terms of the Mozilla Public | |
# License, v. 2.0. If a copy of the MPL was not distributed with this | |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
# locate the test script in mozilla-central repository | |
# path: testing/marionette/harness/marionette_harness/tests/unit/test_key_newtabs.py | |
# | |
# and tun it via: | |
# | |
# ./mach marionette-test testing/marionette/harness/marionette_harness/tests/unit/test_key_newtabs.py -vv --gecko-log - | |
import types | |
from marionette_driver.by import By | |
from marionette_driver.keys import Keys | |
from marionette_driver.marionette import Actions | |
from marionette_harness import MarionetteTestCase, skip_if_mobile, WindowManagerMixin | |
class TestKeyActions(WindowManagerMixin, MarionetteTestCase): | |
def setUp(self): | |
super(TestKeyActions, self).setUp() | |
if self.marionette.session_capabilities["platformName"] == "darwin": | |
self.mod_key = Keys.META | |
else: | |
self.mod_key = Keys.CONTROL | |
test_html = self.marionette.absolute_url("javascriptPage.html") | |
self.marionette.navigate(test_html) | |
self.reporter_element = self.marionette.find_element(By.ID, "keyReporter") | |
self.reporter_element.click() | |
self.key_action = Actions(self.marionette) | |
@property | |
def key_reporter_value(self): | |
return self.reporter_element.get_property("value") | |
# working test cases | |
def test_newtab_via_menu(self): | |
self.open_tab('menu') | |
self.assert_newtab() | |
def test_uppercase_text_via_sendkeys(self): | |
self.reporter_element.send_keys(Keys.SHIFT + "abc" + Keys.SHIFT + "def") | |
self.assertEqual(self.key_reporter_value, "ABCdef") | |
def test_undo_via_element_sendkeys(self): | |
self.reporter_element.send_keys("abcdef" + Keys.CONTROL + "z" + Keys.CONTROL + "123456") | |
self.assertEqual(self.key_reporter_value, "123456") | |
# non-working test cases | |
def test_newtab_via_element_sendkeys(self): | |
self.reporter_element.send_keys(Keys.CONTROL + "t" + Keys.CONTROL) | |
self.assert_newtab() | |
def test_newtab_via_keyactions(self): | |
(self.key_action.key_down(self.mod_key) # Keys.CONTROL in linux | |
.key_down("t") | |
.key_up(self.mod_key) | |
.perform()) | |
self.assert_newtab() | |
# utility methods | |
def newtabs_open(self): | |
return len(self.marionette.window_handles) > len(self.start_tabs) | |
def assert_newtab(self): | |
newtabs_open = self.newtabs_open() | |
self.close_all_tabs() | |
self.assertTrue(newtabs_open, msg="No newtab has been opened") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment