def setUp(self): self.xp = Xpresser() all_image_paths = [self.GENERIC_IMAGES, self.EXTRA_IMAGES, self.IMAGES] for image_path in all_image_paths: if image_path is not None: self.xp.load_images(image_path) Notify.init('Xpresser') self.start_gui()
class XpresserUnittest(unittest.TestCase): GENERIC_IMAGES = os.path.join(GUI_TEST_ROOT_PATH, 'main_window', 'images') EXTRA_IMAGES = None IMAGES = None """ @classmethod def setUpClass(cls): cls.gnome = Gnome() cls.gnome.start_sync() set_display_to_self() @classmethod def tearDownClass(cls): cls.gnome.stop() restore_original_display() """ def setUp(self): self.xp = Xpresser() all_image_paths = [self.GENERIC_IMAGES, self.EXTRA_IMAGES, self.IMAGES] for image_path in all_image_paths: if image_path is not None: self.xp.load_images(image_path) Notify.init('Xpresser') self.start_gui() def start_gui(self): self.gui_process = subprocess.Popen(["python", "w3af_gui", "-n"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) self.gui_process_pid = self.gui_process.pid # Move the mouse pointer somewhere where it shouldn't break any image # matching (screenshot with pointer vs. stored image) self.xp.hover(600, 600) # This is an easy way to wait for the GUI to be available before # starting any specific tests. self.xp.find('insert_target_url_here', timeout=5) self.sleep(0.5) def process_is_alive(self): return self.gui_process.poll() is None def stop_gui(self): if self.process_is_alive(): self.not_find('bug_detected', timeout=1) try: self.xp.find('throbber_stopped') self.type(['<Alt>', '<F4>'], False) self.click('yes') except ImageNotFound: if self.gui_process_pid == self.gui_process.pid: self.gui_process.kill() def tearDown(self): self.stop_gui() @debug_notify def click(self, image): self.xp.click(image) @debug_notify def find(self, image, timeout=5): self.xp.find(image, timeout=timeout) @debug_notify def not_find(self, image, timeout=3): try: self.xp.find(image, timeout=timeout) except: return else: raise ImageFound('%s was found and should NOT be there' % image) @debug_notify def hover(self, *args): self.xp.hover(*args) @debug_notify def double_click(self, image): self.xp.double_click(image) @debug_notify def right_click(self, image): self.xp.right_click(image) @debug_notify def type(self, chars, hold): self.xp.type(chars, hold) def sleep(self, secs): time.sleep(secs)
class XpresserUnittest(unittest.TestCase): GENERIC_IMAGES = os.path.join('core', 'ui', 'tests', 'gui', 'main_window', 'images') EXTRA_IMAGES = None IMAGES = None ''' @classmethod def setUpClass(cls): cls.gnome = Gnome() cls.gnome.start_sync() set_display_to_self() @classmethod def tearDownClass(cls): cls.gnome.stop() restore_original_display() ''' def setUp(self): self.xp = Xpresser() all_image_paths = [self.GENERIC_IMAGES, self.EXTRA_IMAGES, self.IMAGES] for image_path in all_image_paths: if image_path is not None: self.xp.load_images(image_path) Notify.init('Xpresser') self.start_gui() def start_gui(self): self.gui_process = subprocess.Popen(["python", "w3af_gui", "-n"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) self.gui_process_pid = self.gui_process.pid # Move the mouse pointer somewhere where it shouldn't break any image # matching (screenshot with pointer vs. stored image) self.xp.hover(600, 600) # This is an easy way to wait for the GUI to be available before # starting any specific tests. self.xp.find('insert_target_url_here', timeout=5) self.sleep(0.5) def process_is_alive(self): return self.gui_process.poll() is None def stop_gui(self): if self.process_is_alive(): self.not_find('bug_detected', timeout=1) try: self.xp.find('throbber_stopped') self.type(['<Alt>','<F4>'], False) self.click('yes') except ImageNotFound: if self.gui_process_pid == self.gui_process.pid: self.gui_process.kill() def tearDown(self): self.stop_gui() @debug_notify def click(self, image): self.xp.click(image) @debug_notify def find(self, image, timeout=3): self.xp.find(image, timeout=timeout) @debug_notify def not_find(self, image, timeout=2): try: self.xp.find(image, timeout=timeout) except: return else: raise ImageFound('%s was found and should NOT be there' % image) @debug_notify def hover(self, *args): self.xp.hover(*args) @debug_notify def double_click(self, image): self.xp.double_click(image) @debug_notify def right_click(self, image): self.xp.right_click(image) @debug_notify def type(self, chars, hold): self.xp.type(chars, hold) def sleep(self, secs): time.sleep(secs)
def main(): xp = Xpresser() xp.load_images('.') xp.click('12_1') time.sleep(1) xp.click('05_file') xp.click('06_export') xp.type('1.svg') xp.type(['<Enter>']) xp.click('05_file') xp.click('11_close')
def main(): xp = Xpresser() xp.load_images('/Images') time.sleep(3) xp.click('name-actor') xp.type('michael j fox') xp.click(1321,100) time.sleep(3) xp.click(703,135) xp.click(703,135) xp.click(1323,135)
from django.test import TestCase from xpresser import Xpresser xp = Xpresser() xp.load_images('darsplus/tests/gui') import time class TestGUI(TestCase): def testCreateUser(self): print("Firefox found" +str(xp.find("firefox"))) xp.click("firefox") time.sleep(5) xp.click("urlBar") xp.type("http://127.0.0.1:8000/home/") xp.click("refresh") xp.click("username") xp.type("guitest") xp.click("password") xp.type("test") xp.click("createUser") time.sleep(1) error = False xp.find("registration") self.assertFalse()