[setup-wiz] UI test command
This commit is contained in:
parent
89aff93a5e
commit
674308958a
6 changed files with 55 additions and 10 deletions
|
|
@ -344,6 +344,26 @@ def run_ui_tests(context, app=None, test=False, profile=False):
|
|||
if os.environ.get('CI'):
|
||||
sys.exit(ret)
|
||||
|
||||
@click.command('run-setup-wizard-ui-test')
|
||||
@click.option('--app', help="App to run tests on, leave blank for all apps")
|
||||
@click.option('--profile', is_flag=True, default=False)
|
||||
@pass_context
|
||||
def run_setup_wizard_ui_test(context, app=None, profile=False):
|
||||
"Run setup wizard UI test"
|
||||
import frappe.test_runner
|
||||
|
||||
site = get_site(context)
|
||||
frappe.init(site=site)
|
||||
frappe.connect()
|
||||
|
||||
ret = frappe.test_runner.run_setup_wizard_ui_test(app=app, verbose=context.verbose,
|
||||
profile=profile)
|
||||
if len(ret.failures) == 0 and len(ret.errors) == 0:
|
||||
ret = 0
|
||||
|
||||
if os.environ.get('CI'):
|
||||
sys.exit(ret)
|
||||
|
||||
@click.command('serve')
|
||||
@click.option('--port', default=8000)
|
||||
@click.option('--profile', is_flag=True, default=False)
|
||||
|
|
@ -485,6 +505,7 @@ commands = [
|
|||
reset_perms,
|
||||
run_tests,
|
||||
run_ui_tests,
|
||||
run_setup_wizard_ui_test,
|
||||
serve,
|
||||
set_config,
|
||||
watch,
|
||||
|
|
|
|||
|
|
@ -263,7 +263,6 @@ frappe.setup.SetupWizardSlide = class SetupWizardSlide extends frappe.ui.Slide {
|
|||
// }
|
||||
};
|
||||
|
||||
// ======================================================
|
||||
// Frappe slides settings
|
||||
// ======================================================
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ frappe.ui.Slide = class Slide {
|
|||
|
||||
this.$body = $(`<div class="slide-body">
|
||||
<div class="content text-center">
|
||||
<p class="lead">${this.title}</p>
|
||||
<p class="title lead">${this.title}</p>
|
||||
</div>
|
||||
<div class="form-wrapper">
|
||||
<div class="form"></div>
|
||||
|
|
@ -36,7 +36,7 @@ frappe.ui.Slide = class Slide {
|
|||
this.$form = this.$body.find(".form");
|
||||
this.$primary_btn = this.slides_footer.find('.btn-primary').addClass('primary');
|
||||
|
||||
if(this.help) this.$content.append($(`<p>${this.help}</p>`));
|
||||
if(this.help) this.$content.append($(`<p class="help">${this.help}</p>`));
|
||||
if(this.image_src) this.$content.append(
|
||||
$(`<img src="${this.image_src}" style="margin: 20px;">`));
|
||||
|
||||
|
|
|
|||
|
|
@ -139,6 +139,11 @@ def run_tests_for_module(module, verbose=False, tests=(), profile=False):
|
|||
|
||||
return _run_unittest(module=module, verbose=verbose, tests=tests, profile=profile)
|
||||
|
||||
def run_setup_wizard_ui_test(app=None, verbose=False, profile=False):
|
||||
'''Run setup wizard UI test using test_test_runner'''
|
||||
frappe.flags.run_setup_wizard_ui_test = 1
|
||||
return run_ui_tests(app, None, verbose, profile)
|
||||
|
||||
def run_ui_tests(app=None, test=None, verbose=False, profile=False):
|
||||
'''Run a single unit test for UI using test_test_runner'''
|
||||
module = importlib.import_module('frappe.tests.ui.test_test_runner')
|
||||
|
|
|
|||
|
|
@ -4,9 +4,15 @@ import unittest, os, frappe, time
|
|||
|
||||
class TestTestRunner(unittest.TestCase):
|
||||
def test_test_runner(self):
|
||||
if frappe.flags.run_setup_wizard_ui_test:
|
||||
for setup_wizard_test in frappe.get_hooks("setup_wizard_test"):
|
||||
passed = frappe.get_attr(setup_wizard_test)()
|
||||
self.assertTrue(passed)
|
||||
return
|
||||
|
||||
driver = TestDriver()
|
||||
driver.login()
|
||||
frappe.db.set_default('in_selenium', '1')
|
||||
driver.login()
|
||||
for test in get_tests():
|
||||
if test.startswith('#'):
|
||||
continue
|
||||
|
|
@ -26,6 +32,7 @@ class TestTestRunner(unittest.TestCase):
|
|||
driver.set_route('Form', 'Test Runner')
|
||||
driver.click_primary_action()
|
||||
driver.wait_for('#frappe-qunit-done', timeout=timeout)
|
||||
|
||||
console = driver.get_console()
|
||||
passed = 'Tests Passed' in console
|
||||
if frappe.flags.tests_verbose or not passed:
|
||||
|
|
@ -62,4 +69,3 @@ def get_tests_for(app):
|
|||
with open(tests_path, 'r') as fileobj:
|
||||
tests = fileobj.read().strip().splitlines()
|
||||
return tests
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class TestDriver(object):
|
|||
self.get('login')
|
||||
self.wait_for("#login_email")
|
||||
self.set_input("#login_email", "Administrator")
|
||||
self.set_input("#login_password", "admin")
|
||||
self.set_input("#login_password", "abcd1234")
|
||||
self.click('.btn-login')
|
||||
self.wait_for(wait_for_id)
|
||||
self.logged_in = True
|
||||
|
|
@ -87,6 +87,10 @@ class TestDriver(object):
|
|||
elem = self.find(xpath='//input[@data-fieldname="{0}"]'.format(fieldname))
|
||||
elem[0].send_keys(text)
|
||||
|
||||
def set_select(self, fieldname, text):
|
||||
elem = self.find(xpath='//select[@data-fieldname="{0}"]'.format(fieldname))
|
||||
elem[0].send_keys(text)
|
||||
|
||||
def set_text_editor(self, fieldname, text):
|
||||
elem = self.find(xpath='//div[@data-fieldname="{0}"]//div[@contenteditable="true"]'.format(fieldname))
|
||||
elem[0].send_keys(text)
|
||||
|
|
@ -99,7 +103,7 @@ class TestDriver(object):
|
|||
selector = self.cur_route + " " + selector
|
||||
return self.driver.find_elements_by_css_selector(selector)
|
||||
|
||||
def wait_for(self, selector=None, everywhere=False, timeout=20, xpath=None):
|
||||
def wait_for(self, selector=None, everywhere=False, timeout=20, xpath=None, for_invisible=False):
|
||||
if self.cur_route and not everywhere:
|
||||
selector = self.cur_route + " " + selector
|
||||
|
||||
|
|
@ -112,8 +116,12 @@ class TestDriver(object):
|
|||
selector = xpath
|
||||
|
||||
try:
|
||||
elem = self.get_wait(timeout).until(
|
||||
EC.presence_of_element_located((_by, selector)))
|
||||
if not for_invisible:
|
||||
elem = self.get_wait(timeout).until(
|
||||
EC.presence_of_element_located((_by, selector)))
|
||||
else:
|
||||
elem = self.get_wait(timeout).until(
|
||||
EC.invisibility_of_element_located((_by, selector)))
|
||||
return elem
|
||||
except Exception as e:
|
||||
# body = self.driver.find_element_by_id('body_div')
|
||||
|
|
@ -121,6 +129,9 @@ class TestDriver(object):
|
|||
self.print_console()
|
||||
raise e
|
||||
|
||||
def wait_for_invisible(self, selector=None, everywhere=False, timeout=20, xpath=None):
|
||||
self.wait_for(selector, everywhere, timeout, xpath, True)
|
||||
|
||||
def get_console(self):
|
||||
out = []
|
||||
for entry in self.driver.get_log('browser'):
|
||||
|
|
@ -193,8 +204,11 @@ class TestDriver(object):
|
|||
def execute_script(self, js):
|
||||
self.driver.execute_script(js)
|
||||
|
||||
def wait_for_ajax(self):
|
||||
def wait_for_ajax(self, freeze = False):
|
||||
self.wait_for('body[data-ajax-state="complete"]', True)
|
||||
if freeze:
|
||||
self.wait_for_invisible(".freeze-message-container")
|
||||
|
||||
|
||||
# def go_to_module(module_name, item=None):
|
||||
# global cur_route
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue