-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from jrusz/ClipboardCopy
Add ClipboardCopy
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from widgetastic.utils import ParametrizedLocator | ||
from widgetastic.widget import TextInput | ||
from widgetastic.widget import View | ||
|
||
from widgetastic_patternfly4.button import Button | ||
|
||
|
||
class BaseClipboardCopy: | ||
BUTTON_LOC = ".//button[contains(@class, 'pf-c-button pf-m-control')]" | ||
TEXT_LOC = ".//input[contains(@class, 'pf-c-form-control')]" | ||
|
||
@property | ||
def is_editable(self): | ||
if self.browser.get_attribute("readonly", self.text): | ||
return False | ||
else: | ||
return True | ||
|
||
def __init__(self, parent, locator=None, logger=None): | ||
super().__init__(parent, logger=logger) | ||
if locator: | ||
self.locator = locator | ||
else: | ||
self.locator = self.DEFAULT_LOCATOR | ||
|
||
|
||
class ClipboardCopy(BaseClipboardCopy, View): | ||
ROOT = ParametrizedLocator("{@locator}") | ||
DEFAULT_LOCATOR = ".//div[contains(@class,'pf-c-clipboard-copy')]" | ||
|
||
text = TextInput(locator=BaseClipboardCopy.TEXT_LOC) | ||
button = Button(locator=BaseClipboardCopy.BUTTON_LOC) | ||
|
||
def read(self): | ||
return self.text.value | ||
|
||
def fill(self, value): | ||
return self.text.fill(value) | ||
|
||
def copy(self): | ||
self.button.click() |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import pytest | ||
from widgetastic.widget import View | ||
|
||
from widgetastic_patternfly4 import ClipboardCopy | ||
|
||
TESTING_PAGE_URL = "https://patternfly-react.surge.sh/components/clipboard-copy" | ||
|
||
|
||
@pytest.fixture | ||
def view(browser): | ||
class TestView(View): | ||
ROOT = ".//div[@id='ws-react-c-clipboard-copy-basic']" | ||
clipboardEditable = ClipboardCopy(locator="//div[@id='ws-react-c-clipboard-copy-basic']") | ||
clipboardReadOnly = ClipboardCopy( | ||
locator="//div[@id='ws-react-c-clipboard-copy-read-only']" | ||
) | ||
|
||
return TestView(browser) | ||
|
||
|
||
def test_clipboardcopy_displayed(view): | ||
assert view.clipboardEditable.is_displayed | ||
|
||
|
||
def test_clipboardcopy_is_editable(view): | ||
assert view.clipboardEditable.is_editable | ||
|
||
|
||
def test_clipboardcopy_is_read_only(view): | ||
assert view.clipboardReadOnly.is_editable is False | ||
|
||
|
||
def test_clipboardcopy_text(view): | ||
assert view.clipboardEditable.read() == "This is editable" | ||
|
||
assert view.clipboardEditable.fill("Test") | ||
assert view.clipboardEditable.read() == "Test" | ||
|
||
assert view.clipboardReadOnly.read() == "This is read-only" | ||
|
||
|
||
def test_clipboardcopy_copy(view): | ||
assert view.clipboardEditable.button.is_displayed | ||
assert view.clipboardReadOnly.button.is_displayed | ||
view.clipboardReadOnly.copy() | ||
view.clipboardEditable.copy() |