here's the patch we forgot to attach. Also, you can see work on our branch
at:
https://github.com/pivotalsoftware/pgadmin4/tree/pivotal/acceptance-tests
On Thu, Jan 12, 2017 at 5:26 PM, George Gelashvili <[email protected]>
wrote:
> Hi there,
>
> We are working on browser-automation-based acceptance tests that exercise
> pgAdmin4 the way a user might.
>
> The first "connect to database" test works, but at the moment depends on
> Chrome and chromedriver
> <https://sites.google.com/a/chromium.org/chromedriver/>. We would
> appreciate feedback on any possible license or code style issues at this
> point, as well as any thoughts on adding this sort of test to the codebase.
>
> Thanks!
> George and Tira
>
diff --git a/requirements_py2.txt b/requirements_py2.txt
index 51170a45..de167121 100644
--- a/requirements_py2.txt
+++ b/requirements_py2.txt
@@ -36,6 +36,7 @@ testscenarios==0.5.0
testtools==2.0.0
traceback2==1.4.0
unittest2==1.1.0
+selenium==3.0.2
Werkzeug==0.9.6
WTForms==2.0.2
sqlparse==0.1.19
diff --git a/web/acceptance/__init__.py b/web/acceptance/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/web/acceptance/test_connects_to_database.py
b/web/acceptance/test_connects_to_database.py
new file mode 100644
index 00000000..e89ffaad
--- /dev/null
+++ b/web/acceptance/test_connects_to_database.py
@@ -0,0 +1,89 @@
+#############################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2017, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+##############################################################
+
+import json
+from unittest import TestCase
+
+import time
+from selenium import webdriver
+from selenium.common.exceptions import NoSuchElementException
+from selenium.webdriver import ActionChains
+
+from regression import test_setup
+from pgadmin.utils.route import BaseTestGenerator
+
+class ConnectsToDatabase(BaseTestGenerator):
+ """
+ Tests that a database connection can be created from the UI
+ """
+ def setUp(self):
+ self.driver = webdriver.Chrome()
+ self.driver.get("localhost:5050")
+
+ self.server_config = test_setup.config_data['server_credentials'][0]
+
+ def runTest(self):
+ self.assertEqual("pgAdmin 4", self.driver.title)
+ self._wait_for_spinner_to_disappear()
+
+ self._find_by_xpath("//*[@class='aciTreeText' and
.='Servers']").click()
+ self.driver.find_element_by_link_text("Object").click()
+ ActionChains(self.driver) \
+ .move_to_element(self.driver.find_element_by_link_text("Create")) \
+ .perform()
+ self._find_by_partial_link_text("Server...").click()
+
+ self._fill_input_by_xpath("name", self.server_config['name'])
+ self._find_by_partial_link_text("Connection").click()
+ self._fill_input_by_xpath("host", self.server_config['host'])
+ self._fill_input_by_xpath("port", self.server_config['db_port'])
+ self._fill_input_by_xpath("username",
self.server_config['db_username'])
+ self._fill_input_by_xpath("password",
self.server_config['db_password'])
+ self._find_by_xpath("//button[contains(.,'Save')]").click()
+
+ self._find_by_xpath("//*[@class='aciTreeText' and .='" +
self.server_config['name'] + "']")
+
+ def tearDown(self):
+ self.driver.close()
+
+ def _find_by_xpath(self, xpath):
+ return self._wait_for_element(lambda:
self.driver.find_element_by_xpath(xpath))
+
+ def _find_by_partial_link_text(self, link_text):
+ return self._wait_for_element(lambda:
self.driver.find_element_by_partial_link_text(link_text))
+
+ def _fill_input_by_xpath(self, field_name, field_content):
+ self._find_by_xpath("//input[@name='" + field_name + "']").clear()
+ self._find_by_xpath("//input[@name='" + field_name + "']").send_keys(
+ field_content)
+
+ def _wait_for_element(self, find_method_with_args):
+ timeout = 5
+ time_waited = 0
+ sleep_time = 0.01
+
+ while time_waited < timeout:
+ try:
+ element = find_method_with_args()
+ if element.is_displayed() & element.is_enabled():
+ return element
+ except NoSuchElementException:
+ time_waited += sleep_time
+ time.sleep(sleep_time)
+ pass
+
+ raise "Timed out waiting for element"
+
+ def _wait_for_spinner_to_disappear(self):
+ try:
+ while True:
+ self.driver.find_element_by_id("pg-spinner")
+ time.sleep(0.1)
+ except NoSuchElementException:
+ pass
diff --git a/web/pgadmin/utils/route.py b/web/pgadmin/utils/route.py
index f18d2c18..fed26a0f 100644
--- a/web/pgadmin/utils/route.py
+++ b/web/pgadmin/utils/route.py
@@ -54,20 +54,25 @@ class TestsGeneratorRegistry(ABCMeta):
ABCMeta.__init__(cls, name, bases, d)
@classmethod
- def load_generators(cls, pkg):
+ def load_generators(cls, *pkgs):
cls.registry = dict()
+ all_modules = []
+
+ for pkg in pkgs:
+ all_modules += find_modules(pkg, False, True)
+
+
# Check for SERVER mode
- if config.SERVER_MODE:
- for module_name in find_modules(pkg, False, True):
+ for module_name in all_modules:
+ if config.SERVER_MODE:
try:
if "tests." in str(module_name):
import_module(module_name)
except ImportError:
traceback.print_exc(file=sys.stderr)
- else:
- for module_name in find_modules(pkg, False, True):
+ else:
try:
# Exclude the test cases in browser node if SERVER_MODE
# is False
diff --git a/web/regression/.gitignore b/web/regression/.gitignore
index 570f022e..ed1d901d 100644
--- a/web/regression/.gitignore
+++ b/web/regression/.gitignore
@@ -1,4 +1,5 @@
parent_id.pkl
regression.log
test_config.json
+test_greenplum_config.json
test_advanced_config.json
diff --git a/web/regression/runtests.py b/web/regression/runtests.py
index 8d2a886a..fcc4e02c 100644
--- a/web/regression/runtests.py
+++ b/web/regression/runtests.py
@@ -135,7 +135,7 @@ def get_test_modules(arguments):
# Load the test modules which are in given package(i.e. in arguments.pkg)
if arguments['pkg'] is None or arguments['pkg'] == "all":
- TestsGeneratorRegistry.load_generators('pgadmin')
+ TestsGeneratorRegistry.load_generators('pgadmin', 'acceptance')
else:
TestsGeneratorRegistry.load_generators('pgadmin.%s.tests' %
arguments['pkg'])
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers