WebDriver: Add support to import and run W3C tests
[WebKit-https.git] / WebDriverTests / imported / w3c / tools / wptrunner / wptrunner / browsers / ie.py
1 from .base import Browser, ExecutorBrowser, require_arg
2 from ..webdriver_server import InternetExplorerDriverServer
3 from ..executors import executor_kwargs as base_executor_kwargs
4 from ..executors.executorselenium import (SeleniumTestharnessExecutor,
5                                           SeleniumRefTestExecutor)
6 from ..executors.executorinternetexplorer import InternetExplorerDriverWdspecExecutor
7
8 __wptrunner__ = {"product": "ie",
9                  "check_args": "check_args",
10                  "browser": "InternetExplorerBrowser",
11                  "executor": {"testharness": "SeleniumTestharnessExecutor",
12                               "reftest": "SeleniumRefTestExecutor",
13                               "wdspec": "InternetExplorerDriverWdspecExecutor"},
14                  "browser_kwargs": "browser_kwargs",
15                  "executor_kwargs": "executor_kwargs",
16                  "env_extras": "env_extras",
17                  "env_options": "env_options"}
18
19
20 def check_args(**kwargs):
21     require_arg(kwargs, "webdriver_binary")
22
23 def browser_kwargs(test_type, run_info_data, **kwargs):
24     return {"webdriver_binary": kwargs["webdriver_binary"],
25             "webdriver_args": kwargs.get("webdriver_args")}
26
27 def executor_kwargs(test_type, server_config, cache_manager, run_info_data,
28                     **kwargs):
29     from selenium.webdriver import DesiredCapabilities
30
31     ieOptions = {}
32     ieOptions["requireWindowFocus"] = True
33     capabilities = {}
34     capabilities["browserName"] = "internet explorer"
35     capabilities["platformName"] = "windows"
36     capabilities["se:ieOptions"] = ieOptions
37     executor_kwargs = base_executor_kwargs(test_type, server_config,
38                                            cache_manager, **kwargs)
39     executor_kwargs["close_after_done"] = True
40     executor_kwargs["capabilities"] = capabilities
41     return executor_kwargs
42
43 def env_extras(**kwargs):
44     return []
45
46 def env_options():
47     return {"host": "web-platform.test",
48             "bind_hostname": "true",
49             "supports_debugger": False}
50
51 class InternetExplorerBrowser(Browser):
52     used_ports = set()
53
54     def __init__(self, logger, webdriver_binary, webdriver_args=None):
55         Browser.__init__(self, logger)
56         self.server = InterentExplorerDriverServer(self.logger,
57                                                    binary=webdriver_binary,
58                                                    args=webdriver_args)
59         self.webdriver_host = "localhost"
60         self.webdriver_port = self.server.port
61
62     def start(self, **kwargs):
63         self.server.start()
64
65     def stop(self, force=False):
66         self.server.stop(force=force)
67
68     def pid(self):
69         return self.server.pid
70
71     def is_alive(self):
72         # TODO(ato): This only indicates the server is alive,
73         # and doesn't say anything about whether a browser session
74         # is active.
75         return self.server.is_alive()
76
77     def cleanup(self):
78         self.stop()
79
80     def executor_browser(self):
81         return ExecutorBrowser, {"webdriver_url": self.server.url}