def test_handles_snapshot_errors(self):
        mock_healthcheck()
        mock_snapshot(fail=True)

        with patch('builtins.print') as mock_print:
            percy_snapshot(self.driver, 'Snapshot 1')

            mock_print.assert_any_call(f'{LABEL} Could not take DOM snapshot "Snapshot 1"')
    def test_disables_snapshots_when_the_healthcheck_errors(self):
        # no mocks will cause the request to throw an error

        with patch('builtins.print') as mock_print:
            percy_snapshot(self.driver, 'Snapshot 1')
            percy_snapshot(self.driver, 'Snapshot 2')

            mock_print.assert_called_with(f'{LABEL} Percy is not running, disabling snapshots')

        self.assertEqual(len(httpretty.latest_requests()), 0)
    def test_disables_snapshots_when_the_healthcheck_fails(self):
        mock_healthcheck(fail=True)

        with patch('builtins.print') as mock_print:
            percy_snapshot(self.driver, 'Snapshot 1')
            percy_snapshot(self.driver, 'Snapshot 2')

            mock_print.assert_called_with(f'{LABEL} Percy is not running, disabling snapshots')

        self.assertEqual(httpretty.last_request().path, '/percy/healthcheck')
    def test_disables_snapshots_when_the_healthcheck_version_is_wrong(self):
        mock_healthcheck(fail=True, fail_how='wrong-version')

        with patch('builtins.print') as mock_print:
            percy_snapshot(self.driver, 'Snapshot 1')
            percy_snapshot(self.driver, 'Snapshot 2')

            mock_print.assert_called_with(f'{LABEL} Unsupported Percy CLI version, 2.0.0')

        self.assertEqual(httpretty.last_request().path, '/percy/healthcheck')
    def test_disables_snapshots_when_the_healthcheck_version_is_missing(self):
        mock_healthcheck(fail=True, fail_how='no-version')

        with patch('builtins.print') as mock_print:
            percy_snapshot(self.driver, 'Snapshot 1')
            percy_snapshot(self.driver, 'Snapshot 2')

            mock_print.assert_called_with(
                f'{LABEL} You may be using @percy/agent which is no longer supported by this SDK. '
                'Please uninstall @percy/agent and install @percy/cli instead. '
                'https://docs.percy.io/docs/migrating-to-percy-cli')

        self.assertEqual(httpretty.last_request().path, '/percy/healthcheck')
    def test_posts_snapshots_to_the_local_percy_server(self):
        mock_healthcheck()
        mock_snapshot()

        percy_snapshot(self.driver, 'Snapshot 1')
        percy_snapshot(self.driver, 'Snapshot 2', enable_javascript=True)

        self.assertEqual(httpretty.last_request().path, '/percy/snapshot')

        s1 = httpretty.latest_requests()[2].parsed_body
        self.assertEqual(s1['name'], 'Snapshot 1')
        self.assertEqual(s1['url'], 'http://localhost:8000/')
        self.assertEqual(s1['dom_snapshot'], '<html><head></head><body>Snapshot Me</body></html>')
        self.assertRegex(s1['client_info'], r'percy-selenium-python/\d+')
        self.assertRegex(s1['environment_info'][0], r'selenium/\d+')
        self.assertRegex(s1['environment_info'][1], r'python/\d+')

        s2 = httpretty.latest_requests()[3].parsed_body
        self.assertEqual(s2['name'], 'Snapshot 2')
        self.assertEqual(s2['enable_javascript'], True)
