def startBrowser(): global driver if (ConfigReader.readConfigData('Details','Browser') == 'Chrome'): path = './drivers/chromedriver.exe' driver = Chrome(executable_path=path) elif (ConfigReader.readConfigData('Details','Browser') == 'Firefox'): path = './drivers/geckodriver.exe' driver = Firefox(executable_path=path) else: path = './drivers/chromedriver.exe' driver = Chrome(executable_path=path) driver.maximize_window() driver.get(ConfigReader.readConfigData('Details','Application_URL')) return driver
def cartClear(self): try: CartClass(driver).removeProduct() wait.until( ec.presence_of_element_located( (By.XPATH, ConfigReader.fetchElement('Cart', 'empty_cart_XPATH')))) except: print('Cart Clear', sys.exc_info()[0], "occurred.") CartClass(driver).removeProduct() finally: assert wait.until( ec.presence_of_element_located( (By.XPATH, ConfigReader.fetchElement('Cart', 'empty_cart_XPATH')))) driver.close()
def selectBrand(self, brand): search_brand_txtbx = wait.until( ec.element_to_be_clickable( (By.XPATH, ConfigReader.fetchElement('SearchProduct', 'searchbrand_textbox_XPATH')))) driver.execute_script("arguments[0].click();", search_brand_txtbx) search_brand_txtbx.send_keys(Keys.CONTROL, 'a') search_brand_txtbx.send_keys(brand) brand_chckbx = wait.until( ec.element_to_be_clickable( (By.XPATH, ConfigReader.fetchElement('SearchProduct', 'brand_selection_XPATH')))) driver.execute_script("arguments[0].click();", brand_chckbx)
def shoeSizeSelection(self): shoe_sizelist = wait.until( ec.presence_of_all_elements_located( (By.XPATH, ConfigReader.fetchElement('SearchProduct', 'shoe_size_list_XPATH')))) random.choice(shoe_sizelist).click()
def additionToCart(self): try: wait.until( ec.element_to_be_clickable( (By.XPATH, ConfigReader.fetchElement('SearchProduct', 'add_To_cart_XPATH')))).click() wait.until( ec.url_to_be( ConfigReader.fetchElement('SearchProduct', 'cart_matching_URL'))) driver.close() except: print( 'Product is not available currently, we will notify once it is available' ) driver.close()
def categoryCorrection(self, category): srch_bx_ctgry = driver.find_element( By.NAME, ConfigReader.fetchElement( 'Login', 'searchCategory_textbox_NAME')).get_property('value') while srch_bx_ctgry != category: LoginPageClass(driver).category(category) if srch_bx_ctgry.text == category: break
def category(self, category): ctgry_srch_txtbx = wait.until( ec.element_to_be_clickable( (By.NAME, ConfigReader.fetchElement('Login', 'searchCategory_textbox_NAME')))) ctgry_srch_txtbx.send_keys(Keys.CONTROL, 'a') ctgry_srch_txtbx.send_keys(category) ctgry_srch_txtbx.submit()
def removeProduct(self): cart_prd_list = wait.until( ec.visibility_of_all_elements_located( (By.XPATH, ConfigReader.fetchElement('Cart', 'cart_elements_XPATH')))) for items in cart_prd_list: rmv_prd_btn = wait.until( ec.element_to_be_clickable( (By.XPATH, ConfigReader.fetchElement('Cart', 'remove_button_XPATH')))) driver.execute_script("arguments[0].click();", rmv_prd_btn) rmv_prd_cnfrm_popup_btn = wait.until( ec.element_to_be_clickable( (By.XPATH, ConfigReader.fetchElement( 'Cart', 'remove_confirmation_button_XPATH')))) driver.execute_script("arguments[0].click();", rmv_prd_cnfrm_popup_btn) driver.refresh()
def selectionOfProduct(self, category, brand): url = driver.current_url if (not brand in url): ProductSelection(driver).clearFilter(category) ProductSelection(driver).selectBrand(brand) print(brand + ' brand is selected') else: pass products = wait.until( ec.visibility_of_all_elements_located( (By.XPATH, ConfigReader.fetchElement('SearchProduct', 'product_selection_XPATH')))) driver.execute_script("arguments[0].click();", products[0])
def clearFilter(self, category): all_windows = driver.window_handles for win in all_windows: driver.switch_to.window(win) URL_window_handle = driver.current_url if category in URL_window_handle: clear_filter = wait.until( ec.element_to_be_clickable( (By.XPATH, ConfigReader.fetchElement( 'SearchProduct', 'filter_clear_textbox_XPATH')))) driver.execute_script("arguments[0].click();", clear_filter) driver.refresh() url_filter = driver.current_url if (('facets.brand') in url_filter): driver.execute_script("arguments[0].click();", clear_filter) else: pass
def cartCheckOut(self): wait.until( ec.element_to_be_clickable( (By.XPATH, ConfigReader.fetchElement( 'Cart', 'checkout_webelement_XPATH')))).click()
def loginWindow(self): driver.find_element( By.XPATH, ConfigReader.fetchElement('Login', 'loginwindow_popup_XPATH')).click()
import openpyxl from Flipkart.library import ConfigReader path = ConfigReader.readConfigData('Details', 'File_location') sheet_name = ConfigReader.readConfigData('Details', 'Sheet_Name') def getRowCount(): workbook = openpyxl.load_workbook(path) sheet = workbook.get_sheet_by_name(sheet_name) return (sheet.max_row) def getColumnCount(): workbook = openpyxl.load_workbook(path) sheet = workbook.get_sheet_by_name(sheet_name) return (sheet.max_column) def readData(row_number, column_number): workbook = openpyxl.load_workbook(path) sheet = workbook.get_sheet_by_name(sheet_name) return (sheet.cell(row=row_number, column=column_number).value)