def setUpClass(cls):
        super(IntegrationTests, cls).setUpClass()

        cls.driver = webdriver.Chrome()
        loader = percy.ResourceLoader(webdriver=cls.driver)
        cls.percy_runner = percy.Runner(loader=loader)
        cls.percy_runner.initialize_build()
Пример #2
0
    def __init__(
        self,
        browser,
        headless=False,
        options=None,
        remote=None,
        wait_timeout=10,
    ):
        self._browser = browser.lower()
        self._headless = headless
        self._options = options
        self._wait_timeout = wait_timeout

        self._driver = self.get_webdriver(remote)
        self._driver.implicitly_wait(2)

        self._wd_wait = WebDriverWait(self.driver, wait_timeout)
        self._last_ts = 0
        self._url = None

        self._window_idx = 0  # switch browser tabs

        self.percy_runner = percy.Runner(
            loader=percy.ResourceLoader(
                webdriver=self.driver,
                base_url="/assets",
                root_dir="tests/assets",
            )
        )
        self.percy_runner.initialize_build()
    def setUpClass(cls):
        super(IntegrationTests, cls).setUpClass()

        options = Options()
        if 'DASH_TEST_CHROMEPATH' in os.environ:
            options.binary_location = os.environ['DASH_TEST_CHROMEPATH']

        cls.driver = webdriver.Chrome(chrome_options=options)

        root_static_dir = os.path.abspath(
            os.path.join(
                os.path.dirname(__file__),
                '..',
                'assets'
            )
        )

        if os.environ.get('PERCY_ENABLED', False):
            loader = percy.ResourceLoader(
                webdriver=cls.driver,
                base_url='/assets',
                root_dir=root_static_dir
            )
            cls.percy_runner = percy.Runner(loader=loader)
            cls.percy_runner.initialize_build()
Пример #4
0
    def __init__(
        self,
        browser,
        headless=False,
        options=None,
        remote=None,
        download_path=None,
        wait_timeout=10,
    ):
        self._browser = browser.lower()
        self._headless = headless
        self._options = options
        self._download_path = download_path
        self._wait_timeout = wait_timeout

        self._driver = until(lambda: self.get_webdriver(remote), timeout=1)
        self._driver.implicitly_wait(2)

        self._wd_wait = WebDriverWait(self.driver, wait_timeout)
        self._last_ts = 0
        self._url = None

        self._window_idx = 0  # switch browser tabs

        self.percy_runner = percy.Runner(loader=percy.ResourceLoader(
            webdriver=self.driver,
            base_url="/assets",
            root_dir="tests/assets",
        ))
        self.percy_runner.initialize_build()

        logger.debug("initialize browser with arguments")
        logger.debug("  headless => %s", self._headless)
        logger.debug("  download_path => %s", self._download_path)
Пример #5
0
    def setUpClass(cls):
        super(Tests, cls).setUpClass()

        if os.environ.get('PERCY_ENABLED', False):
            loader = percy.ResourceLoader(webdriver=cls.driver)
            percy_config = percy.Config(default_widths=[1280])
            cls.percy_runner = percy.Runner(loader=loader, config=percy_config)
            cls.percy_runner.initialize_build()
    def test_snapshot(self, mock):
        root_dir = os.path.join(TEST_FILES_DIR, 'static')
        webdriver = FakeWebdriver()
        loader = percy.ResourceLoader(root_dir=root_dir, base_url='/assets/', webdriver=webdriver)
        config = percy.Config(access_token='foo')
        runner = percy.Runner(config=config, loader=loader)

        response_text = json.dumps(SIMPLE_BUILD_FIXTURE)
        mock.post('https://percy.io/api/v1/builds/', text=response_text)
        runner.initialize_build()

        # Plain snapshot without a missing resource.
        response_text = json.dumps(SIMPLE_SNAPSHOT_FIXTURE)
        mock.post('https://percy.io/api/v1/builds/123/snapshots/', text=response_text)
        mock.post('https://percy.io/api/v1/snapshots/256/finalize', text='{"success": true}')
        runner.snapshot()

        # Snapshot with a missing resource.
        response_text = json.dumps({
            'data': {
                'id': '256',
                'type': 'snapshots',
                'relationships': {
                    'self': '/api/v1/snapshots/256',
                    'missing-resources': {
                        'data': [
                            {
                                'type': 'resources',
                                'id': loader.snapshot_resources[0].sha,
                            },
                        ],
                    },
                },
            },
        })
        mock.post('https://percy.io/api/v1/builds/123/snapshots/', text=response_text)
        mock.post('https://percy.io/api/v1/builds/123/resources/', text='{"success": true}')
        mock.post('https://percy.io/api/v1/snapshots/256/finalize', text='{"success": true}')
        runner.snapshot(name='foo', enable_javascript=True, widths=[1280])

        # Assert that kwargs are passed through correctly to create_snapshot.
        assert mock.request_history[3].json()['data']['attributes'] == {
            'enable-javascript': True,
            'name': 'foo',
            'widths': [1280],
        }

        # Assert that the snapshot resource was uploaded correctly.
        assert mock.request_history[4].json() == {
            'data': {
                'type': 'resources',
                'id': loader.snapshot_resources[0].sha,
                'attributes': {
                    'base64-content': utils.base64encode(FakeWebdriver.page_source)
                },
            },
        }
