Best Python code snippet using SeleniumBase
asserts.py
Source:asserts.py
...275 self.driver, messenger_post, self.message_duration276 )277 except Exception:278 pass279 def assert_attribute_not_present(280 self, selector, attribute, value=None, by=By.CSS_SELECTOR, timeout=None281 ):282 """Similar to wait_for_attribute_not_present()283 Raises an exception if the attribute is still present after timeout.284 Returns True if successful. Default timeout = SMALL_TIMEOUT."""285 self.__check_scope__()286 timeout = self.get_timeout(timeout, constants.SMALL_TIMEOUT)287 return self.wait_for_attribute_not_present(288 selector, attribute, value=value, by=by, timeout=timeout289 )290 def assert_element(self, selector, by=By.CSS_SELECTOR, timeout=None):291 """Similar to wait_for_element_visible(), but returns nothing.292 As above, will raise an exception if nothing can be found.293 Returns True if successful. Default timeout = SMALL_TIMEOUT."""...
tests-todos.py
Source:tests-todos.py
...68 todo = 'a sample todo'69 Todos.addTodo(self, todo)70 # Check that Todo is Active by Default71 todoEl = f'//li[.="{todo}"]'72 self.assert_attribute_not_present(todoEl,'class', 'completed')73 # Mark Todo as Completed74 Todos.markAsCompletedOrActive(self, todo)75 # Check that Todo is Marked as Completed76 self.assert_attribute(todoEl,'class', 'completed')77 # Visual Check78 if self.data is not None and 'V' in self.data:79 self.check_window(name="test_can_mark_a_todo_as_completed", level=1)80 # Mark Todo as Active81 Todos.markAsCompletedOrActive(self, todo)82 # Check that Todo is Marked as Active83 self.assert_attribute_not_present(todoEl,'class', 'completed')84 # Visual Check85 if self.data is not None and 'V' in self.data:86 self.check_window(name="test_can_mark_a_todo_as_active", level=1)87 def test_can_mark_all_todos_as_completed_or_active(self):88 # Go to ToDoMVC React Page89 Todos.load(self)90 # Add Multiple Todos91 todos = [ 'todo #1', 'todo #2', 'todo #3' ]92 for todo in todos:93 Todos.addTodo(self, todo)94 # Check that All Todos are Active by Default95 for todo in todos:96 todoEl = f'//li[.="{todo}"]'97 self.assert_attribute_not_present(todoEl,'class', 'completed')98 # Mark All Todos as Completed99 Todos.markAllAsCompletedOrActive(self)100 # Check that All Todos are Marked as Completed101 for todo in todos:102 todoEl = f'//li[.="{todo}"]'103 self.assert_attribute(todoEl,'class', 'completed')104 # Visual Check105 if self.data is not None and 'V' in self.data:106 self.check_window(name="test_can_mark_all_todos_as_completed", level=1)107 # Mark All Todos as Active108 Todos.markAllAsCompletedOrActive(self)109 # Check that All Todos are Marked as Active110 for todo in todos:111 todoEl = f'//li[.="{todo}"]'112 self.assert_attribute_not_present(todoEl,'class', 'completed')113 # Visual Check114 if self.data is not None and 'V' in self.data:115 self.check_window(name="test_can_mark_all_todos_as_active", level=1)116 def test_todo_input_has_a_placeholder_value_of_what_needs_to_be_done(self):117 # Go to ToDoMVC React Page118 Todos.load(self)119 # Check Todo Input Placeholder Text120 input = Todos.inputNewTodo121 self.wait_for_element_visible(input)122 self.assert_attribute(input,'placeholder', 'What needs to be done?')123 # Visual Check124 if self.data is not None and 'V' in self.data:125 self.check_window(name="test_todo_input_has_a_placeholder_value_of_what_needs_to_be_done", level=1)126 def test_can_view_completed_or_active_todos(self):...
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!!