Best Python code snippet using lettuce_webdriver_python
base.py
Source: base.py
...21 self.accept_next_alert = True22 def _create_user(self, user, user_data):23 self.driver.get(var.home_page)24 self.driver.find_element_by_css_selector('a.btn.sign-up').click()25 self.select_single_item('id_username', user_data['id_username'])26 self.set_text_id('id_profile_colour', user_data['id_profile_colour'])27 self.select_single_item('id_security_question_1', user_data['id_security_question_1'])28 self.set_text_id('id_security_answer_1', user_data['id_security_answer_1'])29 self.select_single_item('id_security_question_2', user_data['id_security_question_2'])30 self.set_text_id('id_security_answer_2', user_data['id_security_answer_2'])31 self.set_text_id('id_password1', user_data['id_password1'])32 self.set_text_id('id_password2', user_data['id_password2'])33 self.driver.find_element_by_css_selector('div.form-footer > input.btn-submit').click()34 # Login with correct data35 def login(self, user):36 self.driver.get(var.home_page)37 self.set_text_id('id_user-username', user.username)38 self.set_text_id('id_user-password', user.password)39 self.driver.find_element_by_css_selector('input.btn-submit').click()40 # Check if login was succesful by getting username41 self.find_text_element('Log out of JoopeA')42 def admin_login(self, username, password):43 self.driver.get(var.admin_page)44 self.set_text('id_username', username)45 self.set_text('id_password', password)46 self.driver.find_element_by_css_selector('input.grp-button.grp-default').click()47 def set_text_id(self, field_id, text):48 self.driver.find_element_by_id(field_id).clear()49 self.driver.find_element_by_id(field_id).send_keys(text)50 def set_text_name(self, field_name, text):51 self.driver.find_element_by_name(field_name).clear()52 self.driver.find_element_by_name(field_name).send_keys(text)53 def set_text_selector(self, selector, text):54 self.driver.find_element_by_css_selector(selector).clear()55 self.driver.find_element_by_css_selector(selector).send_keys(text)56 def find_css_element(self, selector_id):57 try:58 self.assertTrue(self.is_element_present(By.CSS_SELECTOR, selector_id))59 except AssertionError as e:60 self.verificationErrors.append(str(e))61 def find_text_element(self, text):62 try:63 self.assertTrue(self.is_element_present(By.LINK_TEXT, text))64 except AssertionError as e:65 self.verificationErrors.append(str(e))66 def assert_text_with_xpath(self, value, find_xpath):67 try:68 self.assertEqual(value, self.driver.find_element_by_xpath(find_xpath).text)69 except AssertionError as e:70 self.verificationErrors.append(str(e))71 def assert_text_with_selector(self, text, selector_id):72 try:73 self.assertEqual(text, self.driver.find_element_by_css_selector(selector_id).text)74 except AssertionError as e:75 self.verificationErrors.append(str(e))76 def is_element_present(self, how, what):77 try:78 self.driver.find_element(by=how, value=what)79 except NoSuchElementException:80 return False81 return True82 def select_single_item(self, field_id, value):83 Select(self.driver.find_element_by_id(field_id)).select_by_value(value)84 def select_multi_items(self, field_id, *values):85 options = Select(self.driver.find_element_by_id(field_id))86 for value in values:87 options.select_by_value(value)88 def select_all_items(self, field_id):89 options = Select(self.driver.find_element_by_id(field_id)).options90 for option in options:91 if not option.is_selected():92 option.click()93 def is_alert_present(self):94 try:95 self.driver.switch_to_alert()96 except NoAlertPresentException:...
test_users.py
Source: test_users.py
...20 # def test_create_and_delete_account(self):21 # # Create account22 # self.driver.get(var.home_page)23 # self.driver.find_element_by_css_selector('a.btn.sign-up').click()24 # self.select_single_item('id_username', '1')25 # self.set_text_id('id_profile_colour', '#00ffff')26 # self.select_single_item('id_security_question_1', '1')27 # self.set_text_id('id_security_answer_1', 'Answer 1')28 # self.select_single_item('id_security_question_2', '2')29 # self.set_text_id('id_security_answer_2', 'Answer 2')30 # self.set_text_id('id_password1', 'asdasd')31 # self.set_text_id('id_password2', 'asdasd')32 # self.driver.find_element_by_css_selector('div.form-footer > input.btn-submit').click()33 # time.sleep(3)34 # # Delete account35 # self.driver.find_element_by_css_selector("a.mm-next.mm-fullsubopen").click()36 # self.driver.find_element_by_link_text('My settings').click()37 # self.driver.find_element_by_link_text('Delete Profile').click()38 # self.set_text_id('id_current_password', 'asdasd')39 # self.driver.find_element_by_css_selector('input.btn-submit').click()40 # def test_follow_unfollow_user(self):41 # self.login(var.u1.username, var.u1.password)42 # self.driver.get(var.testing2_user_page) # Go to u2 profile...
test_demo.py
Source: test_demo.py
...26 def test_add_to_cart_red_font(self, main_page, parametrized_index):27 res = main_page.font_color(parametrized_index, 'add_to_cart')28 assert res == 'red'29 @pytest.fixture(scope='class', params=_ids.keys(), ids=_ids.values())30 def select_single_item(self, main_page, request) -> int:31 """Selects a parametrized item by index and returns the index value"""32 main_page.add_or_remove_item(index_=request.param)33 yield request.param34 if main_page.item_text(index_=request.param) == 'REMOVE':35 main_page.add_or_remove_item(index_=request.param)36 def test_add_item_to_the_cart(self, main_page, select_single_item):37 item_selected = main_page.item_text(index_=select_single_item)38 assert item_selected == 'REMOVE'39 def test_black_color_remove_btn(self, main_page, select_single_item):40 item_selected = main_page.font_color(index_=select_single_item, object_element='add_to_cart')41 assert item_selected == 'black'42 def test_cart_label_is_one(self, main_page, select_single_item):43 assert main_page.cart_icon_content() == '1'44 @pytest.fixture(scope='class')...
Check out the latest blogs from LambdaTest on this topic:
API (Application Programming Interface) is a set of definitions and protocols for building and integrating applications. It’s occasionally referred to as a contract between an information provider and an information user establishing the content required from the consumer and the content needed by the producer.
There is just one area where each member of the software testing community has a distinct point of view! Metrics! This contentious issue sparks intense disputes, and most conversations finish with no definitive conclusion. It covers a wide range of topics: How can testing efforts be measured? What is the most effective technique to assess effectiveness? Which of the many components should be quantified? How can we measure the quality of our testing performance, among other things?
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
Many theoretical descriptions explain the role of the Scrum Master as a vital member of the Scrum team. However, these descriptions do not provide an honest answer to the fundamental question: “What are the day-to-day activities of a Scrum Master?”
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!!