def test_modify_contact(app, db, check_ui): app.navigation.open_home_page() if len(db.get_contact_list()) == 0: app.contact.create( Contacts(firstname="wer", middlename="wer", lastname="wer", nickname="wer", title="wer", company="wer", address="werwerwe", home="1234", mobile="1234", email="gfgfg", bday="2", bmonth="March", byear="1989", address2="fdf", phone2="4567", notes="vcvcvcvcv")) old_contacts = db.get_contact_list() any_contact = random.choice(old_contacts) contact = Contacts(firstname="test", lastname="test") contact.id = any_contact.id app.contact.modify_contact_by_id(any_contact.id, contact) assert len(old_contacts) == app.contact.count() new_contact = db.get_contact_list() old_contacts.append(contact) old_contacts.remove(any_contact) assert sorted(old_contacts, key=Contacts.id_or_max) == sorted(new_contact, key=Contacts.id_or_max) if check_ui: assert sorted(new_contact, key=Contacts.id_or_max) == sorted( app.contact.get_contact_list(), key=Contacts.id_or_max)
def test_Contact3(app): old_cont = app.contact.get_cont_list() added = Contacts("Oполк", "Владимирович", "Рeк", "Ок1", "Князь киевский", "Киевская Русь", "Киев кремль", "12358", "(123) 456-78-90", "Князь Тартурский", "(123) 456-78-90", "32854-9(63)", "(123) 456-78-90", "[email protected]", "*****@*****.**", "", "https://ru.wikipedia.org/wiki", "", "335689", "any") app.contact.add(added) new_cont = app.contact.get_cont_list() assert len(old_cont) + 1 == app.contact.count() old_cont.append(added) app.contact.add(Contacts()) #добавление пустого контакта assert sorted(old_cont, key=Contacts.id_or_max) == sorted(new_cont, key=Contacts.id_or_max)
def test_edit_some_contact(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contacts.create((Contacts(first_name="test", middle_name="test2", last_name="test3", nickname="test4", title="test5", company="test_company", address="trtrtrt", home="64645", mobile="75675", work="8787", fax="55657", email="*****@*****.**", email_2="hgjgj2TR.UY", email_3="*****@*****.**", homepage="rtete.com", b_year="1993", address_2="ytyt", phone2="phone2", notes="hghg"))) old_contacts = db.get_contact_list() index = randrange(len(old_contacts)) contact = old_contacts[index] changed_contact = Contacts(first_name="change_first_name", middle_name="change.middle_name", last_name="change.last_name", nickname="change.nickname", title="change.title", company="test_company", address="changeaddress", home="changehome", mobile="changemobile", work="changework", fax="changefax", email="change.email", email_2="change.email_2", email_3="*****@*****.**", homepage="change.homepage", b_year="1993", address_2="change.address_2", phone2="changephone2", notes="changenotes", id=contact.id) app.contacts.edit_contact_by_id(changed_contact.id, changed_contact) assert len(old_contacts) == app.contacts.count() new_contacts = db.get_contact_list() old_contacts[index] = changed_contact assert sorted(old_contacts, key=Contacts.id_or_max) == sorted(new_contacts, key=Contacts.id_or_max) if check_ui: assert sorted(new_contacts, key=Contacts.id_or_max) == sorted( app.contacts.get_contact_list(), key=Contacts.id_or_max)
def test_add_contact_to_group(app, db): app.navigation.open_home_page() if len(db.get_contact_list()) == 0: app.contact.create(Contacts(firstname="wer")) if len(db.get_group_list()) == 0: app.group.create(Group(name="created")) if len(db.get_contacts_not_in_any_group()) == 0: app.contact.create(Contacts(firstname="Contact_for_group")) if len(db.get_group_without_contacts()) == 0: app.group.create(Group(name="Empty_group")) contact = random.choice(db.get_contacts_not_in_any_group()) group = random.choice(db.get_group_without_contacts()) app.contact.add_contact_to_group_by_id(contact.id, group.id) assert contact in db.get_contact_in_group(group)
def test_edit_cont_name(app): if app.contact.count() == 0: app.contact.add(Contacts(lastN = "for del")) old_cont = app.contact.get_cont_list() index = randrange(len(old_cont)) changed = Contacts(name='456', lastN='123', address='789') changed.id = old_cont[index].id # added = Contacts("Святополк", "Владимирович", "Рюрик", "Окаянный", "Князь киевский", "Киевская Русь", "Киев кремль", # "Кремль", "(123) 456-78-90", "Князь Тартурский", "(123) 456-78-90", "[email protected]", "*****@*****.**", # "", "https://ru.wikipedia.org/wiki/Cвятополк Владимирович Окаянный", "", "", "был под арестом") app.contact.edit_contact_by_index(index, changed) new_cont = app.contact.get_cont_list() assert len(old_cont) == app.contact.count() old_cont[index] = changed assert sorted(old_cont, key=Contacts.id_or_max) == sorted(new_cont, key=Contacts.id_or_max)
def get_contact_info_from_edit_page(self, index): wd = self.app.wd self.open_contact_to_edit_by_index(index) first_name = wd.find_element_by_name("firstname").get_attribute( "value") last_name = wd.find_element_by_name("lastname").get_attribute("value") id = wd.find_element_by_name("id").get_attribute("value") home = wd.find_element_by_name("home").get_attribute("value") mobile = wd.find_element_by_name("mobile").get_attribute("value") work = wd.find_element_by_name("work").get_attribute("value") phone2 = wd.find_element_by_name("phone2").get_attribute("value") email = wd.find_element_by_name("email").get_attribute("value") email_2 = wd.find_element_by_name("email2").get_attribute("value") email_3 = wd.find_element_by_name("email3").get_attribute("value") address = wd.find_element_by_name("address").get_attribute("value") return Contacts(first_name=first_name, last_name=last_name, id=id, home=home, work=work, mobile=mobile, phone2=phone2, email=email, email_2=email_2, email_3=email_3, address=address)
def get_contact_info_from_edit_page(self, index): wd = self.app.wd NavigationHelper.open_home_page(self) self.select_contact_by_index(index) self.edit_contact_by_index(index) firstname = wd.find_element_by_name("firstname").get_attribute("value") lastname = wd.find_element_by_name("lastname").get_attribute("value") address = wd.find_element_by_name("address").get_attribute("value") id = wd.find_element_by_name("id").get_attribute("value") home = wd.find_element_by_name("home").get_attribute("value") mobile = wd.find_element_by_name("mobile").get_attribute("value") phone2 = wd.find_element_by_name("phone2").get_attribute("value") email = wd.find_element_by_name("email").get_attribute("value") email2 = wd.find_element_by_name("email2").get_attribute("value") email3 = wd.find_element_by_name("email3").get_attribute("value") return Contacts(firstname=firstname, lastname=lastname, address=address, id=id, home=home, mobile=mobile, phone2=phone2, email=email, email2=email2, email3=email3)
def test_delete_some_contact(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contacts.create((Contacts(first_name="test", middle_name="test2", last_name="test3", nickname="test4", title="test5", company="test_company", address="trtrtrt", home="64645", mobile="75675", work="8787", fax="55657", email="*****@*****.**", email_2="hgjgj2TR.UY", homepage="rtete.com", b_year="1993", address_2="ytyt", notes="hghg"))) old_contacts = db.get_contact_list() contact = random.choice(old_contacts) app.contacts.delete_contact_by_id(contact.id) time.sleep(1) new_contacts = db.get_contact_list() assert len(old_contacts) - 1 == app.contacts.count() old_contacts.remove(contact) assert old_contacts == new_contacts if check_ui: assert sorted(new_contacts, key=Contacts.id_or_max) == sorted( app.contacts.get_contact_list(), key=Contacts.id_or_max)
def get_contact_info_from_edit_page( self, index): # открываем форму редактирования, читаем из нее инфу wd = self.app.wd self.open_contact_to_edit_by_index(index) firstname = wd.find_element_by_name("firstname").get_attribute("value") lastname = wd.find_element_by_name("lastname").get_attribute("value") id = wd.find_element_by_name("id").get_attribute("value") homephone = wd.find_element_by_name("home").get_attribute("value") workphone = wd.find_element_by_name("work").get_attribute("value") mobilephone = wd.find_element_by_name("mobile").get_attribute("value") secondaryphone = wd.find_element_by_name("phone2").get_attribute( "value") address = wd.find_element_by_name("address").text email = wd.find_element_by_name("email").get_attribute("value") email2 = wd.find_element_by_name("email2").get_attribute("value") email3 = wd.find_element_by_name("email3").get_attribute("value") return Contacts(firstname=firstname, lastname=lastname, id=id, homephone=homephone, mobilephone=mobilephone, workphone=workphone, secondaryphone=secondaryphone, address=address, email=email, email2=email2, email3=email3) # построение объекта из этих данных
def get_contact_by_id(self, id_cont): list_cont = [] cursor = self.connection.cursor() try: cursor.execute( "select id, firstname, lastname, address, mobile, home, work, phone2, email, email2, email3 " "from addressbook where deprecated = '0000-00-00 00:00:00' and id='%s'" % id_cont) for row in cursor: (id, firstname, lastname, address, mobile, home, work, phone2, email, email2, email3) = row list_cont.append( Contacts(id=str(id), firstname=firstname, lastname=lastname, address=address, mobile=mobile, home=home, work=work, phone2=phone2, email=email, email2=email2, email3=email3)) finally: cursor.close() return list_cont
def get_contact_list(self): if self.contact_cache is None: wd = self.app.wd self.open_contact_home_page() self.contact_cache = [] for row in wd.find_elements_by_name( "entry"): # находим все элементы, делаем по ним цикл cells = row.find_elements_by_tag_name( "td") # получение текста, обращение к свойству firstname = cells[2].text lastname = cells[1].text address = cells[3].text all_emails = cells[4].text #id = element.find_element_by_name("selected[]").get_attribute("value") # получение идентификатора id = cells[0].find_element_by_tag_name("input").get_attribute( "value") all_phones = cells[5].text self.contact_cache.append( Contacts(firstname=firstname, lastname=lastname, id=id, all_phones_from_home_page=all_phones, address=address, all_emails_from_home_page=all_emails)) # all_phones = cells[5].text.splitlines() # из ячейки читаются только все телефоны, полученную строку разрезаем на части(берем текст из ячейки и делим на (text.splitlines)) # self.contact_cache.append(Contacts(firstname=firstname, lastname=lastname, id=id, all_phones_from_home_page = all_phones, homephone=all_phones[0],mobilephone=all_phones[1], workphone=all_phones[2],secondaryphone=all_phones[3])) # по text и id построение объекта типа контакт и добавление в список return list(self.contact_cache)
def get_contacts_list(self): list = [] cursor = self.connection.cursor() try: cursor.execute( "select id, firstname, lastname, home, work, mobile, phone2, address, email, email2, email3 " "from addressbook where deprecated='0000-00-00 00:00:00'") for row in cursor.fetchall(): (id, firstname, lastname, homephone, workphone, mobilephone, secondaryphone, address, email, email2, email3) = row list.append( Contacts(id=str(id), firstname=firstname, lastname=lastname, homephone=homephone, workphone=workphone, mobilephone=mobilephone, secondaryphone=secondaryphone, address=address, email=email, email2=email2, email3=email3)) finally: cursor.close() return list
def test_modif_first_contact(app, db, check_ui): if len(db.get_contacts_list()) == 0: app.contacts.create(Contacts(firstname="test")) old_contacts = db.get_contacts_list() contacts = Contacts(firstname="test1") contacts.id = random.choice(old_contacts).id app.contacts.modif_contact_by_id(id, contacts) new_contacts = db.get_contacts_list() assert len(old_contacts) == len(new_contacts) old_contacts.id = contacts assert sorted(old_contacts, key=Contacts.id_or_max) == sorted(new_contacts, key=Contacts.id_or_max) if check_ui: assert sorted(old_contacts, key=Contacts.id_or_max) == sorted( app.contacts.get_contacts_list(), key=Contacts.id_or_max)
def get_contact_info_from_edit_page(self, index): wd = self.app.wd self.open_contact_to_edit_by_index(index) name = wd.find_element_by_name("firstname").get_attribute("value") lastname = wd.find_element_by_name("lastname").get_attribute("value") companyaddress = wd.find_element_by_name("address").get_attribute( "value") id = wd.find_element_by_name("id").get_attribute("value") email = wd.find_element_by_name("email").get_attribute("value") email2 = wd.find_element_by_name("email2").get_attribute("value") email3 = wd.find_element_by_name("email3").get_attribute("value") homenumber = wd.find_element_by_name("home").get_attribute("value") mobilenumber = wd.find_element_by_name("mobile").get_attribute("value") worknumber = wd.find_element_by_name("work").get_attribute("value") secondhomenumber = wd.find_element_by_name("phone2").get_attribute( "value") return Contacts(name=name, lastname=lastname, companyaddress=companyaddress, id=id, email=email, email2=email2, email3=email3, homenumber=homenumber, mobilenumber=mobilenumber, worknumber=worknumber, secondhomenumber=secondhomenumber)
def get_cont_list(self): list = [] cursor = self.connection.cursor() try: cursor.execute( "select id, firstname, middlename, lastname, company, title, address, home, mobile, work, email, email2, email3, phone2 from addressbook where deprecated='0000-00-00 00:00:00'" ) for row in cursor: (id, firstname, middlename, lastname, company, title, address, home, mobile, work, email, email2, email3, phone2) = row list.append( Contacts(id=str(id), name=firstname, lastN=lastname, address=address, home=home, mobile=mobile, work=work, email1=email, email2=email2, email3=email3, phone2=phone2)) finally: cursor.close() return list
def get_contact_list(self): if self.contact_cache is None: wd = self.app.wd self.open_contacts_page() self.contact_cache = [] for element in wd.find_elements_by_css_selector("tr"): if element.get_attribute("name") != 'entry': continue last_name = element.find_elements_by_css_selector("td")[1].text first_name = element.find_elements_by_css_selector( "td")[2].text address = element.find_elements_by_css_selector("td")[3].text id = element.find_element_by_name("selected[]").get_attribute( "value") all_emails = element.find_elements_by_css_selector( "td")[4].text all_phones = element.find_elements_by_css_selector( "td")[5].text self.contact_cache.append( Contacts( first_name=first_name, last_name=last_name, id=id, address=address, all_phones=all_phones, all_emails=all_emails # , # address=address, email=all_emails[0], email_2=all_emails[1], # email_3=all_emails[2], home=all_phones[0], mobile=all_phones[1], # work=all_phones[2], phone2=all_phones[3] )) return list(self.contact_cache)
def test_add_contacts(app): app.group.mod_first_contact( Contacts(firstname="Petr", lastname="Ivanov", nickname="petrhulk", title="BIGBOSS", company="Company The Best", email="*****@*****.**"))
def test_add_contacts(app): app.group.add_new_contact( Contacts(firstname="Ekaterina", lastname="Samoilova", nickname="eksam", title="123", company="Ek and Co", email="*****@*****.**"))
def test_Contact4(app): old_cont = app.contact.get_cont_list() added = Contacts( name = "Nick2", lastN = "Sonick2") app.contact.add(added) assert len(old_cont) + 1 == app.contact.count() new_cont = app.contact.get_cont_list() old_cont.append(added) assert sorted(old_cont, key = Contacts.id_or_max) == sorted(new_cont, key = Contacts.id_or_max)
def test_add_two_contacts(app): app.group.add_new_contact( Contacts(firstname="Ivan", lastname="Petrov", nickname="ivaN", title="luxry", company="VIPcomp", email="*****@*****.**"))
def get_contact_from_view_page(self, index): wd = self.app.wd self.open_contact_view_by_index(index) text = wd.find_element_by_id("content").text home = re.search("H: (.*)", text).group(1) mobile = re.search("M: (.*)", text).group(1) work = re.search("W: (.*)", text).group(1) phone2 = re.search("P: (.*)", text).group(1) return Contacts(home=home, work=work, mobile=mobile, phone2=phone2)
def get_contact_from_view_page(self, index): wd = self.app.wd NavigationHelper.open_home_page(self) self.select_contact_by_index(index) self.open_contact_view_by_index(index) text = wd.find_element_by_id("content").text home = re.search("H: (.*)", text).group(1) mobile = re.search("M: (.*)", text).group(1) phone2 = re.search("P: (.*)", text).group(1) return Contacts(home=home, mobile=mobile, phone2=phone2)
def test_add_contact_to_group(app): if len(db.get_contacts_list()) == 0: app.contacts.create(Contacts(firstname="test")) if len(db.get_group_list()) == 0: app.group.create(Group(name="Test")) old_contacts = db.get_contacts_list() old_groups = db.get_group_list() contact = random.choice(old_contacts) group = random.choice(old_groups) old_contacts_in_group = db.get_contacts_in_group(group) if len(db.get_contacts_list()) == len(old_contacts_in_group): app.contact.create(Contacts(firstname="test")) app.contacts.add_contacts_to_group(contact, group) new_contacts_in_group = db.get_contacts_in_group(group) assert len(old_contacts_in_group) + 1 == len(new_contacts_in_group) old_contacts_in_group.append(contact) assert sorted(old_contacts_in_group, key=Contacts.id_or_max) == sorted(new_contacts_in_group, key=Contacts.id_or_max)
def test_edit_cont_name(app, db, check_ui): if len(db.get_cont_list()) == 0: app.contact.add(Contacts(lastN="for del")) old_cont = db.get_cont_list() contact_edit = random.choice(old_cont) #случайный выбор контакта changed = Contacts(name='Task20', lastN='N_Task20', address='Ad_Task20') #изменяемые данные changed.id = contact_edit.id #его id app.contact.edit_contact_by_id(changed.id, changed) new_cont = db.get_cont_list() assert len(old_cont) == len(new_cont) old_cont.remove(contact_edit) old_cont.append( Contacts(name='Task20', lastN='N_Task20', address='Ad_Task20')) assert sorted(old_cont, key=Contacts.id_or_max) == sorted(new_cont, key=Contacts.id_or_max) if check_ui: assert sorted(new_cont, key=Contacts.id_or_max) == sorted( app.contact.get_cont_list(), key=Contacts.id_or_max)
def get_contact_list(self): list = [] cursor = self.connection.cursor() try: cursor.execute("select id, firstname, lastname, address, email, home from addressbook where deprecated = '0000-00-00 00:00:00'") for row in cursor: (id, firstname, lastname, address, email, home) = row list.append(Contacts(id=str(id), name=firstname, lastname=lastname, companyaddress=address, email=email, homenumber=home)) finally: cursor.close() return list
def test_del_Cont(app): if app.contact.count() == 0: app.contact.add(Contacts(lastN="for del")) old_cont = app.contact.get_cont_list() index = randrange(len(old_cont)) print(list(old_cont)) app.contact.del_Cont_by_index(index) assert len(old_cont) - 1 == app.contact.count() new_cont = app.contact.get_cont_list() old_cont[index:index + 1] = [] assert old_cont == new_cont
def clean(contact): return Contacts(id=contact.id, firstname=contact.firstname.strip(), lastname=contact.lastname.strip(), address=contact.address.strip(), home=contact.home, mobile=contact.mobile, phone2=contact.phone2, email=contact.email, email2=contact.email2, email3=contact.email3)
def clean(contact): return Contacts(id=contact.id, lastN=contact.lastN.strip(), name=contact.name.strip(), address=contact.address.strip(), mobile=contact.mobile, email1=contact.email1, email2=contact.email2, email3=contact.email3, home=contact.home, work=contact.work, phone2=contact.phone2)
def test_edit_contact(app, db, check_ui): if len(db.get_contact_list()) == 0: app.contact.create(Contacts(firstname="for modify test_")) contact = Contacts(firstname="new1", middlename="new2", lastname="new3", nickname="new4") old_contacts = db.get_contact_list() index = random.randrange(len(old_contacts)) contact.id = old_contacts[index].id id = contact.id app.contact.edit_contact_by_id(contact, id) new_contacts = db.get_contact_list() assert len(old_contacts) == len(new_contacts) old_contacts[index] = contact assert sorted(old_contacts, key=Contacts.id_or_max) == sorted(new_contacts, key=Contacts.id_or_max) if check_ui: assert sorted(new_contacts, key=Contacts.id_or_max) == sorted( app.contact.get_contacts_list(), key=Contacts.id_or_max)
def get_contact_from_view_page(self, index): wd = self.app.wd self.open_contact_to_view_by_index(index) text = wd.find_element_by_id("content").text homenumber = re.search("H: (.*)", text).group(1) mobilenumber = re.search("M: (.*)", text).group(1) worknumber = re.search("W: (.*)", text).group(1) secondhomenumber = re.search("P: (.*)", text).group(1) return Contacts(homenumber=homenumber, mobilenumber=mobilenumber, worknumber=worknumber, secondhomenumber=secondhomenumber)