Import upstream version 0.14.0
Kali Janitor
3 years ago
33 | 33 | - DJANGO_VERSION=1.7.11 DRIVER=tests/test_djangoclient.py |
34 | 34 | - DRIVER=tests/test_zopetestbrowser.py |
35 | 35 | - python: 3.6 |
36 | env: DJANGO_VERSION=2.0.6 DRIVER=tests/test_djangoclient.py | |
36 | env: | |
37 | - DJANGO_VERSION=2.0.6 DRIVER=tests/test_djangoclient.py | |
38 | - DRIVER=tests/test_zopetestbrowser.py | |
37 | 39 | - python: 3.7 |
38 | env: DJANGO_VERSION=2.0.6 DRIVER=tests/test_djangoclient.py | |
40 | env: | |
41 | - DJANGO_VERSION=2.0.6 DRIVER=tests/test_djangoclient.py | |
42 | - DRIVER=tests/test_zopetestbrowser.py | |
39 | 43 | - python: 3.8 |
40 | env: DJANGO_VERSION=2.0.6 DRIVER=tests/test_djangoclient.py | |
44 | env: | |
45 | - DJANGO_VERSION=2.0.6 DRIVER=tests/test_djangoclient.py | |
46 | - DRIVER=tests/test_zopetestbrowser.py | |
41 | 47 | install: |
42 | 48 | - export PATH=$HOME:$PATH |
43 | 49 | - make dependencies |
51 | 51 | # built documents. |
52 | 52 | # |
53 | 53 | # The short X.Y version. |
54 | version = "0.13.0" | |
54 | version = "0.14.0" | |
55 | 55 | # The full version, including alpha/beta/rc tags. |
56 | release = "0.13.0" | |
56 | release = "0.14.0" | |
57 | 57 | |
58 | 58 | # The language for content autogenerated by Sphinx. Refer to documentation |
59 | 59 | # for a list of supported languages. |
8 | 8 | what's new in splinter 0.1.1? |
9 | 9 | ============================= |
10 | 10 | |
11 | - compability with Firefox 5 | |
11 | - compatibility with Firefox 5 |
0 | .. Copyright 2020 splinter authors. All rights reserved. | |
1 | Use of this source code is governed by a BSD-style | |
2 | license that can be found in the LICENSE file. | |
3 | ||
4 | .. meta:: | |
5 | :description: New splinter features on version 0.14.0. | |
6 | :keywords: splinter 0.14.0, news | |
7 | ||
8 | whats's new in splinter 0.14.0? | |
9 | =============================== | |
10 | ||
11 | * Add FindLinks api to non-webdrivers (https://github.com/cobrateam/splinter/pull/762) | |
12 | * Add support for zope in python3 (https://github.com/cobrateam/splinter/pull/771) | |
13 | * Fix WebDriverElement.screenshot when parent is a WebDriverElement (https://github.com/cobrateam/splinter/pull/769) | |
14 | * Improve firefox headless support (https://github.com/cobrateam/splinter/pull/768) | |
15 | * Fix mouse out on elements in the left corner of the viewport (https://github.com/cobrateam/splinter/pull/766) | |
16 | * Fix fullscreen argument for firefox (https://github.com/cobrateam/splinter/pull/765) | |
17 | * Fix unexpected keyword argument 'original_find' (https://github.com/cobrateam/splinter/pull/758) | |
18 | * Fix incorrect error thrown when missing chrome/geckodriver (https://github.com/cobrateam/splinter/pull/749) | |
19 | * Make find_by_value works with button elements (https://github.com/cobrateam/splinter/pull/746) |
11 | 11 | |
12 | 12 | See below the changes for each splinter release. |
13 | 13 | |
14 | - :doc:`what's new in splinter 0.14.0 </news/0.14.0>` | |
14 | 15 | - :doc:`what's new in splinter 0.13.0 </news/0.13.0>` |
15 | 16 | - :doc:`what's new in splinter 0.12.0 </news/0.12.0>` |
16 | 17 | - :doc:`what's new in splinter 0.11.0 </news/0.11.0>` |
10 | 10 | |
11 | 11 | setup( |
12 | 12 | name="splinter", |
13 | version="0.13.0", | |
13 | version="0.14.0", | |
14 | 14 | url="https://github.com/cobrateam/splinter", |
15 | 15 | description="browser abstraction for web acceptance testing", |
16 | 16 | long_description=README, |
4 | 4 | from splinter.browser import Browser # NOQA |
5 | 5 | |
6 | 6 | |
7 | __version__ = "0.13.0" | |
7 | __version__ = "0.14.0" |
26 | 26 | "chrome": ChromeWebDriver, |
27 | 27 | } |
28 | 28 | |
29 | if sys.version_info[0] <= 2: | |
30 | try: | |
31 | from splinter.driver.zopetestbrowser import ZopeTestBrowser | |
32 | 29 | |
33 | _DRIVERS["zope.testbrowser"] = ZopeTestBrowser | |
34 | except ImportError: | |
35 | pass | |
30 | try: | |
31 | from splinter.driver.zopetestbrowser import ZopeTestBrowser | |
32 | ||
33 | _DRIVERS["zope.testbrowser"] = ZopeTestBrowser | |
34 | except ImportError: | |
35 | pass | |
36 | 36 | |
37 | 37 | try: |
38 | 38 | import django # noqa |
58 | 58 | This can mitigate issues running on Remote WebDriver. |
59 | 59 | |
60 | 60 | """ |
61 | err = None | |
62 | ||
61 | 63 | for _ in range(retry_count): |
62 | 64 | try: |
63 | 65 | return driver(*args, **kwargs) |
64 | 66 | except (IOError, HTTPException, WebDriverException, MaxRetryError) as e: |
65 | pass | |
67 | err = e | |
66 | 68 | |
67 | raise e | |
69 | raise err | |
68 | 70 | |
69 | 71 | |
70 | 72 | def Browser(driver_name="firefox", retry_count=3, *args, **kwargs): |
0 | class FindLinks(object): | |
1 | """Contains methods for finding links in a parent. | |
2 | ||
3 | Accessed through the browser object or an element via the links attribute. | |
4 | ||
5 | Example: | |
6 | ||
7 | browser.links.find_by_href('foobar') | |
8 | ||
9 | """ | |
10 | def __init__(self, parent): | |
11 | self.parent = parent | |
12 | ||
13 | def find_by_href(self, href): | |
14 | return self.parent.find_by_xpath( | |
15 | '//a[@href="{}"]'.format(href), | |
16 | original_find="link by href", | |
17 | original_query=href, | |
18 | ) | |
19 | ||
20 | def find_by_partial_href(self, partial_href): | |
21 | return self.parent.find_by_xpath( | |
22 | '//a[contains(@href, "{}")]'.format(partial_href), | |
23 | original_find="link by partial href", | |
24 | original_query=partial_href, | |
25 | ) | |
26 | ||
27 | def find_by_partial_text(self, partial_text): | |
28 | return self.parent.find_by_xpath( | |
29 | '//a[contains(normalize-space(.), "{}")]'.format(partial_text), | |
30 | original_find="link by partial text", | |
31 | original_query=partial_text, | |
32 | ) | |
33 | ||
34 | def find_by_text(self, text): | |
35 | return self.parent.find_by_xpath( | |
36 | '//a[text()="{}"]'.format(text), | |
37 | original_find="link by text", | |
38 | original_query=text, | |
39 | ) |
13 | 13 | import lxml.html |
14 | 14 | from lxml.cssselect import CSSSelector |
15 | 15 | from splinter.driver import DriverAPI, ElementAPI |
16 | from splinter.driver.find_links import FindLinks | |
16 | 17 | from splinter.driver.element_present import ElementPresentMixIn |
17 | 18 | from splinter.driver.xpath_utils import _concat_xpath_from_str |
18 | 19 | from splinter.element_list import ElementList |
28 | 29 | self._history = [] |
29 | 30 | self._last_urls = [] |
30 | 31 | self._forms = {} |
32 | ||
33 | self.links = FindLinks(self) | |
31 | 34 | |
32 | 35 | def __enter__(self): |
33 | 36 | return self |
147 | 150 | def find_by_css(self, selector): |
148 | 151 | xpath = CSSSelector(selector).path |
149 | 152 | return self.find_by_xpath( |
150 | xpath, original_find="css", original_selector=selector | |
151 | ) | |
152 | ||
153 | def find_by_xpath(self, xpath, original_find=None, original_selector=None): | |
153 | xpath, original_find="css", original_query=selector | |
154 | ) | |
155 | ||
156 | def find_by_xpath(self, xpath, original_find=None, original_query=None): | |
154 | 157 | html = self.htmltree |
155 | 158 | |
156 | 159 | elements = [] |
164 | 167 | elements.append((LxmlElement, xpath_element)) |
165 | 168 | |
166 | 169 | find_by = original_find or "xpath" |
167 | query = original_selector or xpath | |
170 | query = original_query or xpath | |
168 | 171 | |
169 | 172 | return ElementList( |
170 | 173 | [element_class(element, self) for element_class, element in elements], |
174 | 177 | |
175 | 178 | def find_by_tag(self, tag): |
176 | 179 | return self.find_by_xpath( |
177 | "//%s" % tag, original_find="tag", original_selector=tag | |
180 | "//%s" % tag, original_find="tag", original_query=tag | |
178 | 181 | ) |
179 | 182 | |
180 | 183 | def find_by_value(self, value): |
181 | return self.find_by_xpath( | |
182 | '//*[@value="%s"]' % value, original_find="value", original_selector=value | |
183 | ) | |
184 | elem = self.find_by_xpath( | |
185 | '//*[@value="%s"]' % value, original_find="value", original_query=value | |
186 | ) | |
187 | if elem: | |
188 | return elem | |
189 | return self.find_by_xpath('//*[.="%s"]' % value) | |
184 | 190 | |
185 | 191 | def find_by_text(self, text): |
186 | 192 | xpath_str = _concat_xpath_from_str(text) |
187 | 193 | return self.find_by_xpath( |
188 | 194 | xpath_str, |
189 | 195 | original_find="text", |
190 | original_selector=text, | |
196 | original_query=text, | |
191 | 197 | ) |
192 | 198 | |
193 | 199 | def find_by_id(self, id_value): |
194 | 200 | return self.find_by_xpath( |
195 | 201 | '//*[@id="%s"][1]' % id_value, |
196 | 202 | original_find="id", |
197 | original_selector=id_value, | |
203 | original_query=id_value, | |
198 | 204 | ) |
199 | 205 | |
200 | 206 | def find_by_name(self, name): |
411 | 417 | |
412 | 418 | @property |
413 | 419 | def value(self): |
414 | return self._control.value | |
420 | try: | |
421 | return self._control.value | |
422 | except AttributeError: | |
423 | return self._control.text | |
415 | 424 | |
416 | 425 | @property |
417 | 426 | def checked(self): |
13 | 13 | import warnings |
14 | 14 | |
15 | 15 | from selenium.webdriver.common.alert import Alert |
16 | from selenium.common.exceptions import ElementClickInterceptedException, NoSuchElementException, WebDriverException, StaleElementReferenceException, TimeoutException | |
16 | from selenium.common.exceptions import ( | |
17 | ElementClickInterceptedException, | |
18 | NoSuchElementException, | |
19 | WebDriverException, | |
20 | StaleElementReferenceException, | |
21 | TimeoutException, | |
22 | MoveTargetOutOfBoundsException, | |
23 | ) | |
17 | 24 | from selenium.webdriver.common.action_chains import ActionChains |
18 | 25 | from selenium.webdriver.support import expected_conditions as EC |
19 | 26 | from selenium.webdriver.support.ui import WebDriverWait |
21 | 28 | from six import BytesIO |
22 | 29 | |
23 | 30 | from splinter.driver import DriverAPI, ElementAPI |
31 | from splinter.driver.find_links import FindLinks | |
24 | 32 | from splinter.driver.xpath_utils import _concat_xpath_from_str |
25 | 33 | from splinter.element_list import ElementList |
26 | 34 | |
180 | 188 | ) |
181 | 189 | |
182 | 190 | |
183 | class FindLinks(object): | |
184 | """Contains methods for finding links in a parent. | |
185 | ||
186 | Accessed through the browser object or an element via the links attribute. | |
187 | ||
188 | Example: | |
189 | ||
190 | browser.links.find_by_href('foobar') | |
191 | ||
192 | """ | |
193 | def __init__(self, parent): | |
194 | self.parent = parent | |
195 | ||
196 | def find_by_href(self, href): | |
197 | return self.parent.find_by_xpath( | |
198 | '//a[@href="{}"]'.format(href), | |
199 | original_find="link by href", | |
200 | original_query=href, | |
201 | ) | |
202 | ||
203 | def find_by_partial_href(self, partial_href): | |
204 | return self.parent.find_by_xpath( | |
205 | '//a[contains(@href, "{}")]'.format(partial_href), | |
206 | original_find="link by partial href", | |
207 | original_query=partial_href, | |
208 | ) | |
209 | ||
210 | def find_by_partial_text(self, partial_text): | |
211 | return self.parent.find_by_xpath( | |
212 | '//a[contains(normalize-space(.), "{}")]'.format(partial_text), | |
213 | original_find="link by partial text", | |
214 | original_query=partial_text, | |
215 | ) | |
216 | ||
217 | def find_by_text(self, text): | |
218 | return self.parent.find_by_xpath( | |
219 | '//a[text()="{}"]'.format(text), | |
220 | original_find="link by text", | |
221 | original_query=text, | |
222 | ) | |
223 | ||
224 | ||
225 | 191 | def _find(self, finder, selector): |
226 | 192 | """Search for elements. Returns a list of results. |
227 | 193 | |
291 | 257 | |
292 | 258 | def __init__(self, wait_time=2): |
293 | 259 | self.wait_time = wait_time |
294 | self.ori_window_size = None | |
295 | 260 | |
296 | 261 | self.links = FindLinks(self) |
297 | 262 | |
571 | 536 | ) |
572 | 537 | |
573 | 538 | def find_by_value(self, value, wait_time=None): |
574 | return self.find_by_xpath( | |
539 | elem = self.find_by_xpath( | |
575 | 540 | '//*[@value="{}"]'.format(value), |
576 | 541 | original_find="value", |
577 | 542 | original_query=value, |
578 | 543 | wait_time=wait_time, |
579 | 544 | ) |
545 | if elem: | |
546 | return elem | |
547 | return self.find_by_xpath('//*[.="%s"]' % value) | |
580 | 548 | |
581 | 549 | def find_by_text(self, text=None, wait_time=None): |
582 | 550 | xpath_str = _concat_xpath_from_str(text) |
661 | 629 | os.close(fd) |
662 | 630 | |
663 | 631 | if full: |
632 | ori_window_size = self.driver.get_window_size() | |
664 | 633 | self.full_screen() |
665 | 634 | |
666 | 635 | self.driver.get_screenshot_as_file(filename) |
667 | self.recover_screen() | |
636 | ||
637 | if full: | |
638 | self.recover_screen(ori_window_size) | |
639 | ||
668 | 640 | return filename |
669 | 641 | |
670 | 642 | def select(self, name, value): |
684 | 656 | pass |
685 | 657 | |
686 | 658 | def full_screen(self): |
687 | self.ori_window_size = self.driver.get_window_size() | |
688 | 659 | width = self.driver.execute_script("return Math.max(document.body.scrollWidth, document.body.offsetWidth);") |
689 | 660 | height = self.driver.execute_script("return Math.max(document.body.scrollHeight, document.body.offsetHeight);") |
690 | 661 | self.driver.set_window_size(width, height) |
691 | 662 | |
692 | def recover_screen(self): | |
693 | if self.ori_window_size: | |
694 | width = self.ori_window_size.get('width') | |
695 | height = self.ori_window_size.get('height') | |
696 | self.driver.set_window_size(width, height) | |
697 | self.ori_window_size = None | |
663 | def recover_screen(self, size): | |
664 | width = size.get('width') | |
665 | height = size.get('height') | |
666 | self.driver.set_window_size(width, height) | |
698 | 667 | |
699 | 668 | def html_snapshot(self, name="", suffix=".html", encoding='utf-8'): |
700 | 669 | """Write the current html to a file.""" |
851 | 820 | wait_time=wait_time, |
852 | 821 | ) |
853 | 822 | |
854 | def find_by_xpath(self, selector, wait_time=None): | |
823 | def find_by_xpath(self, selector, wait_time=None, original_find="xpath", original_query=None): | |
855 | 824 | return self.find_by( |
856 | 825 | self._element.find_elements_by_xpath, |
857 | 826 | selector, |
858 | original_find="xpath", | |
827 | original_find=original_find, | |
828 | original_query=original_query, | |
859 | 829 | wait_time=wait_time, |
860 | 830 | ) |
861 | 831 | |
929 | 899 | |
930 | 900 | """ |
931 | 901 | self.scroll_to() |
932 | ActionChains(self.driver).move_to_element_with_offset( | |
933 | self._element, -10, -10).click().perform() | |
902 | size = self._element.size | |
903 | ||
904 | try: | |
905 | # Fails on left edge of viewport | |
906 | ActionChains(self.driver).move_to_element_with_offset( | |
907 | self._element, -10, -10).click().perform() | |
908 | except MoveTargetOutOfBoundsException: | |
909 | ActionChains(self.driver).move_to_element_with_offset( | |
910 | self._element, size['width'] + 10, 10).click().perform() | |
934 | 911 | |
935 | 912 | def double_click(self): |
936 | 913 | """ |
955 | 932 | """ |
956 | 933 | self.scroll_to() |
957 | 934 | ActionChains(self.driver).drag_and_drop(self._element, droppable._element).perform() |
935 | ||
936 | def _full_screen(): | |
937 | width = self.driver.execute_script("return Math.max(document.body.scrollWidth, document.body.offsetWidth);") | |
938 | height = self.driver.execute_script("return Math.max(document.body.scrollHeight, document.body.offsetHeight);") | |
939 | self.driver.set_window_size(width, height) | |
958 | 940 | |
959 | 941 | def screenshot(self, name='', suffix='.png', full=False): |
960 | 942 | name = name or '' |
964 | 946 | os.close(fd) |
965 | 947 | |
966 | 948 | if full: |
967 | self.parent.full_screen() | |
949 | ori_window_size = self.driver.get_window_size() | |
950 | self._full_screen() | |
951 | ||
968 | 952 | target = self.screenshot_as_png() |
969 | self.parent.recover_screen() | |
953 | ||
954 | if full: | |
955 | # Restore screen size | |
956 | width = ori_window_size.get('width') | |
957 | height = ori_window_size.get('height') | |
958 | self.driver.set_window_size(width, height) | |
959 | ||
970 | 960 | target.save(filename) |
971 | 961 | |
972 | 962 | return filename |
12 | 12 | WebDriverElement as WebDriverElement, |
13 | 13 | ) |
14 | 14 | from splinter.driver.webdriver.cookie_manager import CookieManager |
15 | from selenium.webdriver.common.keys import Keys | |
16 | from selenium.webdriver.common.action_chains import ActionChains | |
17 | from selenium.webdriver.firefox.firefox_binary import FirefoxBinary | |
18 | 15 | from selenium.webdriver.firefox.options import Options |
19 | 16 | |
20 | 17 | |
62 | 59 | firefox_profile.add_extension(extension) |
63 | 60 | |
64 | 61 | if headless: |
65 | os.environ.update({"MOZ_HEADLESS": "1"}) | |
66 | if 'firefox_binary' in kwargs: | |
67 | if isinstance(kwargs['firefox_binary'], six.string_types): | |
68 | binary = FirefoxBinary(kwargs['firefox_binary']) | |
69 | else: | |
70 | binary = kwargs['firefox_binary'] | |
71 | else: | |
72 | binary = FirefoxBinary() | |
73 | binary.add_command_line_options("-headless") | |
74 | kwargs["firefox_binary"] = binary | |
75 | else: | |
76 | if "MOZ_HEADLESS" in os.environ: | |
77 | del os.environ["MOZ_HEADLESS"] | |
62 | firefox_options.add_argument("--headless") | |
78 | 63 | |
79 | 64 | if incognito: |
80 | 65 | firefox_options.add_argument("-private") |
88 | 73 | ) |
89 | 74 | |
90 | 75 | if fullscreen: |
91 | ActionChains(self.driver).send_keys(Keys.F11).perform() | |
76 | self.driver.fullscreen_window() | |
92 | 77 | |
93 | 78 | self.element_class = WebDriverElement |
94 | 79 |
3 | 3 | # Use of this source code is governed by a BSD-style |
4 | 4 | # license that can be found in the LICENSE file. |
5 | 5 | |
6 | from __future__ import unicode_literals | |
7 | ||
8 | import mimetypes | |
6 | 9 | import re |
7 | ||
10 | import time | |
11 | ||
12 | import lxml.html | |
8 | 13 | from lxml.cssselect import CSSSelector |
9 | 14 | from zope.testbrowser.browser import Browser, ListControl, SubmitControl |
10 | 15 | from splinter.element_list import ElementList |
11 | 16 | from splinter.exceptions import ElementDoesNotExist |
12 | 17 | from splinter.driver import DriverAPI, ElementAPI |
13 | 18 | from splinter.driver.element_present import ElementPresentMixIn |
19 | from splinter.driver.find_links import FindLinks | |
14 | 20 | from splinter.driver.xpath_utils import _concat_xpath_from_str |
15 | 21 | from splinter.cookie_manager import CookieManagerAPI |
16 | ||
17 | import mimetypes | |
18 | import lxml.html | |
19 | import time | |
20 | 22 | |
21 | 23 | |
22 | 24 | class CookieManager(CookieManagerAPI): |
71 | 73 | self._cookie_manager = CookieManager(self._browser) |
72 | 74 | self._last_urls = [] |
73 | 75 | |
76 | self.links = FindLinks(self) | |
77 | ||
74 | 78 | def __enter__(self): |
75 | 79 | return self |
76 | 80 | |
98 | 102 | |
99 | 103 | @property |
100 | 104 | def htmltree(self): |
101 | return lxml.html.fromstring(self.html.decode("utf-8")) | |
105 | try: | |
106 | html = self.html.decode("utf-8") | |
107 | except AttributeError: | |
108 | html = self.html | |
109 | ||
110 | return lxml.html.fromstring(html) | |
102 | 111 | |
103 | 112 | @property |
104 | 113 | def title(self): |
131 | 140 | def find_by_css(self, selector): |
132 | 141 | xpath = CSSSelector(selector).path |
133 | 142 | return self.find_by_xpath( |
134 | xpath, original_find="css", original_selector=selector | |
143 | xpath, original_find="css", original_query=selector | |
135 | 144 | ) |
136 | 145 | |
137 | 146 | def get_control(self, xpath_element): |
138 | 147 | return xpath_element |
139 | 148 | |
140 | def find_by_xpath(self, xpath, original_find=None, original_selector=None): | |
149 | def find_by_xpath(self, xpath, original_find=None, original_query=None): | |
141 | 150 | html = self.htmltree |
142 | 151 | |
143 | 152 | elements = [] |
151 | 160 | elements.append(self.get_control(xpath_element)) |
152 | 161 | |
153 | 162 | find_by = original_find or "xpath" |
154 | query = original_selector or xpath | |
163 | query = original_query or xpath | |
155 | 164 | |
156 | 165 | return ElementList( |
157 | 166 | [ZopeTestBrowserElement(element, self) for element in elements], |
161 | 170 | |
162 | 171 | def find_by_tag(self, tag): |
163 | 172 | return self.find_by_xpath( |
164 | "//%s" % tag, original_find="tag", original_selector=tag | |
173 | "//%s" % tag, original_find="tag", original_query=tag | |
165 | 174 | ) |
166 | 175 | |
167 | 176 | def find_by_value(self, value): |
168 | return self.find_by_xpath( | |
169 | '//*[@value="%s"]' % value, original_find="value", original_selector=value | |
170 | ) | |
177 | elem = self.find_by_xpath( | |
178 | '//*[@value="%s"]' % value, original_find="value", original_query=value | |
179 | ) | |
180 | if elem: | |
181 | return elem | |
182 | return self.find_by_xpath('//*[.="%s"]' % value) | |
171 | 183 | |
172 | 184 | def find_by_text(self, text): |
173 | 185 | xpath_str = _concat_xpath_from_str(text) |
174 | 186 | return self.find_by_xpath( |
175 | 187 | xpath_str, |
176 | 188 | original_find="text", |
177 | original_selector=text, | |
189 | original_query=text, | |
178 | 190 | ) |
179 | 191 | |
180 | 192 | def find_by_id(self, id_value): |
181 | 193 | return self.find_by_xpath( |
182 | 194 | '//*[@id="%s"][1]' % id_value, |
183 | 195 | original_find="id", |
184 | original_selector=id_value, | |
196 | original_query=id_value, | |
185 | 197 | ) |
186 | 198 | |
187 | 199 | def find_by_name(self, name): |
258 | 270 | filename = file_path.split("/")[-1] |
259 | 271 | control = self._browser.getControl(name=name) |
260 | 272 | content_type, _ = mimetypes.guess_type(file_path) |
261 | control.add_file(open(file_path), content_type, filename) | |
273 | with open(file_path, 'rb') as f: | |
274 | control.add_file(f, content_type, filename) | |
262 | 275 | |
263 | 276 | def _find_links_by_xpath(self, xpath): |
264 | 277 | html = self.htmltree |
0 | zope.testbrowser==5.2.4; python_version < '3.0' | |
0 | zope.testbrowser==5.5.1 | |
1 | 1 | lxml==4.2.4 |
2 | 2 | Flask==1.0.2 |
3 | 3 | selenium==3.141.0 |
10 | 10 | six==1.11.0 |
11 | 11 | twine==1.11.0 |
12 | 12 | pytest==4.6.4 |
13 | Pillow==6.2.2 |
32 | 32 | u'inner <div class="inner-html">inner text</div> html test</div>', |
33 | 33 | ) |
34 | 34 | |
35 | def test_element_html_with_breakline(self): | |
36 | self.assertEqual( | |
37 | self.browser.find_by_id("html-property-with-breakline").html, | |
38 | u'\\n some text here\\n', | |
39 | ) | |
40 | ||
35 | 41 | def test_element_html(self): |
36 | 42 | self.assertEqual( |
37 | 43 | self.browser.find_by_id("html-property").html, |
24 | 24 | value = self.browser.find_by_value("M").value |
25 | 25 | id = self.browser.find_by_id("gender-m") |
26 | 26 | self.assertEqual(id.value, value) |
27 | ||
28 | def test_finding_by_value_in_btn_elements(self): | |
29 | value = self.browser.find_by_value("some value").value | |
30 | btn = self.browser.find_by_id("button-value") | |
31 | self.assertEqual(btn.value, value) | |
27 | 32 | |
28 | 33 | def test_finding_by_text(self): |
29 | 34 | element = self.browser.find_by_text("Complex") |
8 | 8 | |
9 | 9 | class ScreenshotTest(object): |
10 | 10 | def test_take_screenshot(self): |
11 | "should take a screenshot of the current page" | |
11 | """Should take a screenshot of the current page""" | |
12 | 12 | filename = self.browser.screenshot() |
13 | self.assertTrue(tempfile.gettempdir() in filename) | |
13 | assert tempfile.gettempdir() in filename | |
14 | 14 | |
15 | 15 | def test_take_screenshot_with_prefix(self): |
16 | "should add the prefix to the screenshot file name" | |
16 | """Should add the prefix to the screenshot file name""" | |
17 | 17 | filename = self.browser.screenshot(name="foobar") |
18 | self.assertTrue("foobar" in filename) | |
18 | assert "foobar" in filename | |
19 | 19 | |
20 | 20 | def test_take_screenshot_with_suffix(self): |
21 | "should add the suffix to the screenshot file name" | |
22 | filename = self.browser.screenshot(suffix="jpeg") | |
23 | self.assertEqual("jpeg", filename[-4:]) | |
21 | """Should add the suffix to the screenshot file name""" | |
22 | filename = self.browser.screenshot(suffix=".jpg") | |
23 | assert ".jpg" in filename[-4:] | |
24 | ||
25 | def test_take_element_screenshot(self): | |
26 | elem = self.browser.find_by_tag("body") | |
27 | filename = elem.screenshot() | |
28 | assert tempfile.gettempdir() in filename | |
29 | ||
30 | def test_take_element_screenshot_with_prefix(self): | |
31 | """Should add the prefix to the screenshot file name""" | |
32 | elem = self.browser.find_by_tag("body") | |
33 | filename = elem.screenshot(name="foobar") | |
34 | assert "foobar" in filename | |
35 | ||
36 | def test_take_nested_element_screenshot(self): | |
37 | elem = self.browser.find_by_tag("body").find_by_css("h1") | |
38 | filename = elem.screenshot() | |
39 | assert tempfile.gettempdir() in filename |
79 | 79 | <body> |
80 | 80 | <h1 id="firstheader">Example Header</h1> |
81 | 81 | <h1 id="firstheader">Example Last Header</h1> |
82 | <button id="button-value">some value</button> | |
82 | 83 | <form action="name" method="GET"> |
83 | 84 | <label for="query">Query</label> |
84 | 85 | <input type="text" name="q" /> |
186 | 187 | <div class="dragged">no</div> |
187 | 188 | <div class="has-class-first has-class-middle has-class-end"></div> |
188 | 189 | <div id="html-property" class="outer html classes">inner <div class="inner-html">inner text</div> html test</div> |
190 | <p id="html-property-with-breakline">\n some text here\n</p> | |
189 | 191 | <a id="open-popup" href="javascript:poptastic('/popup')">Open pop-up window</a> |
190 | 192 | <script> |
191 | 193 | function poptastic(url) { |
11 | 11 | from imp import reload |
12 | 12 | |
13 | 13 | from splinter.exceptions import DriverNotFoundError |
14 | ||
15 | from selenium.common.exceptions import WebDriverException | |
16 | ||
17 | import pytest | |
14 | 18 | |
15 | 19 | from .fake_webapp import EXAMPLE_APP |
16 | 20 | |
56 | 60 | from splinter import Browser |
57 | 61 | |
58 | 62 | Browser("unknown-driver") |
63 | ||
64 | ||
65 | @pytest.mark.parametrize('browser_name', ['chrome', 'firefox']) | |
66 | def test_local_driver_not_present(browser_name): | |
67 | """When chromedriver/geckodriver are not present on the system.""" | |
68 | from splinter import Browser | |
69 | ||
70 | with pytest.raises(WebDriverException) as e: | |
71 | Browser(browser_name, executable_path='failpath') | |
72 | ||
73 | assert "Message: 'failpath' executable needs to be in PATH." in str(e.value) |
7 | 7 | import unittest |
8 | 8 | import sys |
9 | 9 | |
10 | import six | |
11 | ||
10 | 12 | from splinter import Browser |
11 | 13 | from .base import BaseBrowserTests |
12 | 14 | from .fake_webapp import EXAMPLE_APP |
13 | 15 | from .is_element_present_nojs import IsElementPresentNoJSTest |
14 | 16 | |
15 | 17 | |
16 | @unittest.skipIf( | |
17 | sys.version_info[0] > 2, | |
18 | "zope.testbrowser is not currently compatible with Python 3", | |
19 | ) | |
20 | 18 | class ZopeTestBrowserDriverTest( |
21 | 19 | BaseBrowserTests, IsElementPresentNoJSTest, unittest.TestCase |
22 | 20 | ): |
44 | 42 | self.browser.find_by_name("upload").click() |
45 | 43 | |
46 | 44 | html = self.browser.html |
47 | self.assertIn("text/plain", html) | |
48 | self.assertIn(open(file_path).read().encode("utf-8"), html) | |
45 | ||
46 | assert "text/plain" in html | |
47 | ||
48 | with open(file_path) as f: | |
49 | assert f.read() in html | |
49 | 50 | |
50 | 51 | def test_forward_to_none_page(self): |
51 | 52 | "should not fail when trying to forward to none" |
139 | 140 | "pangram_ru": u"В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!", |
140 | 141 | "pangram_eo": u"Laŭ Ludoviko Zamenhof bongustas freŝa ĉeĥa manĝaĵo kun spicoj.", |
141 | 142 | } |
142 | for key, text in non_ascii_encodings.iteritems(): | |
143 | for key, text in six.iteritems(non_ascii_encodings): | |
143 | 144 | link = self.browser.find_link_by_text(text) |
144 | 145 | self.assertEqual(key, link["id"]) |