-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathplugin.py
785 lines (648 loc) · 26.1 KB
/
plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
"""Splinter plugin for pytest.
Provides easy interface for the browser from your tests providing the `browser` fixture
which is an object of splinter Browser class.
"""
import codecs
import functools # pragma: no cover
import warnings
try:
from httplib import HTTPException
except ImportError:
from http.client import HTTPException
import logging
import mimetypes # pragma: no cover
import os.path
import re
import pytest # pragma: no cover
import splinter # pragma: no cover
from _pytest import junitxml
from urllib3.exceptions import MaxRetryError
from selenium.webdriver.support import wait
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.common.exceptions import WebDriverException
from .webdriver_patches import patch_webdriver # pragma: no cover
from .splinter_patches import patch_webdriverelement # pragma: no cover
LOGGER = logging.getLogger(__name__)
NAME_RE = re.compile(r"[\W]")
def _visit(self, old_visit, url):
"""Override splinter's visit to avoid unnecessary checks and add wait_until instead."""
old_visit(url)
self.wait_for_condition(self.visit_condition, timeout=self.visit_condition_timeout)
def _wait_for_condition(
self, condition=None, timeout=None, poll_frequency=0.5, ignored_exceptions=None
):
"""Wait for given javascript condition."""
condition = functools.partial(condition or self.visit_condition, self)
timeout = timeout or self.wait_time
return wait.WebDriverWait(
self.driver,
timeout,
poll_frequency=poll_frequency,
ignored_exceptions=ignored_exceptions,
).until(lambda browser: condition())
def _screenshot_extraline(screenshot_png_file_name, screenshot_html_file_name):
return """
===========================
pytest-splinter screenshots
===========================
png: %s
html: %s
""" % (
screenshot_png_file_name,
screenshot_html_file_name,
)
def Browser(*args, **kwargs):
"""Emulate splinter's Browser."""
visit_condition = kwargs.pop("visit_condition")
visit_condition_timeout = kwargs.pop("visit_condition_timeout")
browser = splinter.Browser(*args, **kwargs)
browser.wait_for_condition = functools.partial(_wait_for_condition, browser)
if hasattr(browser, "driver"):
browser.switch_to = browser.driver.switch_to
browser.visit_condition = visit_condition
browser.visit_condition_timeout = visit_condition_timeout
browser.visit = functools.partial(_visit, browser, browser.visit)
browser.__splinter_browser__ = True
return browser
@pytest.fixture(scope="session") # pragma: no cover
def splinter_close_browser():
"""Close browser fixture."""
return True
@pytest.fixture(scope="session") # pragma: no cover
def splinter_webdriver(request):
"""Webdriver fixture."""
return request.config.option.splinter_webdriver or "firefox"
@pytest.fixture(scope="session") # pragma: no cover
def splinter_remote_url(request):
"""Remote webdriver url.
:return: URL of remote webdriver.
"""
return request.config.option.splinter_remote_url
@pytest.fixture(scope="session") # pragma: no cover
def splinter_selenium_socket_timeout(request):
"""Return internal Selenium socket timeout (communication between webdriver and the browser).
:return: Seconds.
"""
return request.config.option.splinter_webdriver_socket_timeout
@pytest.fixture(scope="session") # pragma: no cover
def splinter_selenium_implicit_wait(request):
"""Return Selenium implicit wait timeout.
:return: Seconds.
"""
return request.config.option.splinter_webdriver_implicit_wait
@pytest.fixture(scope="session") # pragma: no cover
def splinter_wait_time(request):
"""Splinter explicit wait timeout.
:return: Seconds.
"""
return request.config.option.splinter_wait_time or 5
@pytest.fixture(scope="session") # pragma: no cover
def splinter_selenium_speed(request):
"""Selenium speed.
:return: Seconds.
"""
return request.config.option.splinter_webdriver_speed
@pytest.fixture(scope="session") # pragma: no cover
def splinter_browser_load_condition():
"""Return the condition that has to be `True` to assume that the page is fully loaded.
One example is to wait for jQuery, then the condition could be::
@pytest.fixture
def splinter_browser_load_condition():
def condition(browser):
return browser.evaluate_script('typeof $ === "undefined" || !$.active')
return condition
"""
return lambda browser: True
@pytest.fixture(scope="session") # pragma: no cover
def splinter_browser_load_timeout():
"""Return the timeout in seconds in which the page is expected to be fully loaded."""
return 10
@pytest.fixture(scope="session") # pragma: no cover
def splinter_file_download_dir(session_tmpdir):
"""Browser file download directory."""
return session_tmpdir.ensure("splinter", "download", dir=True).strpath
@pytest.fixture(scope="session") # pragma: no cover
def splinter_download_file_types():
"""Browser file types to download. Comma-separated."""
return ",".join(mimetypes.types_map.values())
@pytest.fixture(scope="session")
def splinter_firefox_profile_preferences():
"""Firefox profile preferences."""
return {
"browser.cache.memory.enable": False,
"browser.sessionhistory.max_total_viewers": 0,
"network.http.pipelining": True,
"network.http.pipelining.maxrequests": 8,
"browser.startup.page": 0,
"browser.startup.homepage": "about:blank",
"startup.homepage_welcome_url": "about:blank",
"startup.homepage_welcome_url.additional": "about:blank",
"browser.startup.homepage_override.mstone": "ignore",
"toolkit.telemetry.reportingpolicy.firstRun": False,
"datareporting.healthreport.service.firstRun": False,
"browser.cache.disk.smart_size.first_run": False,
"media.gmp-gmpopenh264.enabled": False, # Firefox hangs when the file is not found
}
@pytest.fixture(scope="session")
def splinter_firefox_profile_directory():
"""Firefox profile directory."""
return os.path.join(os.path.dirname(__file__), "profiles", "firefox")
@pytest.fixture(scope="session")
def splinter_driver_kwargs():
"""Webdriver kwargs."""
return {}
@pytest.fixture(scope="session")
def splinter_window_size():
"""Browser window size. (width, height)."""
return (1366, 768)
@pytest.fixture(scope="session")
def splinter_session_scoped_browser(request):
"""Flag to keep single browser per test session."""
return request.config.option.splinter_session_scoped_browser == "true"
@pytest.fixture(scope="session")
def splinter_make_screenshot_on_failure(request):
"""Flag to make browser screenshot on test failure."""
return request.config.option.splinter_make_screenshot_on_failure == "true"
@pytest.fixture(scope="session") # pragma: no cover
def splinter_screenshot_dir(request):
"""Browser screenshot directory."""
return os.path.abspath(request.config.option.splinter_screenshot_dir)
@pytest.fixture(scope="session")
def splinter_headless(request):
"""Flag to start the browser in headless mode."""
return request.config.option.splinter_headless
@pytest.fixture(scope="session") # pragma: no cover
def splinter_screenshot_encoding(request):
"""Browser screenshot html encoding."""
return "utf-8"
@pytest.fixture(scope="session")
def splinter_webdriver_executable(request):
"""Webdriver executable directory."""
executable = request.config.option.splinter_webdriver_executable
return os.path.abspath(executable) if executable else None
@pytest.fixture(scope="session")
def browser_pool(request, splinter_close_browser):
"""Browser 'pool' to emulate session scope but with possibility to recreate browser."""
pool = {}
def fin():
for browser in pool.values():
try:
browser.quit()
except Exception: # NOQA
pass
if splinter_close_browser:
request.addfinalizer(fin)
return pool
@pytest.fixture(scope="session")
def browser_patches():
"""Browser monkey patches."""
patch_webdriver()
patch_webdriverelement()
@pytest.fixture(scope="session")
def session_tmpdir(tmpdir_factory):
"""pytest tmpdir which is session-scoped."""
return tmpdir_factory.mktemp("pytest-splinter")
@pytest.fixture(scope="session")
def splinter_browser_class(request):
"""Browser class to use for browser instance creation."""
return Browser
def get_args(
driver=None,
download_dir=None,
download_ftypes=None,
firefox_pref=None,
firefox_prof_dir=None,
remote_url=None,
executable=None,
headless=False,
driver_kwargs=None,
):
"""Construct arguments to be passed to webdriver on initialization."""
kwargs = {}
firefox_profile_preferences = dict(
{
"browser.download.folderList": 2,
"browser.download.manager.showWhenStarting": False,
"browser.download.dir": download_dir,
"browser.helperApps.neverAsk.saveToDisk": download_ftypes,
"browser.helperApps.alwaysAsk.force": False,
"pdfjs.disabled": True, # disable internal ff pdf viewer to allow auto pdf download
},
**firefox_pref or {}
)
if driver == "firefox":
kwargs["profile_preferences"] = firefox_profile_preferences
kwargs["profile"] = firefox_prof_dir
if headless:
kwargs["headless"] = headless
elif driver == "remote":
if remote_url:
kwargs["command_executor"] = remote_url
kwargs["keep_alive"] = True
profile = FirefoxProfile(firefox_prof_dir)
for key, value in firefox_profile_preferences.items():
profile.set_preference(key, value)
kwargs["desired_capabilities"] = driver_kwargs.get("desired_capabilities", {})
kwargs["desired_capabilities"]["firefox_profile"] = profile.encoded
# remote geckodriver does not support the firefox_profile desired
# capatibility. Instead `moz:firefoxOptions` should be used:
# https://github.com/mozilla/geckodriver#firefox-capabilities
kwargs["desired_capabilities"]["moz:firefoxOptions"] = driver_kwargs.get(
"moz:firefoxOptions", {}
)
kwargs["desired_capabilities"]["moz:firefoxOptions"][
"profile"
] = profile.encoded
elif driver in ("chrome",):
if executable:
kwargs["executable_path"] = executable
if headless:
kwargs["headless"] = headless
if driver_kwargs:
kwargs.update(driver_kwargs)
return kwargs
@pytest.fixture(scope="session")
def splinter_screenshot_getter_png():
"""Screenshot getter function: png."""
def getter(browser, path):
browser.driver.save_screenshot(path)
return getter
@pytest.fixture(scope="session")
def splinter_screenshot_getter_html(splinter_screenshot_encoding):
"""Screenshot getter function: html."""
def getter(browser, path):
with codecs.open(path, "w", encoding=splinter_screenshot_encoding) as fd:
fd.write(browser.html)
return getter
@pytest.fixture(scope="session")
def splinter_clean_cookies_urls():
"""List of urls to clean cookies on their domains."""
return []
def _take_screenshot(
request,
browser_instance,
fixture_name,
session_tmpdir,
splinter_screenshot_dir,
splinter_screenshot_getter_html,
splinter_screenshot_getter_png,
splinter_screenshot_encoding,
):
"""Capture a screenshot as .png and .html.
Invoked from session and function browser fixtures.
"""
slaveoutput = getattr(request.config, "slaveoutput", None)
names = junitxml.mangle_test_address(request.node.nodeid)
classname = ".".join(names[:-1])
screenshot_dir = os.path.join(splinter_screenshot_dir, classname)
screenshot_file_name_format = "{0}.{{format}}".format(
"{}-{}".format(names[-1][: 128 - len(fixture_name) - 5], fixture_name).replace(
os.path.sep, "-"
)
)
screenshot_file_name = screenshot_file_name_format.format(format="png")
screenshot_html_file_name = screenshot_file_name_format.format(format="html")
if not slaveoutput:
if not os.path.exists(screenshot_dir):
os.makedirs(screenshot_dir)
else:
screenshot_dir = session_tmpdir.ensure("screenshots", dir=True).strpath
screenshot_png_path = os.path.join(screenshot_dir, screenshot_file_name)
screenshot_html_path = os.path.join(screenshot_dir, screenshot_html_file_name)
LOGGER.info("Saving screenshot to %s", screenshot_dir)
try:
splinter_screenshot_getter_html(browser_instance, screenshot_html_path)
splinter_screenshot_getter_png(browser_instance, screenshot_png_path)
if request.node.splinter_failure.longrepr:
reprtraceback = request.node.splinter_failure.longrepr.reprtraceback
reprtraceback.extraline = _screenshot_extraline(
screenshot_png_path, screenshot_html_path
)
if slaveoutput is not None:
with codecs.open(
screenshot_html_path, encoding=splinter_screenshot_encoding
) as html_fd:
with open(screenshot_png_path, "rb") as fd:
slaveoutput.setdefault("screenshots", []).append(
{
"class_name": classname,
"files": [
{
"file_name": screenshot_file_name,
"content": fd.read(),
},
{
"file_name": screenshot_html_file_name,
"content": html_fd.read(),
"encoding": splinter_screenshot_encoding,
},
],
}
)
except Exception as e: # NOQA
warnings.warn(pytest.PytestWarning("Could not save screenshot: {}".format(e)))
@pytest.yield_fixture(autouse=True)
def _browser_screenshot_session(
request,
session_tmpdir,
splinter_session_scoped_browser,
splinter_screenshot_dir,
splinter_make_screenshot_on_failure,
splinter_screenshot_getter_html,
splinter_screenshot_getter_png,
splinter_screenshot_encoding,
):
"""Make browser screenshot on test failure."""
yield
# Screenshot for function scoped browsers is handled in browser_instance_getter
if not splinter_session_scoped_browser:
return
fixture_values = (
# pytest 3
getattr(request, "_fixture_values", {})
or
# pytest 2
getattr(request, "_funcargs", {})
)
for name, value in fixture_values.items():
should_take_screenshot = (
hasattr(value, "__splinter_browser__")
and splinter_make_screenshot_on_failure
and getattr(request.node, "splinter_failure", True)
)
if should_take_screenshot:
_take_screenshot(
request=request,
fixture_name=name,
session_tmpdir=session_tmpdir,
browser_instance=value,
splinter_screenshot_dir=splinter_screenshot_dir,
splinter_screenshot_getter_html=splinter_screenshot_getter_html,
splinter_screenshot_getter_png=splinter_screenshot_getter_png,
splinter_screenshot_encoding=splinter_screenshot_encoding,
)
@pytest.fixture(scope="session")
def browser_instance_getter(
browser_patches,
splinter_session_scoped_browser,
splinter_browser_load_condition,
splinter_browser_load_timeout,
splinter_download_file_types,
splinter_driver_kwargs,
splinter_file_download_dir,
splinter_firefox_profile_preferences,
splinter_firefox_profile_directory,
splinter_make_screenshot_on_failure,
splinter_remote_url,
splinter_screenshot_dir,
splinter_selenium_implicit_wait,
splinter_wait_time,
splinter_selenium_socket_timeout,
splinter_selenium_speed,
splinter_webdriver_executable,
splinter_window_size,
splinter_browser_class,
splinter_clean_cookies_urls,
splinter_screenshot_getter_html,
splinter_screenshot_getter_png,
splinter_screenshot_encoding,
splinter_headless,
session_tmpdir,
browser_pool,
):
"""Splinter browser instance getter. To be used for getting of plugin.Browser's instances.
:return: function(parent). Each time this function will return new instance of plugin.Browser class.
"""
def get_browser(splinter_webdriver, retry_count=3):
kwargs = get_args(
driver=splinter_webdriver,
download_dir=splinter_file_download_dir,
download_ftypes=splinter_download_file_types,
firefox_pref=splinter_firefox_profile_preferences,
firefox_prof_dir=splinter_firefox_profile_directory,
remote_url=splinter_remote_url,
executable=splinter_webdriver_executable,
headless=splinter_headless,
driver_kwargs=splinter_driver_kwargs,
)
try:
return splinter_browser_class(
splinter_webdriver,
visit_condition=splinter_browser_load_condition,
visit_condition_timeout=splinter_browser_load_timeout,
wait_time=splinter_wait_time,
**kwargs
)
except Exception: # NOQA
if retry_count > 1:
return get_browser(splinter_webdriver, retry_count - 1)
else:
raise
def prepare_browser(request, parent, retry_count=3):
splinter_webdriver = request.getfixturevalue("splinter_webdriver")
splinter_session_scoped_browser = request.getfixturevalue(
"splinter_session_scoped_browser"
)
splinter_close_browser = request.getfixturevalue("splinter_close_browser")
browser_key = id(parent)
browser = browser_pool.get(browser_key)
if not splinter_session_scoped_browser:
browser = get_browser(splinter_webdriver)
if splinter_close_browser:
request.addfinalizer(browser.quit)
elif not browser:
browser = browser_pool[browser_key] = get_browser(splinter_webdriver)
if request.scope == "function":
def _take_screenshot_on_failure():
if splinter_make_screenshot_on_failure and getattr(
request.node, "splinter_failure", True
):
_take_screenshot(
request=request,
fixture_name=parent.__name__,
session_tmpdir=session_tmpdir,
browser_instance=browser,
splinter_screenshot_dir=splinter_screenshot_dir,
splinter_screenshot_getter_html=splinter_screenshot_getter_html,
splinter_screenshot_getter_png=splinter_screenshot_getter_png,
splinter_screenshot_encoding=splinter_screenshot_encoding,
)
request.addfinalizer(_take_screenshot_on_failure)
try:
if splinter_webdriver not in browser.driver_name.lower():
raise IOError(f"webdriver does not match (requested: {splinter_webdriver} "
f", available: {browser.driver_name.lower()})")
if hasattr(browser, "driver"):
browser.driver.implicitly_wait(splinter_selenium_implicit_wait)
browser.driver.set_speed(splinter_selenium_speed)
browser.driver.command_executor.set_timeout(
splinter_selenium_socket_timeout
)
browser.driver.command_executor._conn.timeout = (
splinter_selenium_socket_timeout
)
if splinter_window_size and splinter_webdriver != "chrome":
# Chrome cannot resize the window
# https://github.com/SeleniumHQ/selenium/issues/3508
browser.driver.set_window_size(*splinter_window_size)
try:
browser.cookies.delete()
except (IOError, HTTPException, WebDriverException):
LOGGER.warning("Error cleaning browser cookies", exc_info=True)
for url in splinter_clean_cookies_urls:
browser.visit(url)
browser.cookies.delete()
if hasattr(browser, "driver"):
browser.visit_condition = splinter_browser_load_condition
browser.visit_condition_timeout = splinter_browser_load_timeout
browser.visit("about:blank")
except (IOError, HTTPException, WebDriverException, MaxRetryError):
# we lost browser, try to restore the justice
try:
browser.quit()
except Exception: # NOQA
pass
LOGGER.warning("Error preparing the browser", exc_info=True)
if retry_count < 1:
raise
else:
browser = browser_pool[browser_key] = get_browser(splinter_webdriver)
prepare_browser(request, parent, retry_count - 1)
return browser
return prepare_browser
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
"""Assign the report to the item for further usage."""
outcome = yield
rep = outcome.get_result()
if rep.outcome == "failed":
item.splinter_failure = rep
else:
item.splinter_failure = None
@pytest.fixture
def browser(request, browser_instance_getter):
"""Browser fixture."""
return browser_instance_getter(request, browser)
@pytest.fixture(scope="session")
def session_browser(request, browser_instance_getter):
"""Session scoped browser fixture."""
return browser_instance_getter(request, session_browser)
class SplinterXdistPlugin(object):
"""Plugin class to defer pytest-xdist hook handler."""
def __init__(self, screenshot_dir):
"""Initialize the SplinterXdistPlugin with the required configuration."""
self.screenshot_dir = screenshot_dir
def pytest_testnodedown(self, node, error):
"""Copy screenshots back from remote nodes to have them on the master."""
for screenshot in getattr(node, "slaveoutput", {}).get("screenshots", []):
screenshot_dir = os.path.join(self.screenshot_dir, screenshot["class_name"])
if not os.path.exists(screenshot_dir):
os.makedirs(screenshot_dir)
for fil in screenshot["files"]:
encoding = fil.get("encoding")
with codecs.open(
os.path.join(screenshot_dir, fil["file_name"]),
"wb",
**dict(encoding=encoding) if encoding else {}
) as fd:
fd.write(fil["content"])
def pytest_configure(config):
"""Register pytest-splinter's deferred plugin."""
if config.pluginmanager.getplugin("xdist"):
screenshot_dir = os.path.abspath(config.option.splinter_screenshot_dir)
config.pluginmanager.register(
SplinterXdistPlugin(screenshot_dir=screenshot_dir)
)
def pytest_addoption(parser): # pragma: no cover
"""Pytest hook to add custom command line option(s)."""
group = parser.getgroup("splinter", "splinter integration for browser testing")
group.addoption(
"--splinter-webdriver",
help="pytest-splinter webdriver",
type=str,
choices=list(splinter.browser._DRIVERS.keys()),
dest="splinter_webdriver",
metavar="DRIVER",
default=None,
)
group.addoption(
"--splinter-remote-url",
help="pytest-splinter remote webdriver url ",
metavar="URL",
dest="splinter_remote_url",
default=None,
)
group.addoption(
"--splinter-wait-time",
help="splinter explicit wait, seconds",
type=int,
dest="splinter_wait_time",
metavar="SECONDS",
default=None,
)
group.addoption(
"--splinter-implicit-wait",
help="pytest-splinter selenium implicit wait, seconds",
type=int,
dest="splinter_webdriver_implicit_wait",
metavar="SECONDS",
default=5,
)
group.addoption(
"--splinter-speed",
help="pytest-splinter selenium speed, seconds",
type=int,
dest="splinter_webdriver_speed",
metavar="SECONDS",
default=0,
)
group.addoption(
"--splinter-socket-timeout",
help="pytest-splinter socket timeout, seconds",
type=int,
dest="splinter_webdriver_socket_timeout",
metavar="SECONDS",
default=120,
)
group.addoption(
"--splinter-session-scoped-browser",
help="pytest-splinter should use a single browser instance per test session. Defaults to true.",
action="store",
dest="splinter_session_scoped_browser",
metavar="false|true",
type=str,
choices=["false", "true"],
default="true",
)
group.addoption(
"--splinter-make-screenshot-on-failure",
help="pytest-splinter should take browser screenshots on test failure. Defaults to true.",
action="store",
dest="splinter_make_screenshot_on_failure",
metavar="false|true",
type=str,
choices=["false", "true"],
default="true",
)
group.addoption(
"--splinter-screenshot-dir",
help="pytest-splinter browser screenshot directory. Defaults to the current directory.",
action="store",
dest="splinter_screenshot_dir",
metavar="DIR",
default=".",
)
group.addoption(
"--splinter-webdriver-executable",
help="pytest-splinter webdrive executable path. Defaults to unspecified in which case it is taken from PATH",
action="store",
dest="splinter_webdriver_executable",
metavar="DIR",
default="",
)
group.addoption(
"--splinter-headless",
help="Run the browser in headless mode.",
action="store_true",
dest="splinter_headless",
)