Beispiel #1
0
def test_format_failures():
    parser = Parser()

    stack1 = u"""Error: Expected 'Batman' to equal 'PANTS'.
        at stack (http://localhost:8888/__jasmine__/jasmine.js:1110)
        at http://localhost:8888/__spec__/global_spec.js:3"""

    stack2 = u"""Error: Expected 'Batman' to equal 'Superman'.
        at stack (http://localhost:8888/__jasmine__/jasmine.js:1110)
        at http://localhost:8888/__spec__/global_spec.js:6"""

    results = parser.parse([
        {u'status': u'passed', u'fullName': u'Context is this test passes'},
        {u'status': u'failed', u'fullName': u'Context is this test fails', u'failedExpectations': [{u'stack': stack1}]},
        {u'status': u'failed', u'fullName': u'Context is this test also fails',
            u'failedExpectations': [{u'stack': stack2}]},
    ])

    formatter = Formatter(results, colors=False)

    assert formatter.format_failures() ==\
        "Context is this test fails\n" +\
        "Error: Expected 'Batman' to equal 'PANTS'.\n" +\
        "        at http://localhost:8888/__spec__/global_spec.js:3\n" +\
        "Context is this test also fails\n" +\
        "Error: Expected 'Batman' to equal 'Superman'.\n" +\
        "        at http://localhost:8888/__spec__/global_spec.js:6\n"
Beispiel #2
0
def test_format_failures():
    parser = Parser()

    stack1 = u"""Error: Expected 'Batman' to equal 'PANTS'.
        at stack (http://localhost:8888/__jasmine__/jasmine.js:1110)
        at http://localhost:8888/__spec__/global_spec.js:3"""

    stack2 = u"""Error: Expected 'Batman' to equal 'Superman'.
        at stack (http://localhost:8888/__jasmine__/jasmine.js:1110)
        at http://localhost:8888/__spec__/global_spec.js:6"""

    results = parser.parse([
        {u'status': u'passed', u'fullName': u'Context is this test passes'},
        {u'status': u'failed', u'fullName': u'Context is this test fails', u'failedExpectations': [{u'stack': stack1}]},
        {u'status': u'failed', u'fullName': u'Context is this test also fails',
            u'failedExpectations': [{u'stack': stack2}]},
    ])

    formatter = Formatter(results, colors=False)

    assert formatter.format_failures() ==\
        "Context is this test fails\n" +\
        "Error: Expected 'Batman' to equal 'PANTS'.\n" +\
        "        at http://localhost:8888/__spec__/global_spec.js:3\n" +\
        "Context is this test also fails\n" +\
        "Error: Expected 'Batman' to equal 'Superman'.\n" +\
        "        at http://localhost:8888/__spec__/global_spec.js:6\n"
