def test_createWebDriver_WithGrid(self):
        '''
        This will test a grid setup by making a connection to Sauce Labs.

        This test will normally be commented out since it will use billable automation hours 
        on sauce labs.
        '''
        config_reader = MockConfigWithSauceLabs()
        
        driver_factory = WebDriverFactory(config_reader)
        self._driver = driver_factory.create_webdriver()
        exception = None
        try:
            self._driver.get('http://saucelabs.com/test/guinea-pig')
            self.assertGreater(self._driver.session_id, 0, "Did not get a return session id from Sauce.")
        except Exception as e:
            exception = e
        finally:
            # Make sure we quit sauce labs webdriver to avoid getting billed additonal hours.
            try:
                self._driver.quit()
            except:
                pass
        
        if exception != None:
            raise e
    def test_createWebDriver_WithAppium_withAppProvidedByEnv(self):
        '''
        This will test a grid setup with Appium by making a connection to Sauce Labs.

        This test will normally be commented out since it will use billable automation hours 
        on sauce labs.
        '''
        config_reader = MockAppiumConfigWithSauceLabsNoApp()
        os.environ[WebDriverFactory.DESIRED_CAPABILITIES_ENV_PREFIX + "app"] = \
            "http://github.com/wiredrive/wtframework/raw/gh-pages/binaries/TestApp6.0.app.zip"
        driver_factory = WebDriverFactory(config_reader)
        exception = None
        try:
            self._driver = driver_factory.create_webdriver("test_createWebDriver_WithAppium")
            self.assertGreater(
                self._driver.session_id, 0, "Did not get a return session id from Sauce.")
        except Exception as e:
            exception = e
        finally:
            # Make sure we quit sauce labs webdriver to avoid getting billed
            # additonal hours.
            try:
                self._driver.quit()
            except:
                pass

        if exception != None:
            raise e
    def test_createWebDriver_WithLocalBrowser(self):
        '''
        This will test this by opening firefox and trying to fetch Google with it.

        This test will normally be commented out since it spawns annoying browser windows.
        When making changes to WebDriverFactory, please run this test manually.
        '''
        config_reader = mock(ConfigReader)
        when(config_reader).get(
            WebDriverFactory.DRIVER_TYPE_CONFIG).thenReturn("LOCAL")
        when(config_reader).get(
            WebDriverFactory.BROWSER_TYPE_CONFIG).thenReturn("PHANTOMJS")

        try:
            phantom_js_path = WTF_CONFIG_READER.get(WebDriverFactory.PHANTOMEJS_EXEC_PATH)
            when(config_reader).get(
                WebDriverFactory.PHANTOMEJS_EXEC_PATH).thenReturn(phantom_js_path)
        except KeyError:
            when(config_reader).get(
                WebDriverFactory.PHANTOMEJS_EXEC_PATH).thenRaise(KeyError())

        driver_factory = WebDriverFactory(config_reader)
        self._driver = driver_factory.create_webdriver()

        # This whould open a local instance of Firefox.
        self._driver.get("http://www.google.com")

        # Check if we can use this instance of webdriver.
        self._driver.find_element_by_name('q')  # google's famous q element.
    def test_create_phantomjs_driver(self):
        config_reader = mock(ConfigReader)
        when(config_reader).get(
            WebDriverFactory.DRIVER_TYPE_CONFIG).thenReturn("LOCAL")
        when(config_reader).get(
            WebDriverFactory.BROWSER_TYPE_CONFIG).thenReturn("PHANTOMJS")

        # Check if the person running this test has a config specified for
        # phantom JS, otherwise use default.
        try:
            path = WTF_CONFIG_READER.get(WebDriverFactory.PHANTOMEJS_EXEC_PATH)
            when(config_reader).get(
                WebDriverFactory.PHANTOMEJS_EXEC_PATH).thenReturn(path)
        except KeyError:
            when(config_reader).get(
                WebDriverFactory.PHANTOMEJS_EXEC_PATH).thenRaise(KeyError())

        driver_factory = WebDriverFactory(config_reader)
        self._driver = driver_factory.create_webdriver()

        # This whould open a local instance of Firefox.
        self._driver.get("http://www.google.com")

        # Check if we can use this instance of webdriver.
        self._driver.find_element_by_name('q')  # google's famous q element.
