Skip to content
This repository was archived by the owner on Aug 10, 2022. It is now read-only.

Commit 5d87639

Browse files
committed
Allow to set CSS_SELECTOR and XPATH to SeleniumCheckSettings
* Add tests
1 parent b0c43c1 commit 5d87639

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

eyes_selenium/applitools/selenium/fluent/selenium_check_settings.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ def size_mode(self):
8181
def _css_selector_from_(by, value):
8282
if by == By.ID:
8383
value = "#%s" % value
84-
elif by == By.TAG_NAME:
85-
value = value
8684
elif by == By.CLASS_NAME:
8785
value = ".%s" % value
8886
elif by == By.NAME:
8987
value = '[name="%s"]' % value
88+
elif by in [By.XPATH, By.CSS_SELECTOR, By.TAG_NAME]:
89+
value = value
9090
else:
9191
raise TypeError("By {} is not supported".format(by))
9292
return value
@@ -192,6 +192,8 @@ def is_list_or_tuple(elm):
192192

193193

194194
def is_webelement(elm):
195-
return isinstance(elm, WebElement) or isinstance(
196-
getattr(elm, "_element", None), WebElement
195+
return (
196+
isinstance(elm, EyesWebElement)
197+
or isinstance(elm, WebElement)
198+
or isinstance(getattr(elm, "_element", None), WebElement)
197199
)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from mock import MagicMock
2+
from selenium.webdriver.common.by import By
3+
from selenium.webdriver.remote.webelement import WebElement as SeleniumWebElement
4+
from appium.webdriver import WebElement as AppiumWebElement
5+
6+
from applitools.selenium import Region, EyesWebElement
7+
from applitools.selenium.fluent import SeleniumCheckSettings
8+
9+
10+
def test_check_region(driver_mock):
11+
region = Region(0, 1, 2, 3)
12+
cs = SeleniumCheckSettings().region(region)
13+
assert cs.values.target_region == region
14+
15+
selector_or_xpath = ".cssSelector_or_XPATH"
16+
cs = SeleniumCheckSettings().region(selector_or_xpath)
17+
assert cs.values.target_selector == selector_or_xpath
18+
19+
eyes_element = MagicMock(EyesWebElement)
20+
cs = SeleniumCheckSettings().region(eyes_element)
21+
assert cs.values.target_element == eyes_element
22+
23+
selenium_element = MagicMock(SeleniumWebElement)
24+
cs = SeleniumCheckSettings().region(selenium_element)
25+
assert cs.values.target_element == selenium_element
26+
27+
appium_element = MagicMock(AppiumWebElement)
28+
cs = SeleniumCheckSettings().region(appium_element)
29+
assert cs.values.target_element == appium_element
30+
31+
cs = SeleniumCheckSettings().region([By.NAME, "some-name"])
32+
assert cs.values.target_selector == '[name="some-name"]'
33+
cs = SeleniumCheckSettings().region([By.ID, "ident"])
34+
assert cs.values.target_selector == "#ident"
35+
cs = SeleniumCheckSettings().region([By.CLASS_NAME, "class_name"])
36+
assert cs.values.target_selector == ".class_name"
37+
cs = SeleniumCheckSettings().region([By.TAG_NAME, "tag_name"])
38+
assert cs.values.target_selector == "tag_name"
39+
cs = SeleniumCheckSettings().region([By.CSS_SELECTOR, selector_or_xpath])
40+
assert cs.values.target_selector == selector_or_xpath
41+
cs = SeleniumCheckSettings().region([By.XPATH, selector_or_xpath])
42+
assert cs.values.target_selector == selector_or_xpath

0 commit comments

Comments
 (0)