Commit dedbc5ec authored by Jérome Perrin's avatar Jérome Perrin

test

parent 6b8ebcd1
......@@ -46,7 +46,8 @@ setup(name=name,
'erp5.util',
'selenium',
'psutil',
'image'
'image',
'requests',
],
zip_safe=True,
test_suite='test',
......
......@@ -43,6 +43,7 @@ from selenium.webdriver.support import expected_conditions as EC
from PIL import Image
from io import BytesIO
import requests
from utils import SlapOSInstanceTestCase
from utils import findFreeTCPPort
......@@ -121,11 +122,11 @@ class BrowserCompatibilityMixin(WebServerMixin):
def setUp(self):
super(BrowserCompatibilityMixin, self).setUp()
self.driver = webdriver.Remote(
command_executor=self.computer_partition.getConnectionParameterDict()['url'],
command_executor=self.computer_partition.getConnectionParameterDict()['backend-url'],
desired_capabilities=self.desired_capabilities)
def tearDown(self):
self.driver.close()
self.driver.quit()
super(BrowserCompatibilityMixin, self).tearDown()
def test_user_agent(self):
......@@ -150,20 +151,26 @@ class BrowserCompatibilityMixin(WebServerMixin):
def test_window_and_screen_size(self):
size = json.loads(self.driver.execute_script('''
return JSON.stringify({
'screen.availWidth': window.screen.availWidth,
'screen.availHeight': window.screen.availHeight,
'screen.width': window.screen.width,
'screen.height': window.screen.height,
'screen.pixelDepth': window.screen.pixelDepth,
'innerWidth': window.innerWidth,
'innerHeight': window.innerHeight })'''))
# Xvfb is configured like this
self.assertEqual(1024, size['screen.availWidth'])
self.assertEqual(768, size['screen.availHeight'])
self.assertEqual(1024, size['screen.width'])
self.assertEqual(768, size['screen.height'])
self.assertEqual(24, size['screen.pixelDepth'])
# window size must not be 0 (wrong firefox integration report this)
self.assertGreater(size['innerWidth'], 0)
self.assertGreater(size['innerHeight'], 0)
#def test_resize_window(self):
# self.fail('TODO')
#def test_upload_file(self):
# self.fail('TODO')
class SeleniumServerTestCase(SlapOSInstanceTestCase):
"""Test the remote driver on a minimal web server.
......@@ -173,10 +180,10 @@ class SeleniumServerTestCase(SlapOSInstanceTestCase):
return (os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'software.cfg')), )
class TestBrowserSelection(SeleniumServerTestCase, WebServerMixin):
class TestBrowserSelection(WebServerMixin, SeleniumServerTestCase):
def test_firefox(self):
parameter_dict = self.computer_partition.getConnectionParameterDict()
webdriver_url = parameter_dict['url']
webdriver_url = parameter_dict['backend-url']
driver = webdriver.Remote(
command_executor=webdriver_url,
......@@ -192,7 +199,7 @@ class TestBrowserSelection(SeleniumServerTestCase, WebServerMixin):
def test_chrome(self):
parameter_dict = self.computer_partition.getConnectionParameterDict()
webdriver_url = parameter_dict['url']
webdriver_url = parameter_dict['backend-url']
driver = webdriver.Remote(
command_executor=webdriver_url,
......@@ -209,9 +216,9 @@ class TestBrowserSelection(SeleniumServerTestCase, WebServerMixin):
driver.execute_script('return navigator.userAgent'))
driver.quit()
def test_firefox_desired_version(self):
def XXX_test_firefox_desired_version(self):
parameter_dict = self.computer_partition.getConnectionParameterDict()
webdriver_url = parameter_dict['url']
webdriver_url = parameter_dict['backend-url']
desired_capabilities = DesiredCapabilities.FIREFOX.copy()
desired_capabilities['version'] = '51.0.1'
......@@ -234,20 +241,19 @@ class TestBrowserSelection(SeleniumServerTestCase, WebServerMixin):
def test_parralel_connections(self):
parameter_dict = self.computer_partition.getConnectionParameterDict()
webdriver_url = parameter_dict['url']
return
webdriver_url = parameter_dict['backend-url']
queue = multiprocessing.Queue()
def _test(q, server_url):
driver = webdriver.Remote(
command_executor=webdriver_url,
desired_capabilities=DesiredCapabilities.FIREFOX)
# XXX we need to sleep a bit to wait for browser to be ready before using it, otherwise selenium crash
sleep(2)
driver.get(server_url)
q.put(driver.title == 'Test page')
driver.quit()
# XXX
desired_capabilities= dict(DesiredCapabilities.FIREFOX, version='52.9.0esr')) #DesiredCapabilities.FIREFOX)
try:
driver.get(server_url)
q.put(driver.title == 'Test page')
finally:
driver.quit()
nb_workers = 10
workers = []
......@@ -266,6 +272,48 @@ class TestBrowserSelection(SeleniumServerTestCase, WebServerMixin):
[queue.get() for _ in range(nb_workers)])
class TestFrontend(WebServerMixin, SeleniumServerTestCase):
def test_register_url(self):
parameter_dict = self.computer_partition.getConnectionParameterDict()
register_url = parameter_dict['register-url']
parsed = urlparse.urlparse(register_url)
self.assertEqual('node', parsed.username)
self.assertTrue(parsed.password)
self.assertIn(
# we don't do a proper register request, this response is 500.
'JsonException: Expected to read a START_MAP but instead have: END',
requests.get(register_url, verify=False).text)
def test_admin(self):
parameter_dict = self.computer_partition.getConnectionParameterDict()
admin_url = parameter_dict['admin-url']
parsed = urlparse.urlparse(admin_url)
self.assertEqual('admin', parsed.username)
self.assertTrue(parsed.password)
self.assertIn(
'Grid Console',
requests.get(admin_url, verify=False).text)
def test_browser_use_hub(self):
parameter_dict = self.computer_partition.getConnectionParameterDict()
webdriver_url = parameter_dict['url']
parsed = urlparse.urlparse(webdriver_url)
self.assertEqual('selenium', parsed.username)
self.assertTrue(parsed.password)
driver = webdriver.Remote(
command_executor=webdriver_url,
desired_capabilities=DesiredCapabilities.CHROME)
driver.get(self.server_url)
self.assertEqual('Test page', driver.title)
driver.quit()
class TestFirefox52(BrowserCompatibilityMixin, SeleniumServerTestCase):
desired_capabilities = dict(DesiredCapabilities.FIREFOX, version='52.9.0esr')
user_agent = 'Gecko/20100101 Firefox/52.0'
......@@ -281,9 +329,14 @@ class TestChrome69(BrowserCompatibilityMixin, SeleniumServerTestCase):
user_agent = 'Chrome/69.0.3497.0'
#del TestFirefox52
del TestFirefox60
del TestBrowserSelection
if 1:
del TestFrontend
del TestChrome69
del TestFirefox52
#del TestFirefox60
del TestBrowserSelection
# more test:
# XXX run ERP5 test !
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment