How to use open_start_page method in SeleniumBase

Best Python code snippet using SeleniumBase

contact.py

Source:contact.py Github

copy

Full Screen

...6import random7class ContactHelper:8 def __init__(self, app):9 self.app = app10 def open_start_page(self):11 wd = self.app.wd12 if not len(wd.find_elements_by_name("//input[@value='Delete']")) > 0:13 wd.find_element_by_link_text("home").click()14 def open_contact_add(self):15 wd = self.app.wd16 if not len(wd.find_elements_by_link_text("Edit / add address book entry")) > 0:17 wd.find_element_by_link_text("add new").click()18 def change_field_value_con(self, field_data, text):19 wd = self.app.wd20 if text is not None:21 wd.find_element_by_name(field_data).click()22 wd.find_element_by_name(field_data).clear()23 wd.find_element_by_name(field_data).send_keys(text)24 def change_field_select_con(self, field_select, text):25 wd = self.app.wd26 if text is not None:27 wd.find_element_by_name(field_select).click()28 Select(wd.find_element_by_name(field_select)).select_by_visible_text(text)29 def fill_contact_form(self, contact):30 wd = self.app.wd31 self.change_field_value_con("firstname", contact.firstname)32 self.change_field_value_con("middlename", contact.middlename)33 self.change_field_value_con("lastname", contact.lastname)34 self.change_field_value_con("nickname", contact.nickname)35 self.change_field_value_con("title", contact.title)36 self.change_field_value_con("company", contact.company)37 self.change_field_value_con("address", contact.address)38 self.change_field_value_con("home", contact.homephone) # contact.home39 self.change_field_value_con("mobile", contact.mobile)40 self.change_field_value_con("work", contact.workphone) # contact.work41 self.change_field_value_con("phone2", contact.faxphone) # contact.fax42 self.change_field_value_con("email", contact.email)43 self.change_field_value_con("email2", contact.email2)44 self.change_field_value_con("email3", contact.email3)45 self.change_field_value_con("email3", contact.homepage)46 self.change_field_select_con("bday", contact.bday)47 self.change_field_select_con("bmonth", contact.bmonth)48 self.change_field_value_con("byear", contact.byear)49 self.change_field_select_con("aday", contact.aday)50 self.change_field_select_con("amonth", contact.amonth)51 self.change_field_value_con("ayear", contact.ayear)52 self.change_field_value_con("address2", contact.address2)53 self.change_field_value_con("phone2", contact.phone2)54 self.change_field_value_con("notes", contact.notes)55 def createcontact(self, contact):56 wd = self.app.wd57 self.open_start_page()58 self.open_contact_add()59 self.fill_contact_form(contact)60 wd.find_element_by_xpath("//div[@id='content']/form/input[21]").click()61 self.open_start_page()62 self.contact_cache = None63 def selected_first_contact(self):64 wd = self.app.wd65 wd.find_element_by_name("selected[]").click()66 def select_contact_by_index(self, index):67 wd = self.app.wd68 wd.find_elements_by_name("selected[]")[index].click()69 def select_contact_by_id(self, id):70 wd = self.app.wd71 wd.find_element_by_css_selector("input[value='%s']" % id).click()72 def delete_first_contact(self):73 self.delete_contact_by_index(0)74 def delete_contact_by_index(self, index):75 wd = self.app.wd76 self.open_start_page()77 self.select_contact_by_index(index)78 # submit deletion79 wd.find_element_by_xpath("//input[@value='Delete']").click()80 wd.switch_to_alert().accept()81 self.open_start_page()82 self.contact_cache = None83 def delete_contact_by_id(self, id):84 wd = self.app.wd85 self.open_start_page()86 self.select_contact_by_id(id)87 wd.find_element_by_xpath("//input[@value='Delete']").click()88 wd.switch_to.alert.accept()89 wd.find_element_by_css_selector("div.msgbox")90 self.open_start_page()91 self.contact_cache = None92 def modify_first_contact(self):93 self.modify_contact_by_index(0)94 def modify_contact_by_index(self, index, new_contact_data):95 wd = self.app.wd96 self.open_start_page()97 wd.find_elements_by_xpath('//img[@title="Edit"]')[index].click()98 self.fill_contact_form(new_contact_data)99 wd.find_element_by_name("update").click()100 self.open_start_page()101 self.contact_cache = None102 def modify_contact_by_id(self, id, new_contact_data):103 wd = self.app.wd104 self.open_start_page()105 self.random_modify_id(id)106 self.fill_contact_form(new_contact_data)107 wd.find_element_by_name("update").click()108 wd.find_element_by_css_selector("div.msgbox")109 self.open_start_page()110 self.contact_cache = None111 def get_group_value(self):112 wd = self.app.wd113 self.open_start_page()114 wd.find_element_by_link_text("groups").click()115 group_cache = []116 for element in wd.find_elements_by_css_selector("span.group"):117 id = element.find_element_by_name("selected[]").get_attribute("value")118 group_cache.append(id)119 return list(group_cache)120 def random_modify_id(self, id):121 wd = self.app.wd122 wd.find_element_by_css_selector("[href='edit.php?id=%s']" % id).click()123 def countcon(self):124 wd = self.app.wd125 self.open_start_page()126 return len(wd.find_elements_by_name("selected[]"))127 contact_cache = None128 def open_contact_to_edit_by_index(self, index):129 wd = self.app.wd130 self.open_start_page()131 row = wd.find_elements_by_name("entry")[index]132 cell = row.find_elements_by_tag_name("td")[7]133 cell.find_element_by_tag_name("a").click()134 def open_contact_view_by_index(self, index):135 wd = self.app.wd136 self.open_start_page()137 row = wd.find_elements_by_name("entry")[index]138 cell = row.find_elements_by_tag_name("td")[6]139 cell.find_element_by_tag_name("a").click()140 def get_contact_with_group(self, group):141 if self.contact_cache is None:142 wd = self.app.wd143 self.app.open_home_page()144 wd.find_element_by_name("group").click()145 Select(wd.find_element_by_name("group")).select_by_visible_text("%s" % group)146 self.contact_cache = []147 for element in wd.find_elements_by_css_selector("tr")[1:]:148 cells = element.find_elements_by_tag_name("td")149 id = element.find_element_by_name("selected[]").get_attribute("value")150 firstname = cells[2].text151 lastname = cells[1].text152 address = cells[3].text153 all_email = cells[4].text154 all_phones = cells[5].text155 self.contact_cache.append(Contact(firstname=firstname, lastname=lastname, id=id, address=address,156 all_phones_from_home_page=all_phones,157 all_emails_from_home_page=all_email))158 return list(self.contact_cache)159 def get_contact_list(self):160 if self.contact_cache is None:161 wd = self.app.wd162 self.open_start_page()163 self.contact_cache = []164 for element in wd.find_elements_by_name("entry"):165 cells = element.find_elements_by_xpath("td")166 lastname = element.find_element_by_xpath("td[2]").text167 firstname = element.find_element_by_xpath("td[3]").text168 address = element.find_element_by_xpath("td[4]").text169 id = element.find_element_by_name("selected[]").get_attribute("value")170 all_phones = cells[5].text171 all_emails = cells[4].text172 self.contact_cache.append(Contact(lastname=lastname, firstname=firstname, id=id, address=address,173 all_phones_from_home_page=all_phones,174 all_emails_from_home_page=all_emails))175 return list(self.contact_cache)176 def get_contact_info_from_edit_page(self, index):177 wd = self.app.wd178 self.open_contact_to_edit_by_index(index)179 firstname = wd.find_element_by_name("firstname").get_attribute("value")180 lastname = wd.find_element_by_name("lastname").get_attribute("value")181 id = wd.find_element_by_name("id").get_attribute("value")182 homephone = wd.find_element_by_name("home").get_attribute("value")183 workphone = wd.find_element_by_name("work").get_attribute("value")184 mobile = wd.find_element_by_name("mobile").get_attribute("value")185 faxphone = wd.find_element_by_name("phone2").get_attribute("value")186 address = wd.find_element_by_name("address").get_attribute("value")187 email = wd.find_element_by_name("email").get_attribute("value")188 email2 = wd.find_element_by_name("email2").get_attribute("value")189 email3 = wd.find_element_by_name("email3").get_attribute("value")190 return Contact(firstname=firstname, lastname=lastname, id=id, homephone=homephone, workphone=workphone,191 mobile=mobile, phone2=faxphone, address=address, email=email, email2=email2, email3=email3)192 def get_contact_from_view_page(self, index):193 wd = self.app.wd194 self.open_contact_view_by_index(index)195 text = wd.find_element_by_id("content").text196 homephone = re.search("H: (.*)", text).group(1)197 workphone = re.search("W: (.*)", text).group(1)198 mobile = re.search("M: (.*)", text).group(1)199 faxphone = re.search("P: (.*)", text).group(1)200 return Contact(homephone=homephone, workphone=workphone,201 mobile=mobile, phone2=faxphone)202 def open_add_new_contact_page(self):203 wd = self.app.wd204 if not (wd.current_url.endswith("/edit.php") and len(wd.find_elements_by_name("submit")) > 0):205 wd.find_element_by_link_text("add new").click()206 def add_contact_to_group(self, contact, group):207 wd = self.app.wd208 self.open_start_page()209 self.open_add_new_contact_page()210 self.fill_contact_form(contact)211 wd.find_element_by_name("new_group").click()212 Select(wd.find_element_by_name("new_group")).select_by_visible_text("%s" % group)213 wd.find_element_by_xpath("//div[@id='content']/form/input[21]").click()214 self.open_start_page()215 self.contact_cache = None216 def remove_contact_from_group(self, id, group):217 wd = self.app.wd218 self.open_start_page()219 wd.find_element_by_name("group").click()220 Select(wd.find_element_by_name("group")).select_by_visible_text("%s" % group)221 wd.find_element_by_css_selector("input[value='%s']" % id).click()222 wd.find_element_by_xpath("//input[@name='remove']").click()...

Full Screen

Full Screen

test_start_page.py

Source:test_start_page.py Github

copy

Full Screen

...12 # driver.implicitly_wait(1)13 yield driver14 driver.close()15 @pytest.fixture(scope="function")16 def open_start_page(self, driver):17 driver.get(BaseConst.URL)18 return StartPage(driver)19 @pytest.fixture(scope="function")20 def reg_user_and_sign_out(self, open_start_page):21 user_name = f"User{self.random_num()}"22 user_email = f"BOX{self.random_num()}@testmail.com"23 user_password = f"MYTESTPASS{self.random_num()}"24 # register new user25 main_page = open_start_page.reg_new_user(user_name, user_email, user_password)26 main_page.log_out()27 return user_name, user_password28 def random_num(self):29 return str(random.choice(range(11111, 99999)))30 def test_new_reg(self, open_start_page):...

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 SeleniumBase 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