Esempio n. 1
0
    def get_instance(self):
        """
       Get WebDriver Instance based on the browser configuration

        Returns:
            'WebDriver Instance'
        """
        if self.browser == "iexplorer":
            # todo: make this work
            driver = webdriver.Ie()
            self.log.info("Running tests on Internet Explorer")
        elif self.browser == "firefox":
            self.log.info("Running tests on Firefox")
            driver = webdriver.Firefox(configs.geckodriver_path())
        elif self.browser == "chrome":
            self.log.info("Running tests on Chrome")
            driver = webdriver.Chrome(configs.chromedriver_path())
        else:
            raise WdfError("Unknown browser")
        # Setting Driver Implicit Time out in seconds for An Element
        driver.implicitly_wait(3)
        # Maximize the window
        driver.maximize_window()

        return driver
Esempio n. 2
0
 def setUp(self):
     self.driver = webdriver.Chrome(
         executable_path=configs.chromedriver_path())
     self.driver.delete_all_cookies()
     # NOTE: In addCleanup, the first in, is executed last.
     self.addCleanup(self.driver.quit)
     self.addCleanup(self.screen_shot)
     self.driver.implicitly_wait(5)
Esempio n. 3
0
    def test_window_sizing_and_moving(self):
        # not going to need original window thus minimizing it right away
        self.driver.minimize_window()

        # going to create my own window with my own options
        options = Options()
        options.add_argument("window-size=800,600")
        driver = webdriver.Chrome(
            options=options,
            executable_path=configs.chromedriver_path(),
            service_args=["--log-path=../chromedriver.log"])
        driver.get("http://automationpractice.com/")
        current_position = driver.get_window_rect()
        print("Window size: width = {}px, height = {}px".format(
            current_position["width"], current_position["height"]))
        print("Window position: X = {}, Y = {}".format(current_position["x"],
                                                       current_position["y"]))
        time.sleep(1)

        driver.set_window_size(600, 400)
        size = driver.get_window_size()
        print("Window size: width = {}px, height = {}px".format(
            size["width"], size["height"]))
        time.sleep(1)

        driver.set_window_position(10, 10)
        time.sleep(1)

        driver.set_window_position(-100, -100)
        time.sleep(1)
        coordinates = driver.get_window_rect()
        print("Window position: X = {}, Y = {}".format(coordinates["x"],
                                                       coordinates["y"]))

        driver.set_window_position(100, 100)
        time.sleep(1)

        driver.minimize_window()
        time.sleep(1)
        size = driver.get_window_size()
        print("Window size: width = {}px, height = {}px".format(
            size["width"], size["height"]))

        driver.maximize_window()
        time.sleep(1)
        size = driver.get_window_size()
        print("Window size: width = {}px, height = {}px".format(
            size["width"], size["height"]))
Esempio n. 4
0
    def test_headless_mode(self):
        # closing original window
        self.driver.close()
        self.driver.quit()

        options = Options()
        options.add_argument(configs.read_config()["headless"])
        options.add_argument("window-size=800,600")
        driver = webdriver.Chrome(
            options=options,
            executable_path=configs.chromedriver_path(),
            service_args=["--log-path=../chromedriver.log"])
        self.driver = driver
        driver.get("http://google.com/")
        print(driver.get_window_size())
        self.assertIn("Google", driver.title)
Esempio n. 5
0
from selenium import webdriver
from selenium.webdriver import ActionChains

from utils.configs import chromedriver_path

with webdriver.Chrome(executable_path=chromedriver_path(),
                      service_log_path=r"../chromedriver.log") as driver:
    # try accessing a hidden sub menu
    driver.get("http://automationpractice.com/index.php?controller=contact")
    menu = driver.find_element_by_css_selector(
        ".sf-menu > li:nth-child(2) > a:nth-child(1)")
    ActionChains(driver).move_to_element(menu).perform()

    hidden_submenu = driver.find_element_by_css_selector(
        ".sf-menu > li:nth-child(2) > ul:nth-child(2) > li:nth-child(2) > a:nth-child(1)"
    )
    ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()

    # try some html5 drag-and-drop
    driver.get(
        "https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_draganddrop"
    )
    # notice the switch_to frame!
    driver.switch_to.frame("iframeResult")

    source_element = driver.find_element_by_id("drag1")
    dest_element = driver.find_element_by_id("div1")

    # not working
    ActionChains(driver).drag_and_drop(source_element, dest_element).perform()
Esempio n. 6
0
 def setUpClass(cls):
     print('Setting up, once per class %s' % cls.__name__)
     cls.driver = webdriver.Chrome(executable_path=chromedriver_path())
Esempio n. 7
0
 def setUp(self):
     # when speed is not a factor is best to use a new instance. see test parallelization and test isolation
     self.driver = webdriver.Chrome(
         executable_path=configs.chromedriver_path())