Пример #7
0
    def setUpClass(cls):
        super(IntegrationTests, cls).setUpClass()
        cls.driver = webdriver.Chrome()

        if ('PERCY_PROJECT' in os.environ
                and os.environ['PERCY_PROJECT'] == 'solvebio/contrib/dash'):
            loader = percy.ResourceLoader(webdriver=cls.driver)
            cls.percy_runner = percy.Runner(loader=loader)

            cls.percy_runner.initialize_build()
Пример #8
0
    def setUpClass(cls):
        super(IntegrationTests, cls).setUpClass()
        cls.driver = webdriver.Chrome()

        loader = percy.ResourceLoader(webdriver=cls.driver,
                                      base_url='/assets',
                                      root_dir='tests/assets')
        cls.percy_runner = percy.Runner(loader=loader)

        cls.percy_runner.initialize_build()
Пример #9
0
 def Percy_Initialize_Build(self, access_token):
     driver = BuiltIn().get_library_instance('Selenium2Library')._current_browser()
     root_static_dir = os.path.join(os.path.dirname(__file__), '/Users/InternDN19.01.02/Documents/joomla_build2')
     loader = percy.ResourceLoader(
       root_dir=root_static_dir,
       base_url='/joomla_build2',
       webdriver=driver,
     )
     config = percy.Config(access_token=access_token)
     self.percy_runner = percy.Runner(loader=loader, config=config)
     self.percy_runner.initialize_build()
Пример #10
0
    def setUpClass(cls):
        super(IntegrationTests, cls).setUpClass()

        options = Options()

        if 'DASH_TEST_CHROMEPATH' in os.environ:
            options.binary_location = os.environ['DASH_TEST_CHROMEPATH']

        cls.driver = webdriver.Chrome(chrome_options=options)
        loader = percy.ResourceLoader(webdriver=cls.driver)
        cls.percy_runner = percy.Runner(loader=loader)
        cls.percy_runner.initialize_build()
Пример #11
0
    def test_initialize_build_raises_error_when_token_incorrect(self, mock):
        root_dir = os.path.join(TEST_FILES_DIR, 'static')
        loader = percy.ResourceLoader(root_dir=root_dir, base_url='/assets/')
        config = percy.Config(access_token='foo')
        runner = percy.Runner(config=config, loader=loader)

        response_text = json.dumps(SIMPLE_ERROR_RESPONSE_FIXTURE)
        mock.post('https://percy.io/api/v1/repos/foo/bar/builds/',
                  text=response_text)

        self.assertRaises(errors.AuthError,
                          lambda: runner.initialize_build(repo='foo/bar'))
    def test_initialize_build(self, mock):
        root_dir = os.path.join(TEST_FILES_DIR, 'static')
        loader = percy.ResourceLoader(root_dir=root_dir, base_url='/assets/')
        config = percy.Config(access_token='foo')
        runner = percy.Runner(config=config, loader=loader)

        response_text = json.dumps(SIMPLE_BUILD_FIXTURE)
        mock.post('https://percy.io/api/v1/builds/', text=response_text)
        runner.initialize_build()

        # Whitebox check that the current build data is set correctly.
        assert runner._current_build == SIMPLE_BUILD_FIXTURE
        assert runner.build_id == SIMPLE_BUILD_FIXTURE['data']['id']
Пример #13
0
def percy(request):
    import percy

    # Initialize Percy.
    loader = percy.ResourceLoader(
        root_dir=settings.STATIC_ROOT, base_url=quote(settings.STATIC_URL)
    )
    percy_config = percy.Config(default_widths=settings.PERCY_DEFAULT_TESTING_WIDTHS)
    percy = percy.Runner(loader=loader, config=percy_config)
    percy.initialize_build()

    request.addfinalizer(percy.finalize_build)
    return percy
