def get_product_list(self): wd = self.app.wd self.go_to_catalog_page() product_list = [] count = 0 while True: try: wd.find_elements_by_xpath( "//i[@class='fa fa-pencil']")[count].click() except: break name = wd.find_element_by_xpath( "//input[@name='name[en]']").get_attribute('value') wd.find_element_by_xpath( "//a[contains(text(),'Information')]").click() short_description = wd.find_element_by_xpath( "//input[@name='short_description[en]']").get_attribute( 'value') description = wd.find_element_by_xpath( "//textarea[@name='description[en]']").get_attribute('value') wd.find_element_by_xpath("//a[contains(text(),'Prices')]").click() USD = wd.find_element_by_xpath( "//input[@name='prices[USD]']").get_attribute('value') wd.find_element_by_xpath("//button[@value='Cancel']").click() product_list.append( Product(name=name, short_description=short_description, description=description, USD=USD)) count += 1 return product_list
def test_modify_product_name(appf_admin): with allure.step('Modify last product name in admin panel'): appf_admin.admin_panel.modify_last_product_name( Product(name='new_test_name')) with allure.step('Get element with product name from catalog'): name = appf_admin.admin_panel.get_element_with_product_name_from_catalog_table( 'new_test_name') with allure.step('Check that the name is correct'): assert name == 'new_test_name'
def test_remove_last_product(appf_admin, db): with allure.step('Get product count from db'): count = db.get_product_count() if count == 0: with allure.step('There are no products in the catalog, and we add new one'): appf_admin.admin_panel.add_new_product(Product( name='test_name', date_from='01.01.2018', date_to='01.01.2020', short_description='short_description', description='description', USD=100 )) count += 1 with allure.step('Remove last product'): appf_admin.admin_panel.remove_last_product() with allure.step('Get product count from db again'): count_after = db.get_product_count() with allure.step('Comparison the length of the old products list and new one. Old list is less by one product'): assert count -1 == count_after
def get_product_list(self): list_with_objs = [] cursor = self.connection.cursor() try: cursor.execute(""" SELECT lc_products_info.id, lc_products_info.name, lc_products_prices.USD FROM lc_products_info INNER JOIN lc_products_prices ON lc_products_info.id=lc_products_prices.id; """) for row in cursor: type_fixed_row = tuple([ el.decode('utf-8') if type(el) is bytearray else int(el) for el in row ]) (id, name, USD) = type_fixed_row list_with_objs.append(Product(id=id, name=name, USD=USD)) finally: cursor.close() return list_with_objs
def test_add_new_product(appf_admin, db, check_ui): with allure.step("Get list of products from DB"): products_before = db.get_product_list() with allure.step(f"Add product in admin panel"): appf_admin.admin_panel.add_new_product( Product( name = 'Product name', short_description = 'Short description', description = 'Description', USD = '78', ) ) with allure.step("Get list of products from DB again"): product_after = db.get_product_list() with allure.step("Comparison the length of the old products list and new one"): assert len(products_before) +1 == len(product_after) if check_ui: with allure.step("Comparison sorted lists of product-objects with fully info about products"): assert sorted(product_after, key=Product.sort_key_name) == \ sorted(appf_admin.admin_panel.get_product_list(), key=Product.sort_key_name)
from Parameter_Object.product import Product import random import string def random_string(maxlen): symbol = string.ascii_letters + string.digits return ''.join( [random.choice(symbol) for i in range(random.randrange(1, maxlen))]) def random_digits(maxlen): symbol = string.digits return ''.join( [random.choice(symbol) for i in range(random.randrange(1, maxlen))]) testdata = [ Product(name=random_string(10), short_description=random_string(10), description=random_string(100), USD=random_digits(3)) for i in range(10) ]