Example #5
0
    def test_createWebDriver_WithGrid(self):
        '''
        This will test a grid setup by making a connection to Sauce Labs.

        This test will normally be commented out since it will use billable automation hours 
        on sauce labs.
        '''
        config_reader = MockConfigWithSauceLabs()

        driver_factory = WebDriverFactory(config_reader)
        self._driver = driver_factory.create_webdriver(
            "test_createWebDriver_WithGrid")
        exception = None
        try:
            self._driver.get('http://saucelabs.com/test/guinea-pig')
            self.assertGreater(self._driver.session_id, 0,
                               "Did not get a return session id from Sauce.")
        except Exception as e:
            exception = e
        finally:
            # Make sure we quit sauce labs webdriver to avoid getting billed additonal hours.
            try:
                self._driver.quit()
            except:
                pass

        if exception != None:
            raise e
    def test_create_phantomjs_driver(self):
        config_reader = mock(ConfigReader)
        when(config_reader).get(
            WebDriverFactory.DRIVER_TYPE_CONFIG).thenReturn("LOCAL")
        when(config_reader).get(
            WebDriverFactory.BROWSER_TYPE_CONFIG).thenReturn("PHANTOMJS")

        # Check if the person running this test has a config specified for
        # phantom JS, otherwise use default.
        try:
            path = WTF_CONFIG_READER.get(WebDriverFactory.PHANTOMEJS_EXEC_PATH)
            when(config_reader).get(
                WebDriverFactory.PHANTOMEJS_EXEC_PATH).thenReturn(path)
        except KeyError:
            when(config_reader).get(
                WebDriverFactory.PHANTOMEJS_EXEC_PATH).thenRaise(KeyError())

        driver_factory = WebDriverFactory(config_reader)
        self._driver = driver_factory.create_webdriver()

        # This whould open a local instance of Firefox.
        self._driver.get("http://www.google.com")

        # Check if we can use this instance of webdriver.
        self._driver.find_element_by_name('q')  # google's famous q element.
    def test_createWebDriver_WithLocalBrowser(self):
        '''
        This will test this by opening firefox and trying to fetch Google with it.

        This test will normally be commented out since it spawns annoying browser windows.
        When making changes to WebDriverFactory, please run this test manually.
        '''
        config_reader = mock(ConfigReader)
        when(config_reader).get(
            WebDriverFactory.DRIVER_TYPE_CONFIG).thenReturn("LOCAL")
        when(config_reader).get(
            WebDriverFactory.BROWSER_TYPE_CONFIG).thenReturn("PHANTOMJS")

        try:
            phantom_js_path = WTF_CONFIG_READER.get(
                WebDriverFactory.PHANTOMEJS_EXEC_PATH)
            when(config_reader).get(
                WebDriverFactory.PHANTOMEJS_EXEC_PATH).thenReturn(
                    phantom_js_path)
        except KeyError:
            when(config_reader).get(
                WebDriverFactory.PHANTOMEJS_EXEC_PATH).thenRaise(KeyError())

        driver_factory = WebDriverFactory(config_reader)
        self._driver = driver_factory.create_webdriver()

        # This whould open a local instance of Firefox.
        self._driver.get("http://www.google.com")

        # Check if we can use this instance of webdriver.
        self._driver.find_element_by_name('q')  # google's famous q element.
    def test_createWebDriver_WithAppium_withAppProvidedByEnv(self):
        '''
        This will test a grid setup with Appium by making a connection to Sauce Labs.

        This test will normally be commented out since it will use billable automation hours 
        on sauce labs.
        '''
        config_reader = MockAppiumConfigWithSauceLabsNoApp()
        os.environ[WebDriverFactory.DESIRED_CAPABILITIES_ENV_PREFIX + "app"] = \
            "http://github.com/wiredrive/wtframework/raw/gh-pages/binaries/TestApp6.0.app.zip"
        driver_factory = WebDriverFactory(config_reader)
        exception = None
        try:
            self._driver = driver_factory.create_webdriver(
                "test_createWebDriver_WithAppium")
            self.assertGreater(self._driver.session_id, 0,
                               "Did not get a return session id from Sauce.")
        except Exception as e:
            exception = e
        finally:
            # Make sure we quit sauce labs webdriver to avoid getting billed
            # additonal hours.
            try:
                self._driver.quit()
            except:
                pass

        if exception != None:
            raise e
    def test_env_vars_folded_into_desired_capabilities(self):
        config_reader = MockAppiumConfigWithSauceLabs()
        path_to_app = "//:path_to_app"
        env_vars_stub = {WebDriverFactory.DESIRED_CAPABILITIES_ENV_PREFIX + "app": path_to_app}
        driver_factory = WebDriverFactory(config_reader=config_reader, env_vars=env_vars_stub)

        # Set an env variable WTF_selenium_desired_capabilities_app
        dc = driver_factory._generate_desired_capabilities("mytest")
        self.assertEqual(path_to_app, dc['app'])
    def test_env_vars_folded_into_desired_capabilities(self):
        config_reader = MockAppiumConfigWithSauceLabs()
        path_to_app = "//:path_to_app"
        env_vars_stub = {
            WebDriverFactory.DESIRED_CAPABILITIES_ENV_PREFIX + "app":
            path_to_app
        }
        driver_factory = WebDriverFactory(config_reader=config_reader,
                                          env_vars=env_vars_stub)

        # Set an env variable WTF_selenium_desired_capabilities_app
        dc = driver_factory._generate_desired_capabilities("mytest")
        self.assertEqual(path_to_app, dc['app'])
    def test_createWebDriver_WithLocalBrowser(self):
        '''
        This will test this by opening firefox and trying to fetch Google with it.

        This test will normally be commented out since it spawns annoying browser windows.
        When making changes to WebDriverFactory, please run this test manually.
        '''
        config_reader = self._mocker.CreateMock(ConfigReader)
        config_reader.get(WebDriverFactory.DRIVER_TYPE_CONFIG).InAnyOrder().AndReturn("LOCAL")
        config_reader.get(WebDriverFactory.BROWSER_TYPE_CONFIG).InAnyOrder().AndReturn("FIREFOX")
        self._mocker.ReplayAll()
        
        driver_factory = WebDriverFactory(config_reader)
        self._driver = driver_factory.create_webdriver()
        self._driver.get("http://www.google.com")
        self._driver.find_element_by_name('q') #google's famous q element.
    def test_createWebDriver_WithHtmlUnitDriver(self):
        "Simple unit test to check if instantiating an HTMLUnit driver works."
        config_reader = self._mocker.CreateMock(ConfigReader)
        config_reader.get(WebDriverFactory.DRIVER_TYPE_CONFIG).InAnyOrder().AndReturn("LOCAL")
        config_reader.get(WebDriverFactory.BROWSER_TYPE_CONFIG).InAnyOrder().AndReturn("FIREFOX")
        config_reader.get("selenium.server", \
                                                 WebDriverFactory._DEFAULT_SELENIUM_SERVER_FOLDER)\
                                                 .InAnyOrder()\
                                                 .AndReturn(WebDriverFactory._DEFAULT_SELENIUM_SERVER_FOLDER)
        self._mocker.ReplayAll()

        driver_factory = WebDriverFactory(config_reader)
        self._driver = driver_factory.create_webdriver()
        self._driver.get("http://www.google.com/")
        print "page title:", self._driver.title
        self._driver.find_element_by_name("q") #Google's famous 'q' element.