summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/old-tests/webdriver/base_test.py
blob: 851099936d29158f0084fb24ddb21fd97a249452 (plain)
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
import ConfigParser
import json
import os
import sys
import unittest

from network import get_lan_ip

repo_root = os.path.abspath(os.path.join(__file__, "../.."))
sys.path.insert(1, os.path.join(repo_root, "tools", "webdriver"))
sys.path.insert(1, os.path.join(repo_root, "tools", "wptserve"))
from wptserve import server
from selenium import webdriver


class WebDriverBaseTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.driver = create_driver()

        cls.webserver = server.WebTestHttpd(host=get_lan_ip())
        cls.webserver.start()
        cls.webserver.where_is = cls.webserver.get_url

    @classmethod
    def tearDownClass(cls):
        cls.webserver.stop()
        if cls.driver:
            cls.driver.quit()


def create_driver():
    config = ConfigParser.ConfigParser()
    config.read('webdriver.cfg')
    section = os.environ.get("WD_BROWSER", 'firefox')
    if config.has_option(section, 'url'):
        url = config.get(section, "url")
    else:
        url = 'http://127.0.0.1:4444/wd/hub'
    capabilities = None
    if config.has_option(section, 'capabilities'):
        try:
            capabilities = json.loads(config.get(section, "capabilities"))
        except:
            pass
    mode = 'compatibility'
    if config.has_option(section, 'mode'):
        mode = config.get(section, 'mode')
    if section == 'firefox':
        driver = webdriver.Firefox()
    elif section == 'chrome':
        driver = webdriver.Chrome()
    elif section == 'edge':
        driver = webdriver.Remote()
    elif section == 'ie':
        driver = webdriver.Ie()
    elif section == 'selendroid':
        driver = webdriver.Android()

    return driver