Пример #14
0
    def __init__(
        self,
        browser,
        remote=False,
        remote_url=None,
        headless=False,
        options=None,
        download_path="",
        percy_run=True,
        percy_finalize=True,
        percy_assets_root="",
        wait_timeout=10,
        pause=False,
    ):
        self._browser = browser.lower()
        self._remote_url = remote_url
        self._remote = (
            True if remote_url and remote_url != SELENIUM_GRID_DEFAULT else remote
        )
        self._headless = headless
        self._options = options
        self._download_path = download_path
        self._wait_timeout = wait_timeout
        self._percy_finalize = percy_finalize
        self._percy_run = percy_run
        self._pause = pause

        self._driver = until(self.get_webdriver, timeout=1)
        self._driver.implicitly_wait(2)

        self._wd_wait = WebDriverWait(self.driver, wait_timeout)
        self._last_ts = 0
        self._url = None

        self._window_idx = 0  # switch browser tabs

        if self._percy_run:
            self.percy_runner = percy.Runner(
                loader=percy.ResourceLoader(
                    webdriver=self.driver,
                    base_url="/assets",
                    root_dir=percy_assets_root,
                )
            )
            self.percy_runner.initialize_build()

        logger.info("initialize browser with arguments")
        logger.info("  headless => %s", self._headless)
        logger.info("  download_path => %s", self._download_path)
        logger.info("  percy asset root => %s", os.path.abspath(percy_assets_root))
Пример #15
0
    def setUpClass(cls):
        super(IntegrationTests, cls).setUpClass()

        cls.driver = webdriver.Chrome()

        python_version = sys.version.split(' ')[0]
        if '2.7' in python_version:
            root_static_dir = os.path.abspath(
                os.path.join(os.path.dirname(__file__), '..', 'assets'))
            loader = percy.ResourceLoader(webdriver=cls.driver,
                                          base_url='/assets',
                                          root_dir=root_static_dir)
            cls.percy_runner = percy.Runner(loader=loader)
            print('>>> initialize_build {}'.format(python_version))
            cls.percy_runner.initialize_build()
 def Percy_Initialize_Build(self, **kwargs):
     driver = BuiltIn().get_library_instance('SeleniumLibrary').driver
     loader = percy.ResourceLoader(root_dir=kwargs.get('root_dir'),
                                   base_url=kwargs.get('base_url'),
                                   webdriver=driver)
     # api_url
     # access_token
     # default_widths
     config = percy.Config(**kwargs)
     self.percy_runner = percy.Runner(loader=loader, config=config)
     # branch
     # pull_request_number
     # parallel_nonce
     # parallel_total_shards
     # commit_data
     self.percy_runner.initialize_build(**kwargs)
    def test_finalize_build(self, mock):
        config = percy.Config(access_token='foo')
        runner = percy.Runner(config=config)

        self.assertRaises(errors.UninitializedBuildError, lambda: runner.finalize_build())

        response_text = json.dumps(SIMPLE_BUILD_FIXTURE)
        mock.post('https://percy.io/api/v1/builds/', text=response_text)
        runner.initialize_build()

        mock.post('https://percy.io/api/v1/builds/123/finalize', text='{"success": true}')
        runner.finalize_build()
        assert mock.request_history[1].json() == {}

        # Whitebox check that the current build data is reset.
        assert runner._current_build == None
Пример #18
0
    def setUpClass(cls):
        super(IntegrationTests, cls).setUpClass()

        options = Options()
        capabilities = DesiredCapabilities.CHROME
        capabilities["loggingPrefs"] = {"browser": "SEVERE"}

        if "DASH_TEST_CHROMEPATH" in os.environ:
            options.binary_location = os.environ["DASH_TEST_CHROMEPATH"]

        cls.driver = webdriver.Chrome(options=options,
                                      desired_capabilities=capabilities)
        loader = percy.ResourceLoader(webdriver=cls.driver,
                                      base_url="/assets",
                                      root_dir="tests/assets")
        cls.percy_runner = percy.Runner(loader=loader)
        cls.percy_runner.initialize_build()
Пример #19
0
    def setUp(self):
        self.webdriver = webdriver.Chrome()
        self.webdriver.get(self.live_server_url)

        root_static_dir = os.path.join(os.path.dirname(__file__), '../../',
                                       'static')

        loader = percy.ResourceLoader(
            root_dir=root_static_dir,
            # Prepend `/assets` to all of the files in the static directory, to match production assets.
            # This is only needed if your static assets are served from a nested directory.
            base_url='/static/',
            webdriver=self.webdriver,
        )

        self.percy_runner = percy.Runner(loader=loader)
        self.percy_runner.initialize_build()
Пример #20
0
    def __init__(self, browser, remote=None, wait_timeout=10):
        self._browser = browser.lower()
        self._wait_timeout = wait_timeout

        self._driver = self.get_webdriver(remote)
        self._driver.implicitly_wait(2)

        self._wd_wait = WebDriverWait(self.driver, wait_timeout)
        self._last_ts = 0
        self._url = None

        self.percy_runner = percy.Runner(loader=percy.ResourceLoader(
            webdriver=self.driver,
            base_url="/assets",
            root_dir="tests/assets",
        ))
        self.percy_runner.initialize_build()
