How to use get_window_title method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

winapi.py

Source:winapi.py Github

copy

Full Screen

...2526 DEFAULT = CASE_INSENSITIVE | EXACT2728 29def get_window_title(hwnd):30 # TODO GetWindowTextLength31 buf = ctypes.create_unicode_buffer(255)32 # Can't really raise on zero because the window text might have no length33 user32.GetWindowTextW(hwnd, buf, 254)34 return buf.value353637def get_window_application(hwnd):38 hinstance = GetWindowLong(hwnd, GWLP_HINSTANCE)39 if 0 == hinstance:40 raise ctypes.WinError()41 return hinstance424344def get_memes(hproc):45 buf = ctypes.create_unicode_buffer(1024)46 if 0 == psapi.GetModuleFileNameExW(..., hproc, buf, 1023):47 raise ctypes.WinError()48 return buf.value495051class WindowDiscovery(object):52 """ Calls `sync` which is a `callable(new_hwnds, removed_hwnds)`53 """5455 def __init__(self, sync, show_untitled=False):56 self.show_untitled = show_untitled57 self._discovered = set()58 self.sync = sync5960 @classmethod61 def fresh(cls, *args, **kwargs):62 inst = cls(*args, **kwargs)63 inst.refresh()64 return inst6566 @classmethod67 def get_current_hwnds(cls, *args, **kwargs):68 """ Returns a set of hwnds for current windows.69 """70 results = set()71 update = lambda new, gone: (results.update(new), results.difference_update(gone))72 cls.fresh(update, *args, **kwargs)73 return results7475 @property76 def discovered(self):77 return self._discovered7879 def refresh(self):80 seen = set()8182 @ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM)83 def cb(hwnd, _):84 if user32.IsWindowVisible(hwnd) and (self.show_untitled or get_window_title(hwnd).strip()):85 seen.add(hwnd)86 return True # I think this means keep enumerating8788 if 0 == user32.EnumWindows(cb, 0):89 raise ctypes.WinError()9091 new = seen - self._discovered92 gone = self._discovered - seen93 if new or gone:94 self._discovered.difference_update(gone)95 self._discovered.update(new)96 self.sync(new, gone)979899def test_window_match(hwnd, pat):100 """ Return (window title, whether it matches the pattern)101 """102 title = get_window_title(hwnd)103 return title, re.search(pat, title, re.I) is not None104105106def multi_search(hwnds, pat):107 '''108 Generator yielding hwnd, window title pairs for all windows which match109 `pat` as a case insensitive regex.110 '''111 for hwnd in hwnds:112 title = get_window_title(hwnd)113 if re.search(pat, title, re.I) is not None:114 yield hwnd, title115116117def search(hwnds, pat):118 '''119 Like multi_search but will throw an exception if it receives more or120 fewer than one result. And only returns the hwnd.121 '''122 r = list(multi_search(hwnds, pat))123 if len(r) > 1:124 raise ValueError('Multiple matches found: %s' % r)125 elif not r:126 raise ValueError('No window with matching title found')127 return r[0]128129130def query(hwnds, match, flags=Q.DEFAULT):131 if flags != Q.DEFAULT:132 raise NotImplementedError133 for hwnd in hwnds:134 if get_window_title(hwnd) == match:135 yield hwnd136137138class NoResults(ValueError):139 pass140141142class TooManyResults(ValueError):143 pass144145146def query_one(*args, **kwargs):147 res = list(query(*args, **kwargs))148 if len(res) == 1: ...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

...29def save_plots(path: Path, figs: list):30 plotter.ioff()31 mkdir = lambda x: get_dir(x, True)32 for fig in figs:33 fig.savefig(mkdir(path / 'pdf') / f'{fig.canvas.get_window_title()}.pdf', dpi=138, bbox_inches='tight')34 fig.savefig(mkdir(path / 'svg') / f'{fig.canvas.get_window_title()}.svg', dpi=138, bbox_inches='tight')35 fig.savefig(mkdir(path / 'png') / f'{fig.canvas.get_window_title()}.png', dpi=138, bbox_inches='tight')36 print('Saved {}/<format>/{}.<format>'.format(37 str(path).replace('\\', '/'),38 fig.canvas.get_window_title()39 ))40 plotter.close('all')41def get_data(f: Path, pattern:str, uniqueness=3, parts=['%s','%s','%s']):42 43 return (44 get_simple_fname(f.name, pattern, uniqueness=uniqueness, parts=parts), 45 DataFrame.from_dict(read_json(f))46 )47def collect_data(48 paths: Iterable, fpattern:str,49 key_sort=lambda x: orderedby(x.name, FNAME_PATTERN),50 recursively=False, ds_merge_level=3, 51 data_getter=get_data):52 sortbykey = lambda x: x[0]...

Full Screen

Full Screen

selenium_agent_ex03_window_handling.py

Source:selenium_agent_ex03_window_handling.py Github

copy

Full Screen

...12win_handler.set_window_size(200,400)13time.sleep(5)14win_handler.maximize_window()15time.sleep(5)16print(win_handler.get_window_title())17automator.execute_javascript("window.open('google.com')")18print(win_handler.get_all_window_handles())19print(win_handler.get_window_title())20time.sleep(5)21win_handler.switch_to_new_window()22print(win_handler.get_window_title())23win_handler.close_current_window()24time.sleep(5)25automator.execute_javascript("window.open('google.com')")26print(win_handler.get_all_window_handles())27time.sleep(5)28automator.execute_javascript("window.open('yahoo.com')")29print(win_handler.get_all_window_handles())30time.sleep(5)31automator.execute_javascript("window.open('bing.com')")32print(win_handler.get_all_window_handles())33time.sleep(5)34win_handler.close_all_child_windows()35print(win_handler.get_window_title())36time.sleep(5)37win_handler.close_current_window()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-appiumlibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful