1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 04:50:09 +00:00

wait for page loaded in auto tests

This commit is contained in:
Lu Wang 2015-03-17 19:07:05 +08:00
parent d8b86df0e5
commit c1d3720036
3 changed files with 23 additions and 6 deletions

View File

@ -28,7 +28,7 @@ class BrowserTests(Common):
def tearDownClass(cls):
pass
def run_test_case(self, filename, pdf2htmlEX_args=[]):
def run_test_case(self, filename, pdf2htmlEX_args=[], page_must_load=True):
basefilename, extension = os.path.splitext(filename)
htmlfilename = basefilename + '.html'
@ -62,7 +62,7 @@ class BrowserTests(Common):
out_img = Image.open(pngfilename_out_fullpath)
pngfilename_ref_fullpath = os.path.join(png_out_dir, basefilename + '.ref.png')
self.generate_image(ref_htmlfilename, pngfilename_ref_fullpath)
self.generate_image(ref_htmlfilename, pngfilename_ref_fullpath, page_must_load=page_must_load)
ref_img = Image.open(pngfilename_ref_fullpath)
diff_img = ImageChops.difference(ref_img, out_img);
@ -83,7 +83,7 @@ class BrowserTests(Common):
# To test if the environment can detect any errors
# E.g. when network is down, 404 message is shown for any HTML message
with self.assertRaises(AssertionError):
self.run_test_case('test_fail.pdf')
self.run_test_case('test_fail.pdf', page_must_load=False)
def test_basic_text(self):
self.run_test_case('basic_text.pdf')

View File

@ -5,6 +5,9 @@
import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from browser_tests import BrowserTests
class test_local_browser(BrowserTests, unittest.TestCase):
@ -24,6 +27,11 @@ class test_local_browser(BrowserTests, unittest.TestCase):
cls.browser.quit()
super(test_local_browser, cls).tearDownClass()
def generate_image(self, html_file, png_file):
def generate_image(self, html_file, png_file, page_must_load=True):
self.browser.get('file://' + html_file)
try:
WebDriverWait(self.browser, 5).until(expected_conditions.presence_of_element_located((By.ID, 'page-container')))
except:
if page_must_load:
raise
self.browser.save_screenshot(png_file)

View File

@ -7,6 +7,9 @@ import sys
import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from sauceclient import SauceClient
from browser_tests import BrowserTests
@ -95,7 +98,7 @@ class test_remote_browser_base(BrowserTests):
try:
passed = (sys.exc_info() == (None, None, None))
branch = os.environ.get('TRAVIS_BRANCH', 'manual')
pull_request = os.environ.get('TRAVIS_PULL_REQUEST')
pull_request = os.environ.get('TRAVIS_PULL_REQUEST', 'false')
self.sauce.jobs.update_job(self.browser.session_id,
build_num=os.environ.get('TRAVIS_BUILD_NUMBER', '0'),
name='pdf2htmlEX',
@ -104,10 +107,16 @@ class test_remote_browser_base(BrowserTests):
tags = [pull_request] if pull_request != 'false' else [branch]
)
except:
raise
pass
def generate_image(self, html_file, png_file):
def generate_image(self, html_file, png_file, page_must_load=True):
self.browser.get(BASEURL + html_file)
try:
WebDriverWait(self.browser, 5).until(expected_conditions.presence_of_element_located((By.ID, 'page-container')))
except:
if page_must_load:
raise
self.browser.save_screenshot(png_file)
test_classnames = []