Пример #21
0
    def setUpClass(cls):
        super(IntegrationTests, cls).setUpClass()

        options = Options()
        capabilities = DesiredCapabilities.CHROME
        capabilities['loggingPrefs'] = {'browser': 'SEVERE'}

        if 'DASH_TEST_CHROMEPATH' in os.environ:
            options.binary_location = os.environ['DASH_TEST_CHROMEPATH']

        cls.driver = webdriver.Chrome(options=options,
                                      desired_capabilities=capabilities)
        loader = percy.ResourceLoader(webdriver=cls.driver,
                                      base_url='/assets',
                                      root_dir='tests/assets')
        cls.percy_runner = percy.Runner(loader=loader)
        cls.percy_runner.initialize_build()
Пример #22
0
    def test_initialize_build_sends_missing_resources(self, mock):
        root_dir = os.path.join(TEST_FILES_DIR, 'static')
        loader = percy.ResourceLoader(root_dir=root_dir, base_url='/assets/')
        config = percy.Config(access_token='foo')
        runner = percy.Runner(config=config, loader=loader)

        build_fixture = {
            'data': {
                'id': '123',
                'type': 'builds',
                'relationships': {
                    'self': "/api/v1/snapshots/123",
                    'missing-resources': {
                        'data': [
                            {
                                'type': 'resources',
                                'id': loader.build_resources[0].sha,
                            },
                        ],
                    },
                },
            },
        }
        mock.post('https://percy.io/api/v1/repos/foo/bar/builds/',
                  text=json.dumps(build_fixture))
        mock.post('https://percy.io/api/v1/builds/123/resources/',
                  text='{"success": true}')
        runner.initialize_build(repo='foo/bar')

        # Make sure the missing resources were uploaded. The mock above will not fail if not called.
        with open(loader.build_resources[0].local_path, 'r') as f:
            content = f.read()
        assert len(content) > 0
        assert mock.request_history[1].json() == {
            'data': {
                'type': 'resources',
                'id': loader.build_resources[0].sha,
                'attributes': {
                    'base64-content': utils.base64encode(content)
                },
            },
        }
Пример #23
0
    def setUpClass(cls):
        super(IntegrationTests, cls).setUpClass()

        options = Options()
        options.add_argument('--no-sandbox')

        capabilities = DesiredCapabilities.CHROME
        capabilities['loggingPrefs'] = {'browser': 'SEVERE'}

        if 'DASH_TEST_CHROMEPATH' in os.environ:
            options.binary_location = os.environ['DASH_TEST_CHROMEPATH']

        cls.driver = webdriver.Chrome(
            chrome_options=options,
            desired_capabilities=capabilities,
            service_args=["--verbose", "--log-path=chrome.log"])

        cls.percy_runner = percy.Runner(loader=percy.ResourceLoader(
            webdriver=cls.driver, base_url='/assets', root_dir='tests/assets'))

        cls.percy_runner.initialize_build()
Пример #24
0
    def setUpClass(cls):
        super(IntegrationTests, cls).setUpClass()

        options = Options()
        options.add_argument("--no-sandbox")

        capabilities = DesiredCapabilities.CHROME
        capabilities["loggingPrefs"] = {"browser": "SEVERE"}

        if "DASH_TEST_CHROMEPATH" in os.environ:
            options.binary_location = os.environ["DASH_TEST_CHROMEPATH"]

        cls.driver = webdriver.Chrome(
            options=options,
            desired_capabilities=capabilities,
            service_args=["--verbose", "--log-path=chrome.log"],
        )

        cls.percy_runner = percy.Runner(loader=percy.ResourceLoader(
            webdriver=cls.driver, base_url="/assets", root_dir="tests/assets"))

        cls.percy_runner.initialize_build()
 def test_safe_snapshot_when_disabled(self):
     runner = percy.Runner()
     assert runner._is_enabled == False
     runner.snapshot()
 def test_safe_finalize_when_disabled(self):
     runner = percy.Runner()
     assert runner._is_enabled == False
     runner.finalize_build()
 def test_init(self):
     runner = percy.Runner()
     assert runner.client.config.default_widths == []
     runner = percy.Runner(config=percy.Config(default_widths=[1280, 375]))
     assert runner.client.config.default_widths == [1280, 375]
 def test_safe_initialize_when_disabled(self, mock):
     runner = percy.Runner()
     assert runner._is_enabled == False
     runner.initialize_build()