-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa6cce4
commit 5f835f1
Showing
6 changed files
with
107 additions
and
4 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
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,34 @@ | ||
from widgetastic.widget import GenericLocatorWidget | ||
|
||
|
||
class SwitchDisabled(Exception): | ||
pass | ||
|
||
|
||
class BaseSwitch: | ||
"""Represents the Patternfly Switch. | ||
https://www.patternfly.org/components/switch | ||
""" | ||
|
||
CHECKBOX_LOCATOR = "./input" | ||
|
||
@property | ||
def is_enabled(self): | ||
"""Returns a boolean detailing if the switch is enabled.""" | ||
return self.browser.get_attribute("disabled", self.CHECKBOX_LOCATOR) is None | ||
|
||
def click(self): | ||
"""Click on a Switch.""" | ||
if not self.is_enabled: | ||
raise SwitchDisabled("{} is disabled".format(repr(self))) | ||
else: | ||
self.browser.click(self.CHECKBOX_LOCATOR) | ||
return True | ||
|
||
def __repr__(self): | ||
return "{}({!r})".format(type(self).__name__, self.locator) | ||
|
||
|
||
class Switch(BaseSwitch, GenericLocatorWidget): | ||
pass |
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,32 @@ | ||
import pytest | ||
from widgetastic.widget import View | ||
|
||
from widgetastic_patternfly5 import Switch | ||
from widgetastic_patternfly5 import SwitchDisabled | ||
|
||
TESTING_PAGE_URL = "https://patternfly-react-main.surge.sh/components/switch" | ||
|
||
|
||
@pytest.fixture | ||
def view(browser): | ||
class TestView(View): | ||
switch = Switch(locator='.//label[@for="simple-switch"]') | ||
disabled_switch_on = Switch(locator='.//label[@for="disabled-switch-on"]') | ||
|
||
return TestView(browser) | ||
|
||
|
||
def test_switch_is_displayed(view): | ||
assert view.switch.is_displayed | ||
assert view.disabled_switch_on.is_displayed | ||
|
||
|
||
def test_switch_is_enabled(view): | ||
assert view.switch.is_enabled | ||
assert not view.disabled_switch_on.is_enabled | ||
|
||
|
||
def test_switch_click(view): | ||
assert view.switch.click() | ||
with pytest.raises(SwitchDisabled): | ||
view.disabled_switch_on.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
from widgetastic.widget import View | ||
|
||
from widgetastic_patternfly5.ouia import Switch as SwitchOUIA | ||
|
||
TESTING_PAGE_URL = "https://patternfly-react-main.surge.sh/components/switch" | ||
|
||
|
||
@pytest.fixture | ||
def view(browser): | ||
class TestView(View): | ||
switch = SwitchOUIA("BasicSwitch") | ||
|
||
return TestView(browser) | ||
|
||
|
||
def test_switch_is_displayed(view): | ||
assert view.switch.is_displayed | ||
|
||
|
||
def test_switch_is_enabled(view): | ||
assert view.switch.is_enabled | ||
|
||
|
||
def test_switch_click(view): | ||
assert view.switch.click() |