Best Python code snippet using robotframework-appiumlibrary_python
test_multiple_windows.py
Source:test_multiple_windows.py
...18from time import sleep19from webbrowser_app.tests import StartOpenRemotePageTestCaseBase20class TestMultipleWindows(StartOpenRemotePageTestCaseBase):21 def test_open_new_window(self):22 windows = self.app.get_windows()23 self.assertThat(len(windows), Equals(1))24 self.open_new_window()25 windows = self.app.get_windows()26 self.assertThat(len(windows), Equals(2))27 for window in windows:28 self.assertThat(window.incognito, Equals(False))29 def test_open_new_private_window(self):30 windows = self.app.get_windows()31 self.assertThat(len(windows), Equals(1))32 self.open_new_private_window()33 windows = self.app.get_windows()34 self.assertThat(len(windows), Equals(2))35 self.assertThat(len(self.app.get_windows(incognito=False)), Equals(1))36 self.assertThat(len(self.app.get_windows(incognito=True)), Equals(1))37 def test_open_new_window_progress_bar_hidden(self):38 # Regression test for pad.lv/163833739 url = self.base_url + "/test2"40 self.main_window.go_to_url(url)41 self.main_window.wait_until_page_loaded(url)42 self.assertThat(self.main_window.chrome.get_progress_bar().visible,43 Eventually(Equals(False)))44 # Open a new window45 self.open_new_window()46 windows = self.app.get_windows()47 self.assertThat(len(windows), Equals(2))48 # Check that progress bar is hidden49 for window in windows:50 self.assertThat(window.chrome.get_progress_bar().visible,51 Eventually(Equals(False)))52class TestMultipleWindowsDrag(StartOpenRemotePageTestCaseBase):53 def setUp(self):54 super(TestMultipleWindowsDrag, self).setUp()55 if not self.main_window.wide:56 self.skipTest("Only on wide form factors")57 def drag_tab(self, tab, x2, y2):58 x1, y1 = self.get_object_center(tab)59 self.pointing_device.move(x1, y1)60 self.pointing_device.press()61 # Drag tab downwards first to ensure we activate tab dragging62 for i in range(100):63 self.pointing_device.move(x1, y1 + i)64 # Move to destination and release65 # pause at each point so we can what is happening66 sleep(0.25)67 self.pointing_device.move(x2, y2)68 sleep(0.25)69 self.pointing_device.release()70 sleep(0.25)71 def get_object_center(self, obj):72 x1, y1, width, height = obj.globalRect73 x1 += width // 274 y1 += height // 275 return x1, y176 def get_tab_delegate(self, window, tabIndex):77 return window.chrome.get_tabs_bar().get_tab(tabIndex)78 def test_drag_tab_tabbar_nothing(self):79 '''test that dragging a tab out and in of tabbar is same'''80 window = self.app.get_windows()[0]81 # Drag tab down and then back into tab bar82 tab = self.get_tab_delegate(window, 0)83 x2, y2 = self.get_object_center(tab)84 self.drag_tab(tab, x2, y2)85 # Check we still have 1 window and 1 tab86 windows = self.app.get_windows()87 self.assertThat(len(windows), Equals(1))88 self.assertThat(lambda: len(windows[0].get_webviews()),89 Eventually(Equals(1)))90 def test_drag_tab_bottom_new_window(self):91 '''test with two tabs dragging one to the bottom opens a new window'''92 window = self.app.get_windows()[0]93 # Open a new tab and check we have two94 self.open_new_tab()95 self.assertThat(lambda: len(window.get_webviews()),96 Eventually(Equals(2)))97 # Drag new tab to bottom part of window98 tab = self.get_tab_delegate(window, 1)99 x2, y2 = self.get_object_center(window)100 self.drag_tab(tab, x2, y2)101 # Check that a new window has been opened102 windows = self.app.get_windows()103 self.assertThat(len(windows), Equals(2))104 self.assertThat(lambda: len(windows[0].get_webviews()),105 Eventually(Equals(1)))106 self.assertThat(lambda: len(windows[1].get_webviews()),107 Eventually(Equals(1)))108 def test_drag_tab_outside_new_window(self):109 '''test with two tabs dragging one to the bottom opens a new window'''110 window = self.app.get_windows()[0]111 # Open a new tab and check we have two112 self.open_new_tab()113 self.assertThat(lambda: len(window.get_webviews()),114 Eventually(Equals(2)))115 # Drag new tab outside of window116 tab = self.get_tab_delegate(window, 1)117 x2, y2, width, height = window.globalRect118 if x2 > 20:119 x2 -= 20120 else:121 x2 += width + 20122 self.drag_tab(tab, x2, y2)123 # Check that a new window has been opened124 windows = self.app.get_windows()125 self.assertThat(len(windows), Equals(2))126 self.assertThat(lambda: len(windows[0].get_webviews()),127 Eventually(Equals(1)))128 self.assertThat(lambda: len(windows[1].get_webviews()),129 Eventually(Equals(1)))130 def test_drag_tab_between_windows_move(self):131 '''test that dragging a tab from one window to another'''132 # Open a new tab and window133 self.open_new_tab()134 self.open_new_window()135 windows = self.app.get_windows()136 self.assertThat(len(windows), Equals(2))137 self.assertThat(lambda: len(windows[0].get_webviews()),138 Eventually(Equals(2)))139 self.assertThat(lambda: len(windows[1].get_webviews()),140 Eventually(Equals(1)))141 # Focus window 0142 self.switch_to_unfocused_window(windows[0])143 # Move tab into window 1144 tab = self.get_tab_delegate(windows[0], 1)145 x2, y2 = self.get_object_center(windows[1].chrome.get_tabs_bar())146 self.drag_tab(tab, x2, y2)147 # Check there are two windows and two tabs open in the second window148 windows = self.app.get_windows()149 self.assertThat(len(windows), Equals(2))150 self.assertThat(lambda: len(windows[0].get_webviews()),151 Eventually(Equals(1)))152 self.assertThat(lambda: len(windows[1].get_webviews()),153 Eventually(Equals(2)))154 def test_drag_tab_between_windows_move_and_close_window(self):155 '''test that dragging tab from one window to another closes original'''156 self.open_new_window()157 windows = self.app.get_windows()158 self.assertThat(len(windows), Equals(2))159 # Focus window 0160 self.switch_to_unfocused_window(windows[0])161 # Move tab into window 1162 tab = self.get_tab_delegate(windows[0], 0)163 x2, y2 = self.get_object_center(windows[1].chrome.get_tabs_bar())164 self.drag_tab(tab, x2, y2)165 # Check there are two tabs open in the single remaining window166 windows = self.app.get_windows()167 self.assertThat(len(windows), Equals(1))168 self.assertThat(lambda: len(windows[0].get_webviews()),169 Eventually(Equals(2)))170 def test_drag_public_tab_into_private_window(self):171 '''test that you cannot drag a public tab into private window'''172 # Open private window, check there are two windows173 self.open_new_private_window()174 windows = self.app.get_windows()175 self.assertThat(len(windows), Equals(2))176 public_window = self.app.get_windows(incognito=False)[0]177 private_window = self.app.get_windows(incognito=True)[0]178 # Focus public window179 self.switch_to_unfocused_window(public_window)180 # Move tab into private window181 tab = self.get_tab_delegate(public_window, 0)182 x2, y2 = self.get_object_center(private_window)183 self.drag_tab(tab, x2, y2)184 # Check there are two windows, one of public and one private185 windows = self.app.get_windows()186 self.assertThat(len(windows), Equals(2))187 self.assertThat(len(self.app.get_windows(incognito=False)), Equals(1))188 self.assertThat(len(self.app.get_windows(incognito=True)), Equals(1))189 def test_drag_private_tab_into_public_window(self):190 '''test that you cannot drag a private tab into public window'''191 # Open private window, check there are two windows192 self.open_new_private_window()193 windows = self.app.get_windows()194 self.assertThat(len(windows), Equals(2))195 public_window = self.app.get_windows(incognito=False)[0]196 private_window = self.app.get_windows(incognito=True)[0]197 # Move tab into public window198 tab = self.get_tab_delegate(private_window, 0)199 x2, y2 = self.get_object_center(public_window)200 self.drag_tab(tab, x2, y2)201 # Check there are two windows, one of public and one private202 windows = self.app.get_windows()203 self.assertThat(len(windows), Equals(2))204 self.assertThat(len(self.app.get_windows(incognito=False)), Equals(1))...
experiment.py
Source:experiment.py
...45 self.ECG = butter_bandpass_filter(self.ECG, 0.3, 70, 256)46 def compile_items(self, window_size, step_size):47 items = []48 segments = zip(49 # get_windows(torch.Tensor(self.piezo1), window_size, step_size),50 # get_windows(torch.Tensor(self.piezo2), window_size, step_size),51 get_windows(torch.Tensor(self.piezo3), window_size, step_size),52 get_windows(torch.Tensor(self.piezo4), window_size, step_size),53 get_windows(torch.Tensor(self.piezo5), window_size, step_size),54 get_windows(torch.Tensor(self.piezoB), window_size, step_size),55 get_windows(torch.Tensor(self.piezoA), window_size, step_size),56 get_windows(torch.Tensor(self.piezoEF), window_size, step_size),57 get_windows(torch.Tensor(self.piezoDC), window_size, step_size),58 get_windows(torch.Tensor(self.ECG), window_size, step_size),59 # get_windows(torch.Tensor(self.Thorax), window_size, step_size),60 # get_windows(torch.Tensor(self.Abdomen), window_size, step_size),61 # get_windows(torch.Tensor(self.NasalPressure), window_size, step_size),62 # get_windows(torch.Tensor(self.Plethysmogram), window_size, step_size),63 get_windows(torch.Tensor(self.labels), window_size, step_size),64 torch.Tensor(self.labels_)65 )66 # ecg, thorax, abdomen, \67 # nasal_pressure, plethysmogram,68 for piezo3, piezo4, piezo5, piezoB, \69 piezoA, piezoEF, piezoDC,ecg, \70 label, true_label in segments:71 # for ecg, thorax,abdomen, label, true_label in segments:72 item = {73 # 'piezo1': piezo1,74 # 'piezo2': piezo2,75 'piezo3': piezo3,76 'piezo4': piezo4,77 'piezo5': piezo5,...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!