class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config="target.json", browser="Chrome"): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config) with open(config_file) as f: self.target = json.load(f) def init_fixtures(self): web_config = self.target['web'] self.fixture = Application(browser=self.browser, base_url=web_config['baseUrl']) self.fixture.session.ensure_login(username=web_config['username'], password=web_config['password']) db_config = self.target['db'] self.dbfixture = DbFixture(host = db_config['host'], name = db_config['name'], user = db_config['user'], password = db_config['password']) def destroy_fixtures(self): self.dbfixture.destroy() self.fixture.destroy() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def get_group_list(self): return self.dbfixture.get_group_list() def create_group(self, group): self.fixture.group.create(group) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.id) def group_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Group.id_or_max) == sorted(list2, key=Group.id_or_max)
class Addressbook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self,config="target.json", browser="chrome"): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(_file_)), "..", config) with open(config_file) as f: self.target = json.load(f) def init_fixtures(self): web_config = self.target ['web'] self.fixture = Application(browser=self.browser, base_url=web_config('baseUrl')) self.fixture.session.ensure_login(username=web_config["username"], password=web_config["password"]) db_config = self.target['db'] self.dbfixture = DbFixture(host=db_config['host'], name=db_config['name'], user=db_config['user'], password=db_config['password']) def destroy_fixtures(self): self.dbfixture.destroy() self.fixture.destroy() def create_group(self, name, header, footer): self.fixture.group.create(Group(name=name, header=header, footer=footer))
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config="target.json", browser="firefox"): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config) with open(config_file) as f: self.target = json.load(f) def init_fixtures(self): web_config = self.target['web'] self.fixture = Application(browser=self.browser, base_url=web_config['baseUrl']) self.fixture.session.ensure_login(username=web_config['username'], password=web_config['password']) db_config = self.target['db'] self.dbfixture = DbFixture(host=db_config['host'], name=db_config['name'], user=db_config['user'], password=db_config['password']) def destroy_fixtures(self): self.dbfixture.destroy() self.fixture.destroy() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def get_group_list(self): return self.dbfixture.get_group_list() def create_group(self, group): self.fixture.group.create(group) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.id) def modify_group(self, source_group, new_data_group): self.fixture.group.modify_group_by_id(source_group.id, new_data_group) def group_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Group.id_or_max) == sorted(list2, key=Group.id_or_max) def new_contact(self, lastname, firstname, address, home, mobile, work, phone2, email, email2, email3): return Contact(lastname=lastname, firstname=firstname, address=address, home=home, mobile=mobile, work=work, phone2=phone2, email=email, email2=email2, email3=email3) def get_contact_list(self): return self.dbfixture.get_contact_list() def add_contact(self, contact): self.fixture.contact.add(contact) def delete_contact(self, contact): self.fixture.contact.delete_contact_by_id(contact.id) self.fixture.wd.implicitly_wait(5) def modify_contact(self, source_contact, new_data_contact): self.fixture.contact.modify_contact_by_id(source_contact.id, new_data_contact) def contact_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Contact.id_or_max) == sorted(list2, key=Contact.id_or_max)
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST_SUITE' def __init__(self, config='target.json', browser='chrome'): self.browser = browser path_to_config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', config) with open(path_to_config_file) as config_file: self.target = json.load(config_file) def init_fixtures(self): self.fixture = Application(browser=self.browser, base_url=self.target['web']['baseUrl']) self.fixture.session.check_login(username=self.target['web']['username'], password=self.target['web']['password']) db_config = self.target['db'] self.dbfixture = DbFixture(host=db_config['host'], name=db_config['name'], user=db_config['user'], password=db_config['password']) def destroy_fixtures(self): self.fixture.destroy() self.dbfixture.destroy() # GROUPS def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def create_group(self, group): self.fixture.group.create(group) def get_group_list(self): return self.dbfixture.get_groups_list() def group_lists_should_be_equal(self, old_list, new_list): assert sorted(old_list, key=Group.sorting_id_or_maxsize) == sorted(new_list, key=Group.sorting_id_or_maxsize) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.id) # CONTACTS def new_contact(self, firstname, lastname): return Contact(firstname=firstname, lastname=lastname) def create_contact(self, contact): self.fixture.contact.create(contact) def get_contact_list(self): return self.dbfixture.get_contacts_list() def contact_lists_should_be_equal(self, old_list, new_list): assert sorted(old_list, key=Contact.sorting_id_or_maxsize) == sorted(new_list, key=Contact.sorting_id_or_maxsize) def delete_contact(self, contact): self.fixture.contact.delete_contact_by_id(contact.id) def modify_contact(self, contact, new_contact): new_contact.id = contact.id # чтоб в изм. контакте был заданный id, не None. А то будут проблемы при сортировке self.fixture.contact.modify_contact_by_id(contact.id, new_contact)
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config = 'target.json', browser='firefox'): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', config) with open(config_file) as f: self.target = json.load(f) def init_fixtures(self): web_config = self.target["web"] self.fixture = Application(browser=self.browser, base_url=web_config['baseUrl']) self.fixture.session.ensure_login(username=web_config["username"], password=web_config["password"]) db_config = self.target["db"] self.dbfixture = DbFixture(host=db_config["host"], name=db_config["name"], user=db_config["user"], password=db_config["password"]) def destroy_fixtures(self): self.fixture.destroy() self.dbfixture.destroy() def get_group_list(self): return self.dbfixture.get_group_list() def get_contact_list(self): return self.dbfixture.get_contact_list() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def new_contact(self, firstname, lastname): return Contact(firstname=firstname, lastname=lastname) def create_group(self, group): self.fixture.group.create(group) def create_contact(self, contact): self.fixture.contact.add_new(contact) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.id) def delete_contact(self, contact): self.fixture.contact.delete_contact_by_id(contact.id) def change_contact_name(self, contact, new_name): edited_contact = contact edited_contact.firstname = new_name self.fixture.contact.edit_contact_by_id(edited_contact, contact.id) def group_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Group.id_or_max) == sorted(list2, key=Group.id_or_max) def contact_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Contact.id_or_max) == sorted(list2, key=Contact.id_or_max)
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config="target.json", browser="firefox"): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config) with open(config_file) as f: self.target = json.load(f) def init_fixtures(self): web_config = self.target['web'] self.fixture = Application(browser=self.browser, baseurl=web_config['baseurl']) self.fixture.session.ensure_login(username=web_config['username'], password=web_config['password']) db_config = self.target['db'] self.dbfixture = DbFixture(host=db_config['host'], name=db_config['name'], user=db_config['user'], password=db_config['password']) def destroy_fixtures(self): self.dbfixture.destroy() self.fixture.destroy() def new_contact(self, firstname, lastname): return Contact(firstname=firstname, lastname=lastname) def get_contact_list(self): return self.dbfixture.get_contact_list() def create_contact(self, contact): self.fixture.contact.create(contact) def delete_contact(self, contact): self.fixture.contact.delete_contact_by_id(contact.id) time.sleep(0.1) def modify_contact(self, contact, new_contact): self.fixture.contact.modify_contact_by_id(contact.id, new_contact) time.sleep(0.1) def contact_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Contact.id_or_max) == sorted(list2, key=Contact.id_or_max)
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config="target.json", browser="chrome"): self.browser = browser config_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config) with open(config_file_path) as f: self.target = json.load(f) def init_fixture(self): web_config = self.target["web"] self.fixture = Application(browser=self.browser, base_url=web_config["baseUrl"]) self.fixture.session.ensure_login(username=web_config['username'], password=web_config['password']) db_config = self.target["db"] self.dbfixture = DbFixture(host=db_config["host"], name=db_config["name"], user=db_config["user"], password=db_config["password"]) def destroy_fixture(self): self.dbfixture.destroy() self.fixture.destroy() def get_group_list(self): return self.dbfixture.get_group_list() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def create_group(self, group): self.fixture.group.create(group) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.id) def group_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Group.id_or_max) == sorted(list2, key=Group.id_or_max)
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config="target.json", browser="chrome"): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config) with open(config_file) as f: self.target = json.load(f) def init_fixtures(self): web_config = self.target['web'] self.fixture = Application(browser=self.browser, base_url=web_config["baseUrl"]) self.fixture.session.ensure_login(username=web_config["username"], password=web_config["password"]) db_config = self.target['db'] self.dbFixture = DbFixture(host=db_config["host"], name=db_config["name"], user=db_config["user"], password=db_config["password"]) def destroy_fixtures(self): self.dbFixture.destroy() self.fixture.destroy() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def get_group_list(self): return self.dbFixture.get_group_list() def create_group(self, group): self.fixture.group.create(group) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.id) def group_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Group.id_or_max) == sorted(list2, key=Group.id_or_max) def new_contact(self, firstname, middlename, lastname, nickname, title, company, address, fax, mobilephone, workphone, homephone, email, email2, email3, homepage, option1, option2, byear, option3, option4, ayear, address2, secondaryphone, notes): return Contact(firstname=firstname, middlename=middlename, lastname=lastname, nickname=nickname, title=title, company=company, address=address, fax=fax, mobilephone=mobilephone, workphone=workphone, homephone=homephone, email=email, email2=email2, email3=email3, homepage=homepage, option1=option1, option2=option2, byear=byear, option3=option3, option4=option4, ayear=ayear, address2=address2, secondaryphone=secondaryphone, notes=notes) def get_contact_list(self): return self.dbFixture.get_contact_list() def create_contact(self, contact): self.fixture.contact.create(contact) def delete_contact(self, contact): self.fixture.contact.delete_contact_by_id(contact.id) def edit_contact(self, contact, new_contact): self.fixture.contact.edit_contact_by_id(contact.id, new_contact) def fix_new_contact_id(self, contact, new_contact): new_contact.id = contact.id return new_contact def contact_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Contact.id_or_max) == sorted(list2, key=Contact.id_or_max)
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config='target.json', browser='chrome'): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config) with open(config_file) as f: self.target = json.load(f) def init_fixtures(self): web_config = self.target["web"] self.fixture = Application(browser=self.browser, base_url=web_config["baseUrl"]) self.fixture.session.ensure_login(username=web_config["username"], password=web_config["password"]) db_config = self.target["db"] self.dbfixture = DbFixture(host=db_config["host"], name=db_config["name"], user=db_config["user"], password=db_config["password"]) def destroy_fixtures(self): self.dbfixture.destroy() self.fixture.destroy() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def get_group_list(self): return self.dbfixture.get_group_list() def create_group(self, group): self.fixture.group.create(group) def group_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Group.id_or_max) == sorted(list2, key=Group.id_or_max) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.id) def get_contact_list(self): return self.dbfixture.get_contact_list() def new_contact(self, firstname, lastname, address, home, mobile): return Contact(firstname=firstname, lastname=lastname, address=address, home=home, mobile=mobile) def new_contact_data(self, id, firstname, lastname, address, home, mobile): return Contact(id=id, firstname=firstname, lastname=lastname, address=address, home=home, mobile=mobile) def create_contact(self, contact): self.fixture.contact.create(contact) def contact_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Contact.id_or_max) == sorted(list2, key=Contact.id_or_max) def edit_contact(self, contact, contact_data): self.fixture.contact.edit_contact_by_id(contact.id, contact_data) def delete_contact(self, contact): self.fixture.contact.delete_by_id_from_edit_form(contact.id)
#import mysql.connector import pymysql.cursors from fixture.db import DbFixture db = DbFixture(host="127.0.0.1", name="addressbook", user="******", password="") try: contacts = db.get_contact_list() for contact in contacts: print(contact) print(len(contacts)) finally: db.destroy()
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config="target.json", browser="chrome"): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config) with open(config_file) as f: self.target = json.load(f) def init_fixture(self): web_config = self.target['web'] self.fixture = Application(browser=self.browser, base_url=web_config['baseUrl']) self.fixture.session.ensure_login(username=web_config['username'], password=web_config['password']) db_config = self.target['db'] self.dbfixture = DbFixture(host=db_config['host'], name=db_config['database'], user=db_config['user'], password=db_config['password']) def destroy_fixture(self): self.dbfixture.destroy() self.fixture.destroy() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def get_group_list(self): return self.dbfixture.get_group_list() def create_group(self, group): self.fixture.group.create(group) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.id) def group_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Group.id_or_max) == sorted(list2, key=Group.id_or_max) def get_contact_list(self): return self.dbfixture.get_contact_list() def new_contact(self, firstname, middlename, lastname, nickname, title, company, address, home, mobile, work, fax, email, email2, email3, homepage, address2, phone2, notes, bday, bmonth, byear, aday, amonth, ayear): return Contact(firstname=firstname, middlename=middlename, lastname=lastname, nickname=nickname, title=title, company=company, address1=address, homephone=home, mobilephone=mobile, workphone=work, fax=fax, email1=email, email2=email2, email3=email3, homepage=homepage, bdaydate=bday, bmonth=bmonth, aday=aday, amonth=amonth, byear=byear, ayear=ayear, address2=address2, phone2=phone2, notes1=notes) def create_contact(self, contact): self.fixture.contact.add_new_contact() self.fixture.contact.fill_data(contact) self.fixture.contact.submit() def contact_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Contact.id_or_max) == sorted(list2, key=Contact.id_or_max) def delete_contact(self, contact): self.fixture.contact.delete_contact_by_id(contact.id) def edit_contact(self, contact): self.fixture.contact.edit_contact_by_id(contact.id) def edited_contact(self, firstname, middlename, lastname, nickname, title, company, address, home, mobile, work, fax, email, email2, email3, homepage, address2, phone2, notes, bday, bmonth, byear, aday, amonth, ayear): return Contact(firstname=firstname, middlename=middlename, lastname=lastname, nickname=nickname, title=title, company=company, address1=address, homephone=home, mobilephone=mobile, workphone=work, fax=fax, email1=email, email2=email2, email3=email3, homepage=homepage, bdaydate=bday, bmonth=bmonth, aday=aday, amonth=amonth, byear=byear, ayear=ayear, address2=address2, phone2=phone2, notes1=notes) def update_contact(self, contact): self.fixture.contact.fill_data(contact) self.fixture.contact.update() time.sleep(5) def update_old_list(self, old_contact, contact): for i in old_contact: if i.id == contact.id: i.firstname = contact.firstname i.lastname = contact.lastname return old_contact
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config="target.json", browser="chrome"): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config) with open(config_file) as f: self.target = json.load(f) def init_fixtures(self): web_config = self.target['web'] self.fixture = Application(browser=self.browser, base_url=web_config['baseUrl']) self.fixture.session.ensure_login(username=web_config['username'], password=web_config['password']) db_config = self.target['db'] self.dbfixture = DbFixture(host=db_config['host'], name=db_config['name'], user=db_config['user'], password=db_config['password']) def destroy_fixtures(self): self.fixture.destroy() self.dbfixture.destroy() def get_group_list(self): return self.dbfixture.get_group_list() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def create_group(self, group): self.fixture.group.create(group) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.id) def group_list_should_be_equals(self, list1, list2): def clear(group): return Group(id=group.id, name=re.sub(" +", " ", group.name).strip()) assert sorted(map(clear, list1), key=Group.id_or_max) == sorted(map(clear, list2), key=Group.id_or_max) def get_contact_list(self): return self.dbfixture.get_contact_list() def new_contact(self, firstname, middlename, lastname): return Contact(firstname=firstname, middlename=middlename, lastname=lastname) def create_contact(self, contact): self.fixture.contact.create(contact) def contact_list_should_be_equals(self, list1, list2): assert sorted(list1, key=Contact.id_or_max) == sorted(list2, key=Contact.id_or_max) def delete_contact(self, contact): self.fixture.contact.delete_contact_by_id(contact.id) def get_non_empty_contact_list(self): if len(self.dbfixture.get_contact_list()) == 0: self.fixture.contact.create( Contact(firstname="Name", middlename="Middle", lastname="Surname")) return self.dbfixture.get_contact_list() def modify_contact(self, random_contact, new_contact): self.fixture.contact.modify_contact_by_id(new_contact, random_contact.id)
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config="target.json", browser="chrome"): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config) with open(config_file) as f: self.target = json.load(f) def init_fixtures(self): web_config = self.target['web'] self.fixture = Application(browser=self.browser, base_url=web_config["baseUrl"]) self.fixture.session.ensure_login(username=web_config["username"], password=web_config["password"]) db_config = self.target['db'] self.dbfixture = DbFixture(host=db_config['host'], name=db_config['name'], user=db_config['user'], password=db_config['password']) def destroy_fixtures(self): self.fixture.destroy() self.dbfixture.destroy() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def new_group_for_modify(self, name, header, footer, id): return Group(name=name, header=header, footer=footer, id=id) def get_group_list(self): return self.dbfixture.get_group_list() def create_group(self, group): self.fixture.group.create(group) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.id) def get_group_id(self, group): return group.id def get_contact_id(self, contact): return contact.id def modify_group(self, group1, group2): self.fixture.group.modify_group_by_id(group1.id, group2) def group_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Group.id_or_max) == sorted(list2, key=Group.id_or_max) def verify_group_list_is_not_empty(self, list1): if len(list1) == 0: self.fixture.group.create(Group(name="New_group")) def get_contact_list(self): return self.dbfixture.get_contact_list() def new_contact(self, firstname, lastname, address): return Contact(firstname=firstname, lastname=lastname, address=address) def new_contact_for_modify(self, firstname, lastname, address, id): return Contact(firstname=firstname, lastname=lastname, address=address, id=id) def create_contact(self, contact): self.fixture.contact.create(contact) def verify_contact_list_is_not_empty(self, list1): if len(list1) == 0: self.fixture.contact.create( Contact(firstname="firstname4", lastname="lastname4", address="adress4")) def contact_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Contact.id_or_max) == sorted(list2, key=Contact.id_or_max) def delete_contact(self, contact): self.fixture.contact.delete_contact_by_id(contact.id) def modify_contact(self, contact1, contact2): self.fixture.contact.modify_contact_by_id(contact1.id, contact2)
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config="target.json", browser='firefox'): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', config) with open(config_file) as f: self.target = json.load(f) def init_fixtures(self): web_config = self.target['web'] self.fixture = Application(browser=self.browser, base_url=web_config['baseUrl']) self.fixture.session.ensure_login(username=web_config["username"], password=web_config["password"]) db_config = self.target['db'] self.dbfixture = DbFixture(host=db_config['host'], name=db_config['name'], user=db_config['user'], password=db_config['password']) def destroy_fixtures(self): self.dbfixture.destroy() self.fixture.destroy() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def get_group_list(self): return self.dbfixture.get_group_list() def create_group(self, group): self.fixture.group.create(group) def group_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Group.id_or_max) == sorted(list2, key=Group.id_or_max) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.id) def edit_group(self, random_group, edit_group): edit_group.id = random_group.id self.fixture.group.edit_group_by_id(edit_group.id, edit_group) def replace_values_list(self, old_list, index, edit_value): old_list[index] = edit_value def get_contact_list(self): return self.dbfixture.get_contact_list() def new_contact(self, firstname='name_123', lastname='name_456', mobile='789'): return Contact(firstname=firstname, lastname=lastname, mobile=mobile) def create_contact(self, contact): self.fixture.contact.create(contact) def contact_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Contact.id_or_max) == sorted(list2, key=Contact.id_or_max) def delete_contact(self, contact): self.fixture.contact.delete_contact_by_id(contact.id) def edit_contact(self, random_contact, edit_contact): edit_contact.id = random_contact.id self.fixture.contact.edit_contact_by_id(edit_contact.id, edit_contact)
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST_SUITE' def __init__(self, config='target.json', browser='chrome'): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', config) with open(config_file) as f: self.target = json.load(f) def init_fixtures(self): web_config = self.target['web'] self.fixture = Application(browser=self.browser, base_url=web_config['baseUrl'], host_ip=web_config['hostip']) self.fixture.session.ensure_login(username=web_config['username'], password=web_config['password']) db_config = self.target['db'] self.dbfixture = DbFixture(host=db_config['host'], name=db_config['name'], user=db_config['user'], password=db_config['password']) def destroy_fixtures(self): self.fixture.destroy() self.dbfixture.destroy() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def get_group_list(self): return self.dbfixture.get_group_list() def create_group(self, group): self.fixture.group.create(group) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.id) def group_lists_should_be_equal(self, new_list, old_list): assert sorted(old_list, key=Group.id_or_max) == sorted(new_list, key=Group.id_or_max) def new_contact(self, firstname, lastname): return Contact(firstname=firstname, lastname=lastname) def get_contact_list(self): return self.dbfixture.get_contact_list() def create_contact(self, contact): self.fixture.contact.create_contact(contact) def delete_contact(self, contact): self.fixture.contact.delete_contact_by_id(contact.id) time.sleep(4) def modify_contact(self, contact): self.fixture.contact.modify_contact_by_id(contact.id, contact) def contact_lists_should_be_equal(self, new_list, old_list): assert sorted(old_list, key=Contact.id_or_max) == sorted(new_list, key=Contact.id_or_max)
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' # Едиый объект для всего тестового набора def __init__(self, config="target.json", browser="firefox"): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config) # Определение пути к конфигурационному файлу по умолчанию with open(config_file) as f: # Открыть файл, контроль автоматического закрытия после выполнения блока команд self.target = json.load(f) # Загрузка данных из файла # Инициализация (создание) фикстур def init_fixtures(self): web_config = self.target["web"] # Получение данных конфигурации выполнения из файла для работы с Web self.fixture = Application(browser=self.browser, base_url=web_config['baseUrl']) self.fixture.session.ensure_login(username=web_config['username'], password=web_config['password']) # Авторизация пользователя db_config = self.target['db'] # Получение данных конфигурации выполнения из файла для работы с базой данных self.dbfixture = DbFixture(host=db_config['host'], name=db_config['name'], user=db_config['user'], password=db_config['password']) # Создание фикстуры работы с базой данных orm_config = self.target['db'] # Получение данных конфигурации выполнения из файла для работы с базой данных self.ormfixture = ORMFixture(host=orm_config['host'], name=orm_config['name'], user=orm_config['user'], password=orm_config['password']) # Создание фикстуры работы с базой данных # Уничтожение фикстур def destroy_fixtures(self): self.dbfixture.destroy() self.fixture.destroy() self.ormfixture.destroy() # Определение контакта def new_address(self, first_name, middle_name, last_name, address): return Address(first_name=first_name, middle_name=middle_name, last_name=last_name, address=address) # Контакт # Переопределение контакта по идетфикатору def new_address_with_id(self, id, first_name, middle_name, last_name, address): return Address(id=id, first_name=first_name, middle_name=middle_name, last_name=last_name, address=address) # Контакт # Получение идентификатора контакта из списка по его номеру def get_address_id_by_index_from_the_list(self, index, address_list): return address_list[index].id # Тдентификатор контакта # Получение списка контактов def get_address_list(self): return self.ormfixture.get_address_list() # Список контактов # Получение непустого списка контактов def get_not_empty_address_list(self): if len(self.ormfixture.get_address_list()) == 0: # Проверка наличия хотябы одного контакта в списке self.fixture.address.create(Address(first_name="Михаил", middle_name="Алексеевич", last_name="Новиков", nickname="M.Novikov", title="Title", company="КБ ДОРС", address="Федеративный пр. д.15 к.4", tel_home="001-13-59", tel_mobile="002-13-59", tel_work="003-13-59", tel_fax="004-13-59", web_email="*****@*****.**", web_email2="*****@*****.**", web_email3="*****@*****.**", web_homepage="http://software-testing.ru", birthday_day=14, birthday_month=11, birthday_year="1986", anniversary_day=1, anniversary_month=1, anniversary_year="2000", sec_address="Secondary Address", home="Home", notes="Notes")) # Создание контакта на случай пустого списка return self.get_address_list() # Список контактов # Создание контакта def create_address(self, address): self.fixture.address.create(address) # Создание нового контакта # Удаление контакта def delete_address(self, address): self.fixture.address.delete_address_by_id(address.id) # Удаление контакта по идентификатору # Изменение контакта def modify_address(self, address): self.fixture.address.modify_address_by_id(address) # Изменение контакта по идентификатору # Проверка равенства списков контактов def address_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Address.id_or_max) == sorted(list2, key=Address.id_or_max) # Сравнение сортированных по идентификатору списков контактов
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config="target.json", browser="chrome"): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config) with open(config_file) as f: self.target = json.load(f) def init_fixtures(self): web_config = self.target['web'] self.fixture = Application(browser=self.browser, base_URL=web_config['baseURL']) self.fixture.session.ensure_login(username=web_config["username"], password=web_config["password"]) db_config = self.target['db'] self.dbfixture = DbFixture(host=db_config['host'], name=db_config['name'], user=db_config['user'], password=db_config['password']) def destroy_fixtures(self): self.dbfixture.destroy() self.fixture.destroy() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def get_group_list(self): return self.dbfixture.get_group_list() def create_group(self, group): self.fixture.group.create(group) def group_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Group.id_or_max) == sorted(list2, key=Group.id_or_max) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.identifier) def get_contact_list(self): return self.dbfixture.get_contact_list() def new_contact(self, firstname1, middlename1, lastname1): return Contact(firstname=firstname1, middlename=middlename1, lastname=lastname1) def create_contact(self, contact): self.fixture.contact.create(contact) def contact_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Contact.id_or_max) == sorted(list2, key=Contact.id_or_max) print(list1, list2) def delete_contact(self, contact): self.fixture.contact.delete_contact_by_id(contact.identifier) def edit_contact(self, contact, new_contact_data): self.fixture.contact.edit_contact_by_id(contact.identifier, new_contact_data)
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config_file="target.json", browser="firefox"): self.browser = browser config = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config_file) with open(config_file) as config: self.target = json.load(config) def init_fixtures(self): web_config = self.target['web'] self.fixture = Application(browser=self.browser, base_url=web_config['baseUrl']) db_config = self.target['db'] self.dbfixture = DbFixture(host=db_config['host'], name=db_config['name'], user=db_config['user'], password=db_config['password']) self.fixture.session.ensure_login(username=web_config['username'], password=web_config['password']) def destroy_fixtures(self): self.fixture.destroy() self.dbfixture.destroy() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) # Group methods def get_group_list(self): return self.dbfixture.get_group_list() # TODO: try to implement single method which can be used # to choose both groups and contacts def choose_group_from_list(self, groups): return random.choice(groups) def create_group(self, group): self.fixture.groups.create(group) def delete_group(self, group): self.fixture.groups.delete_group_by_id(group.id) def group_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Group.id_or_maxval) == sorted(list2, key=Group.id_or_maxval) # Contact methods def get_contacts_list(self): return self.dbfixture.get_contacts_list() # TODO: try to implement single method which can be used # to choose both groups and contacts def choose_contact_from_list(self, contacts): return random.choice(contacts) def new_contact(self): return contact_with_rnd_data def create_contact(self, contact): self.fixture.contacts.create(contact) def delete_contact(self, contact): self.fixture.contacts.delete_contact_by_id(contact.id) def modify_contact(self, contact_to_modify, new_contact_data): new_contact_data.id = contact_to_modify.id # Save contact we got after entering data on edit form. # This is necessary for cases when we don't change # some of fields. return self.fixture.contacts.edit_contact_by_id(new_contact_data) def contacts_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Contact.id_or_maxval) == sorted(list2, key=Contact.id_or_maxval)
from fixture.db import DbFixture #Second Db for users --working db = DbFixture (host="127.0.0.1", name= "addressbook", user="******", password="") try: users=db.get_user_list() for user in users: print(user) print(len(users)) finally: db.destroy() #First -working # import mysql.connector # # connection = mysql.connector.connect (host="127.0.0.1", database= "addressbook", # user="******", password="") # # try: # cursor = connection.cursor() # cursor.execute("select * from group_list") # for row in cursor.fetchall(): # print(row) # # finally: # connection.close()
class AddressBook: ROBOT_LIBRARY_SCOPE = 'TEST SUITE' def __init__(self, config="target.json", browser="firefox"): self.browser = browser config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", config) with open(config_file) as f: self.target = json.load(f) def init_fixtures(self): web_config = self.target['web'] self.fixture = Application(browser=self.browser, base_url=web_config["baseUrl"]) self.fixture.session.ensure_login(username=web_config["username"], password=web_config["password"]) db_config = self.target['db'] self.dbfixture = DbFixture(host=db_config["host"], name=db_config["name"], user=db_config["user"], password=db_config["password"]) def destroy_fixtures(self): self.fixture.destroy() self.dbfixture.destroy() def new_group(self, name, header, footer): return Group(name=name, header=header, footer=footer) def new_groupWithID(self, group, name, header, footer): return Group(id=group.id, name=name, header=header, footer=footer) def get_group_list(self): return self.dbfixture.get_group_list() def create_group(self, group): self.fixture.group.create(group) def group_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Group.id_or_max) == sorted(list2, key=Group.id_or_max) def delete_group(self, group): self.fixture.group.delete_group_by_id(group.id) def modify_group(self, group): self.fixture.group.change_group_by_id(group.id, group) def get_contact_list(self): return self.dbfixture.get_contact_list() def new_contact(self, lastname, firstname, address, email, email2, email3, home_phone, mobile_phone, work_phone, phone2): return Contact(lastname=lastname, firstname=firstname, address=address, email=email, email2=email2, email3=email3, home_phone=home_phone, mobile_phone=mobile_phone, work_phone=work_phone, phone2=phone2) def new_contactWithID(self, contact, lastname, firstname, address, email, email2, email3, home_phone, mobile_phone, work_phone, phone2): return Contact(id=contact.id, lastname=lastname, firstname=firstname, address=address, email=email, email2=email2, email3=email3, home_phone=home_phone, mobile_phone=mobile_phone, work_phone=work_phone, phone2=phone2) def create_contact(self, new_contact): self.fixture.contact.add_new(new_contact) def contact_lists_should_be_equal(self, list1, list2): assert sorted(list1, key=Contact.id_or_max) == sorted(list2, key=Contact.id_or_max) def delete_contact(self, contact): self.fixture.contact.delete_contact_by_id(contact.id) def modify_contact(self, contact): self.fixture.contact.change_contact_by_id(contact.id, contact)