示例#7
0
    def take_snapshots(self, browser):
        """Take DOM snapshots of a set of URLs and upload to Percy."""

        # homepage
        browser.get("http://localhost:8000/")
        browser.find_element_by_css_selector("#mainmenu label.open").click()
        browser.find_element_by_css_selector("input[type=search]").send_keys(
            "digital")
        percy_snapshot(browser, "Home")

        # landing page
        browser.get("http://localhost:8000/landing")
        percy_snapshot(browser, "Landing Page")

        # content page
        browser.get("http://localhost:8000/landing/content")
        percy_snapshot(browser, "Content Page")

        # projects list page
        browser.get("http://localhost:8000/projects/sponsored")
        browser.find_element_by_class_name("toggle").click()  # expand dropdown
        percy_snapshot(browser, "Projects List Page")

        # project page
        browser.get("http://localhost:8000/projects/derridas-margins/")
        percy_snapshot(browser, "Project Page")

        # people list page
        browser.get("http://localhost:8000/people/staff")
        browser.find_element_by_class_name("toggle").click()
        percy_snapshot(browser, "Person List Page")

        # profile page
        browser.get("http://localhost:8000/people/staffer/")
        percy_snapshot(browser, "Profile Page")

        # events list page
        browser.get("http://localhost:8000/events")
        browser.find_element_by_class_name("toggle").click()
        percy_snapshot(browser, "Events List Page")

        # event page
        browser.get("http://localhost:8000/events/2017/02/testing-course/")
        percy_snapshot(browser, "Event Page")

        # blog list page
        browser.get("http://localhost:8000/updates")
        browser.find_element_by_class_name("toggle").click()
        percy_snapshot(browser, "Blog List Page")

        # blog post
        browser.get(
            "http://localhost:8000/updates/2021/07/06/a-big-announcement/")
        percy_snapshot(browser, "Blog Post")

        # 404 page
        browser.get("http://localhost:8000/bad-url")
        percy_snapshot(browser, "404 Page")

        # 500 page
        browser.get("http://localhost:8000/500")
        percy_snapshot(browser, "500 Page")

        # site search
        browser.get("http://localhost:8000/search?q=digital")
        percy_snapshot(browser, "Site Search")
 def test_throws_error_when_a_name_is_not_provided(self):
     with self.assertRaises(Exception):
         percy_snapshot(self.driver)
示例#9
0
httpd = HTTPServer(('localhost', 8000), SimpleHTTPRequestHandler)
thread = Thread(target=httpd.serve_forever)
thread.setDaemon(True)
thread.start()

# launch firefox headless
ff_options = FirefoxOptions()
ff_options.add_argument('-headless')
browser = Firefox(options=ff_options)

# go to the example app
browser.get('http://localhost:8000')
browser.implicitly_wait(10)

# snapshot empty state
percy_snapshot(browser, 'Empty Todo State')

# snapshot with a new todo
new_todo_input = browser.find_element_by_class_name('new-todo')
new_todo_input.send_keys('Try Percy')
new_todo_input.send_keys(Keys.ENTER)
percy_snapshot(browser, 'With a Todo')

# snapshot with a completed todo
todo_toggle = browser.find_element_by_class_name('toggle')
todo_toggle.click()
percy_snapshot(browser, 'Completed Todo')

# clean up
browser.quit()
httpd.shutdown()
示例#10
0
    def take_snapshots(self, browser, dark_mode=False):
        """Take DOM snapshots of a set of URLs and upload to Percy."""

        dark_mode_str = ""  # empty string in light mode

        # dark mode switch
        browser.get("http://*****:*****@media (min-width: 900px) { ul#about-menu { left: auto !important; } }"
        percy_snapshot(
            browser, "About submenu%s" % dark_mode_str, percy_css=about_menu_css
        )

        # 404 page
        browser.get("http://localhost:8000/en/bad-url/")
        percy_snapshot(browser, "404 Page%s" % dark_mode_str)

        # 500 page
        browser.get("http://localhost:8000/_500/")
        percy_snapshot(browser, "500 Page%s" % dark_mode_str)
示例#11
0
from selenium import webdriver
from percy import percy_snapshot

browser = webdriver.Chrome()
browser.get('https://www.somkiat.cc')
browser.implicitly_wait(10)
percy_snapshot(browser, 'Home Page')