浏览代码

adding tab switching to screen
This is needed to reproduce the object duplication bug in ui.scene

Rodja Trappe 2 年之前
父节点
当前提交
b4e60f00b4
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      tests/screen.py

+ 9 - 0
tests/screen.py

@@ -70,6 +70,15 @@ class Screen:
         if self.is_open:
             self.selenium.close()
 
+    def switch_to(self, tab_id: int) -> None:
+        window_count = len(self.selenium.window_handles)
+        if tab_id > window_count:
+            raise IndexError(f'Could not go to or create tab {tab_id}, there are only {window_count} tabs')
+        elif tab_id == window_count:
+            self.selenium.switch_to.new_window('tab')
+        else:
+            self.selenium.switch_to.window(self.selenium.window_handles[tab_id])
+
     def should_contain(self, text: str) -> None:
         assert self.selenium.title == text or self.find(text), f'could not find "{text}"'