Beispiel #3
0
def test_clean_stack(results):
    formatter = Formatter(results, colors=False)

    dirty_stack = u"""Error: Expected 'Batman' to equal 'PANTS'.
        at stack (http://localhost:8888/__jasmine__/jasmine.js:1110)
        at http://localhost:8888/__spec__/global_spec.js:3"""

    assert formatter.clean_stack(dirty_stack) == """Error: Expected 'Batman' to equal 'PANTS'.
Beispiel #4
0
def test_clean_stack():
    formatter = Formatter(results, colors=False)

    dirty_stack = u"""Error: Expected 'Batman' to equal 'PANTS'.
        at stack (http://localhost:8888/__jasmine__/jasmine.js:1110)
        at http://localhost:8888/__spec__/global_spec.js:3"""

    assert formatter.clean_stack(dirty_stack) == """Error: Expected 'Batman' to equal 'PANTS'.
Beispiel #5
0
def test_format_browser_logs(results, browser_logs):
    formatter = Formatter(results, colors=False, browser_logs=browser_logs)

    dt1, dt2, dt3 = map(datetime.datetime.fromtimestamp, range(3))
    assert formatter.format_browser_logs() == (
        "Browser Session Logs:\n" + "  [{0} - INFO] hi\n".format(dt1) +
        "  [{0} - WARNING] lo\n".format(dt2) +
        "  [{0} - INFO] bye\n".format(dt3) + "\n")
Beispiel #6
0
def test_format_after_all_errors():
    parser = Parser()
    suite_results = parser.parse([{
        u'status': u'failed',
        u'failedExpectations': [{
            "message": "ahhh"
        }]
    }])

    formatter = Formatter([], suite_results=suite_results)
    assert "After All ahhh" in formatter.format_suite_failure()
Beispiel #7
0
def test_format_browser_logs(results, browser_logs):
    formatter = Formatter(results, colors=False, browser_logs=browser_logs)

    dt1, dt2, dt3 = map(datetime.datetime.fromtimestamp, range(3))
    assert formatter.format_browser_logs() == (
        "Browser Session Logs:\n" +
        "  [{0} - INFO] hi\n".format(dt1) +
        "  [{0} - WARNING] lo\n".format(dt2) +
        "  [{0} - INFO] bye\n".format(dt3) +
        "\n"
    )
Beispiel #8
0
def test_pending_with_message():
    parser = Parser()

    results = parser.parse([{
        u'status': u'pending',
        u'fullName': u'pending',
        u'pendingReason': 'the reason'
    }])

    formatter = Formatter(results, colors=False)
    assert formatter.format_pending() == "pending\n  Reason: the reason\n"
Beispiel #9
0
    def run(self, browser=None):
        try:
            test_server = TestServerThread()
            test_server.start()

            driver = browser if browser else os.environ.get('JASMINE_BROWSER', 'firefox')

            try:
                webdriver = __import__("selenium.webdriver.{0}.webdriver".format(driver), globals(), locals(), ['object'], 0)

                self.browser = webdriver.WebDriver()
            except ImportError as e:
                print("Browser {0} not found".format(driver))

            self.browser.get("http://localhost:{0}/".format(test_server.port))

            WebDriverWait(self.browser, 100).until(
                lambda driver: driver.execute_script("return jsApiReporter.finished;")
            )

            spec_results = []
            index = 0
            batch_size = 50

            parser = Parser()


            while True:
                results = self.browser.execute_script("return jsApiReporter.specResults({0}, {1})".format(index, batch_size))

                results = parser.parse(results)

                spec_results.extend(results)
                index += len(results)

                if not len(results) == batch_size:
                    break

            try:
                log = self.browser.get_log('browser')
            except WebDriverException:
                log = []

            formatter = Formatter(spec_results, browser_logs=log)

            sys.stdout.write(formatter.format())
            if len(list(formatter.results.failed())):
                sys.exit(1)
        finally:
            if hasattr(self, 'browser'):
                self.browser.close()
            if hasattr(self, 'test_server'):
                self.test_server.join()
Beispiel #10
0
    def run(self, browser=None):
        try:
            test_server = TestServerThread()
            test_server.start()

            driver = browser if browser else os.environ.get('JASMINE_BROWSER', 'firefox')

            try:
                webdriver = __import__("selenium.webdriver.{0}.webdriver".format(driver), globals(), locals(), ['object'], 0)

                self.browser = webdriver.WebDriver()
            except ImportError as e:
                print("Browser {0} not found".format(driver))

            self.browser.get("http://localhost:{0}/".format(test_server.port))

            WebDriverWait(self.browser, 100).until(
                lambda driver: driver.execute_script("return window.jsApiReporter.finished;")
            )

            self.browser.execute_script("""
                for (k in jsApiReporter.results()) {
                    var result = jsApiReporter.results()[k];
                    var messages = result.messages;

                    for (var i = 0; i < messages.length; i++) {
                        if (result.result === 'failed') {
                            messages[i].stack = messages[i].trace.stack;
                        }
                    }
                }
            """)

            results = self.browser.execute_script("return window.jsApiReporter.results()")
            suites = self.browser.execute_script("return window.jsApiReporter.suites()")

            spec_results = self._process_results(suites, results)

            results = Parser().parse(spec_results)
            formatter = Formatter(results, browser_logs=self.browser.get_log('browser'))

            sys.stdout.write(formatter.format())
            if list(results.failed()):
                sys.exit(1)
        finally:
            if hasattr(self, 'browser'):
                self.browser.close()
            if hasattr(self, 'test_server'):
                self.test_server.join()
Beispiel #11
0
    def run(self, browser=None):
        try:
            test_server = TestServerThread()
            test_server.start()

            driver = browser if browser else os.environ.get('JASMINE_BROWSER', 'firefox')

            try:
                webdriver = __import__("selenium.webdriver.{0}.webdriver".format(driver), globals(), locals(), ['object'], 0)

                self.browser = webdriver.WebDriver()
            except ImportError as e:
                print("Browser {0} not found".format(driver))

            self.browser.get("http://localhost:{0}/".format(test_server.port))

            WebDriverWait(self.browser, 100).until(
                lambda driver: driver.execute_script("return window.jsApiReporter.finished;")
            )

            self.browser.execute_script("""
                for (k in jsApiReporter.results()) {
                    var result = jsApiReporter.results()[k];
                    var messages = result.messages;

                    for (var i = 0; i < messages.length; i++) {
                        if (result.result === 'failed') {
                            messages[i].stack = messages[i].trace.stack;
                        }
                    }
                }
            """)

            results = self.browser.execute_script("return window.jsApiReporter.results()")
            suites = self.browser.execute_script("return window.jsApiReporter.suites()")

            spec_results = self._process_results(suites, results)

            results = Parser().parse(spec_results)
            formatter = Formatter(results)

            sys.stdout.write(formatter.format())
            if list(results.failed()):
                sys.exit(1)
        finally:
            if hasattr(self, 'browser'):
                self.browser.close()
            if hasattr(self, 'test_server'):
                self.test_server.join()
Beispiel #12
0
def test_pending_stack(results):
    formatter = Formatter(results, colors=False)

    assert formatter.format_pending() == "Context is this test is pending\n"
Beispiel #13
0
def test_format_progress(results):
    formatter = Formatter(results, colors=False)

    assert formatter.format_progress() == ".X.*"
Beispiel #14
0
def test_format_browser_logs_with_no_failures(passing_results, browser_logs):
    formatter = Formatter(passing_results, colors=False, browser_logs=browser_logs)

    assert formatter.format_browser_logs() == ""
Beispiel #15
0
def test_format_summary(results):
    formatter = Formatter(results, colors=False)

    assert formatter.format_summary() == "4 specs, 1 failed, 1 pending"
Beispiel #16
0
def test_format_progress(results):
    formatter = Formatter(results, colors=False)

    assert formatter.format_progress() == ".X.*"
Beispiel #17
0
def test_format_summary(results):
    formatter = Formatter(results, colors=False)

    assert formatter.format_summary() == "4 specs, 1 failed, 1 pending"
Beispiel #18
0
def test_format_browser_logs_with_no_failures(passing_results, browser_logs):
    formatter = Formatter(passing_results,
                          colors=False,
                          browser_logs=browser_logs)

    assert formatter.format_browser_logs() == ""
Beispiel #19
0
def test_pending_stack(results):
    formatter = Formatter(results, colors=False)

    assert formatter.format_pending() == "Context is this test is pending\n"