instead of that patch, please use this no-zombies version that kills the started process group instead of pid-only.
On Wed, Jan 25, 2017 at 6:31 PM, George Gelashvili <ggelashv...@pivotal.io> wrote: > ah > That diff was generated before the python 3 patch was applied. This should > work against master > > Cheers, > George > > On Tue, Jan 24, 2017 at 4:43 AM, Dave Page <dp...@pgadmin.org> wrote: > >> On Fri, Jan 20, 2017 at 5:33 PM, George Gelashvili >> <ggelashv...@pivotal.io> wrote: >> > Thanks for bringing that to our attention! Here's the latest patch >> >> piranha:pgadmin4 dpage$ git apply >> ~/Downloads/acceptance-tests-with-server-start-and-polling.diff >> error: patch failed: web/regression/test_utils.py:69 >> error: web/regression/test_utils.py: patch does not apply >> >> :-( >> >> > On Fri, Jan 20, 2017 at 10:38 AM, Dave Page <dp...@pgadmin.org> wrote: >> >> >> >> On Thu, Jan 19, 2017 at 10:07 PM, George Gelashvili >> >> <ggelashv...@pivotal.io> wrote: >> >> > >> >> > Here is an updated patch which starts the server up when the test >> starts >> >> > and >> >> > uses the values from config.py for server name etc. It still requires >> >> > installing chromedriver before running. Should we add something to >> the >> >> > readme about that? >> >> >> >> Yes, we definitely should (including download site URL) >> >> >> >> > On Tue, Jan 17, 2017 at 11:09 AM, Atira Odhner <aodh...@pivotal.io> >> >> > wrote: >> >> >> >> >> >> Thanks for your feedback, Dave! >> >> >> >> >> >> We can put the tests under the regression directory. I think that >> makes >> >> >> sense. >> >> >> I'm not picturing these tests being module specific, but we may >> want to >> >> >> enable running it as a separate suite of tests. >> >> >> >> >> >> Thanks for the callout about the port and title. We'll make sure >> those >> >> >> are >> >> >> pulled from config or that the pgAdmin server is spun up by the test >> >> >> with >> >> >> specific values. >> >> >> >> >> >> I have a couple ideas about why the test might not have been running >> >> >> for >> >> >> you. I think the patch we attached didn't spin up its own pgAdmin >> yet >> >> >> and it >> >> >> definitely doesn't fill in username/password if your app is running >> >> >> that >> >> >> way. That's part of the WIP-ness :-P >> >> >> >> >> >> -Tira >> >> >> >> >> >> Hi >> >> >> >> >> >> On Thu, Jan 12, 2017 at 10:41 PM, George Gelashvili >> >> >> <ggelashvili(at)pivotal(dot)io> wrote: >> >> >> > 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 >> >> >> > <ggelashvili(at)pivotal(dot)io> >> >> >> > wrote: >> >> >> >> >> >> >> >> Hi there, >> >> >> >> >> >> >> >> We are working on browser-automation-based acceptance tests that >> >> >> >> exercise >> >> >> >> pgAdmin4 the way a user might. >> >> >> >> >> >> Nice! >> >> >> >> >> >> >> The first "connect to database" test works, but at the moment >> >> >> >> depends >> >> >> >> on >> >> >> >> Chrome and 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. >> >> >> >> >> >> A few thoughts: >> >> >> >> >> >> - If these tests are to run as part of the regression suite, the >> >> >> framework for them should live under that directory. >> >> >> >> >> >> - Are any of the tests likely to be module-specific? If so, they >> >> >> should really be part of the relevant module as the regression tests >> >> >> are. If they're more general/less tightly coupled, then I don't see >> a >> >> >> problem with them residing where they are. >> >> >> >> >> >> - Please take care not to include changes to .gitgnore files that >> >> >> aren't relevant to the rest of us. >> >> >> >> >> >> - The port number is hard-coded in the test. >> >> >> >> >> >> - You've hard-coded the string "pgAdmin 4". We've tried to keep that >> >> >> title as a config option in config.py, so you should pull the string >> >> >> from there rather than hard-coding it. >> >> >> >> >> >> - The connect test fails for me (Mac, Python 2.7). I have a >> suspicion >> >> >> that this may be because when the test starts chromedriver, OS X >> >> >> prompts the user about whether a listening port should be opened, >> but >> >> >> the tests don't wait (though, I tested with 3 servers configured and >> >> >> it failed with the same error on the second and third as well, long >> >> >> after I clicked OK on the prompt): >> >> >> >> >> >> Traceback (most recent call last): >> >> >> File >> >> >> >> >> >> "/Users/dpage/git/pgadmin4/web/acceptance/test_connects_to_ >> database.py", >> >> >> line 32, in runTest >> >> >> self.assertEqual("pgAdmin 4", self.driver.title) >> >> >> AssertionError: 'pgAdmin 4' != u'localhost' >> >> >> >> >> >> - Please keep tests in the pgadmin. namespace >> (pgadmin.acceptance.??). >> >> >> >> >> >> - It looks like running a single test won't work yet (because of >> >> >> TestsGeneratorRegistry.load_generators('pgadmin.%s.tests' % >> >> >> arguments['pkg'])) >> >> >> >> >> >> Thanks! >> >> >> >> >> >> -- >> >> >> Dave Page >> >> >> Blog: http://pgsnake.blogspot.com >> >> >> Twitter: @pgsnake >> >> >> >> >> >> EnterpriseDB UK: http://www.enterprisedb.com >> >> >> The Enterprise PostgreSQL Company >> >> >> >> >> >> >> >> > >> >> > >> >> > >> >> > -- >> >> > Sent via pgadmin-hackers mailing list (pgadmin-hack...@postgresql.or >> g) >> >> > To make changes to your subscription: >> >> > http://www.postgresql.org/mailpref/pgadmin-hackers >> >> > >> >> >> >> >> >> >> >> -- >> >> Dave Page >> >> Blog: http://pgsnake.blogspot.com >> >> Twitter: @pgsnake >> >> >> >> EnterpriseDB UK: http://www.enterprisedb.com >> >> The Enterprise PostgreSQL Company >> > >> > >> >> >> >> -- >> Dave Page >> Blog: http://pgsnake.blogspot.com >> Twitter: @pgsnake >> >> EnterpriseDB UK: http://www.enterprisedb.com >> The Enterprise PostgreSQL Company >> > >
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/requirements_py3.txt b/requirements_py3.txt index f68db7a8..9565a6e4 100644 --- a/requirements_py3.txt +++ b/requirements_py3.txt @@ -35,6 +35,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/pgadmin/acceptance/__init__.py b/web/pgadmin/acceptance/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/web/pgadmin/acceptance/tests/__init__.py b/web/pgadmin/acceptance/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/web/pgadmin/acceptance/tests/connect_to_database_feature_test.py b/web/pgadmin/acceptance/tests/connect_to_database_feature_test.py new file mode 100644 index 00000000..a3baa45c --- /dev/null +++ b/web/pgadmin/acceptance/tests/connect_to_database_feature_test.py @@ -0,0 +1,78 @@ +############################################################# +# +# pgAdmin 4 - PostgreSQL Tools +# +# Copyright (C) 2013 - 2017, The pgAdmin Development Team +# This software is released under the PostgreSQL Licence +# +############################################################## + +import time + +from selenium import webdriver +from selenium.common.exceptions import NoSuchElementException +from selenium.webdriver import ActionChains + +from pgadmin.utils.route import BaseTestGenerator + +import subprocess +import os +import signal +import config as app_config +from regression import test_utils +from regression.utils.app_starter import AppStarter +from regression.utils.pgadmin_page import PgadminPage + + +class ConnectsToDatabaseFeatureTest(BaseTestGenerator): + """ + Tests that a database connection can be created from the UI + """ + + def setUp(self): + if app_config.SERVER_MODE: + self.skipTest("Currently, config is set to start pgadmin in server mode. " + "This test doesn't know username and password so doesn't work in server mode") + + self.pgadmin_process = subprocess.Popen(["python", "pgAdmin4.py"], shell=False, preexec_fn=os.setsid, + stderr=open(os.devnull, 'w')) + + driver = webdriver.Chrome() + self.app_starter = AppStarter(driver, app_config) + self.page = PgadminPage(driver, app_config) + + test_utils.create_database(self.server, "acceptance_test_db") + + self.app_starter.start_app() + self.page.wait_for_app() + + + def runTest(self): + self.assertEqual(app_config.APP_NAME, self.page.driver.title) + self.page.wait_for_spinner_to_disappear() + + self.page.find_by_xpath("//*[@class='aciTreeText' and .='Servers']").click() + self.page.driver.find_element_by_link_text("Object").click() + ActionChains(self.page.driver) \ + .move_to_element(self.page.driver.find_element_by_link_text("Create")) \ + .perform() + self.page.find_by_partial_link_text("Server...").click() + + server_config = self.server + self.page.fill_input_by_field_name("name", server_config['name']) + self.page.find_by_partial_link_text("Connection").click() + self.page.fill_input_by_field_name("host", server_config['host']) + self.page.fill_input_by_field_name("port", server_config['port']) + self.page.fill_input_by_field_name("username", server_config['username']) + self.page.fill_input_by_field_name("password", server_config['db_password']) + self.page.find_by_xpath("//button[contains(.,'Save')]").click() + + self.page.find_by_xpath("//*[@id='tree']//*[.='" + server_config['name'] + "']") + + def tearDown(self): + self.page.driver.close() + os.killpg(os.getpgid(self.pgadmin_process.pid), signal.SIGTERM) + + def failureException(self, *args, **kwargs): + self.page.driver.save_screenshot('/tmp/pgadmin_test_screenshot.png') + return AssertionError(*args, **kwargs) 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 0581810b..723fce7e 100644 --- a/web/regression/.gitignore +++ b/web/regression/.gitignore @@ -1,4 +1,5 @@ parent_id.pkl regression.log +test_greenplum_config.json test_advanced_config.json test_config.json diff --git a/web/regression/README b/web/regression/README index 8cc29987..ae5d268d 100644 --- a/web/regression/README +++ b/web/regression/README @@ -103,6 +103,10 @@ Test Data Details Execution: ----------- +- For acceptance tests to run as part of the entire test suite, Chrome and chromedriver need to be installed: + get chromedriver from https://sites.google.com/a/chromium.org/chromedriver/downloads or a package manager + and make sure it is on the PATH + - The test framework is modular and pluggable and dynamically locates tests for modules which are discovered at runtime. All test cases are found and registered automatically by its module name in diff --git a/web/regression/test_utils.py b/web/regression/test_utils.py index 1f9f0522..68f36cbc 100644 --- a/web/regression/test_utils.py +++ b/web/regression/test_utils.py @@ -134,6 +134,24 @@ def create_database(server, db_name): traceback.print_exc(file=sys.stderr) +def create_table(server, db_name, table_name): + try: + connection = get_db_connection(db_name, + server['username'], + server['db_password'], + server['host'], + server['port']) + old_isolation_level = connection.isolation_level + connection.set_isolation_level(0) + pg_cursor = connection.cursor() + pg_cursor.execute('''CREATE TABLE "%s" (name VARCHAR, value NUMERIC)''' % table_name) + pg_cursor.execute('''INSERT INTO "%s" VALUES ('Some-Name', 6)''' % table_name) + connection.set_isolation_level(old_isolation_level) + connection.commit() + + except Exception: + traceback.print_exc(file=sys.stderr) + def drop_database(connection, database_name): """This function used to drop the database""" if database_name not in ["postgres", "template1", "template0"]: diff --git a/web/regression/utils/__init__.py b/web/regression/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/web/regression/utils/app_starter.py b/web/regression/utils/app_starter.py new file mode 100644 index 00000000..c093f046 --- /dev/null +++ b/web/regression/utils/app_starter.py @@ -0,0 +1,24 @@ +import os +import subprocess + +import signal + + +class AppStarter: + + def __init__(self, driver, app_config): + self.driver = driver + self.app_config = app_config + + def start_app(self): + self.pgadmin_process = subprocess.Popen(["python", "pgAdmin4.py"], + shell=False, + preexec_fn=os.setsid, + stderr=open(os.devnull, 'w')) + + print("opening browser") + self.driver.get("http://" + self.app_config.DEFAULT_SERVER + ":" + str(self.app_config.DEFAULT_SERVER_PORT)) + + def stop_app(self): + self.driver.close() + os.killpg(os.getpgid(self.pgadmin_process.pid), signal.SIGTERM) diff --git a/web/regression/utils/pgadmin_page.py b/web/regression/utils/pgadmin_page.py new file mode 100644 index 00000000..1c8857f2 --- /dev/null +++ b/web/regression/utils/pgadmin_page.py @@ -0,0 +1,103 @@ +import time +from selenium.common.exceptions import NoSuchElementException +from selenium.webdriver import ActionChains + + +class PgadminPage: + def __init__(self, driver, app_config): + self.driver = driver + self.app_config = app_config + + def add_server(self, server_config): + 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_field_name("name", server_config['name']) + self.find_by_partial_link_text("Connection").click() + self.fill_input_by_field_name("host", server_config['host']) + self.fill_input_by_field_name("port", server_config['port']) + self.fill_input_by_field_name("username", server_config['username']) + self.fill_input_by_field_name("password", server_config['db_password']) + self.find_by_xpath("//button[contains(.,'Save')]").click() + + self.find_by_xpath("//*[@id='tree']//*[.='" + server_config['name'] + "']") + + def remove_server(self, server_config): + self.find_by_xpath("//*[@id='tree']//*[.='" + server_config['name'] + "']").click() + self.find_by_partial_link_text("Object").click() + self.find_by_partial_link_text("Delete/Drop").click() + time.sleep(0.5) + self.find_by_xpath("//button[contains(.,'OK')]").click() + + def toggle_open_tree_item(self, tree_item_text): + self.find_by_xpath("//*[@id='tree']//*[.='" + tree_item_text + "']/../*[@class='aciTreeButton']").click() + + def find_by_xpath(self, xpath): + return self.wait_for_element(lambda: self.driver.find_element_by_xpath(xpath)) + + def find_by_id(self, element_id): + return self.wait_for_element(lambda: self.driver.find_element_by_id(element_id)) + + 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_field_name(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 fill_codemirror_area_with(self, field_content): + self.find_by_xpath( + "//pre[contains(@class,'CodeMirror-line')]/../../../*[contains(@class,'CodeMirror-code')]").click() + ActionChains(self.driver).send_keys(field_content).perform() + + def wait_for_element(self, find_method_with_args): + def element_if_it_exists(): + try: + element = find_method_with_args() + if element.is_displayed() & element.is_enabled(): + return element + except NoSuchElementException: + return False + + return self._wait_for("element to exist", element_if_it_exists) + + def wait_for_spinner_to_disappear(self): + def spinner_has_disappeared(): + try: + self.driver.find_element_by_id("pg-spinner") + return False + except NoSuchElementException: + return True + + self._wait_for("spinner to disappear", spinner_has_disappeared) + + def wait_for_app(self): + def page_shows_app(): + if self.driver.title == self.app_config.APP_NAME: + return True + else: + self.driver.refresh() + return False + + self._wait_for("app to start", page_shows_app) + + def _wait_for(self, waiting_for_message, condition_met_function): + timeout = 5 + time_waited = 0 + sleep_time = 0.01 + + while time_waited < timeout: + result = condition_met_function() + if result: + return result + time_waited += sleep_time + time.sleep(sleep_time) + + raise RuntimeError("timed out waiting for " + waiting_for_message)
-- Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgadmin-hackers