class Test_SearchCustomerByEmail_004: baseURL = ReadConfig.get_app_url() username = ReadConfig.get_username() password = ReadConfig.get_password() logger = LogGen.log_gen() @pytest.mark.regression def test_search_customer_by_email(self, setup): self.logger.info("***** SearchCustomerByEmail_004 *****") self.driver = setup self.driver.get(self.baseURL) self.driver.maximize_window() self.lp = LoginPage(self.driver) self.lp.set_username(self.username) self.lp.set_password(self.password) self.lp.click_login() self.logger.info("***** Login successful *****") self.logger.info("***** Starting Search Customer By Email *****") self.add_cst = AddCustomer(self.driver) self.add_cst.click_on_customers_menu() self.add_cst.click_on_customers_menu_item() self.logger.info("***** Searching customer by emailID *****") search_cst = SearchCustomer(self.driver) search_cst.set_email("*****@*****.**") search_cst.click_search() time.sleep(5) status = search_cst.search_customer_by_email( "*****@*****.**") self.driver.close() self.logger.info("***** TC_SearchCustomerByEmail_004 Finished *****") assert status is True
class Util(object): log = logger = LogGen.loggen() def sleep(self, sec, info=""): """ Put the program to wait for the specified amount of time """ if info is not None: self.log.info("Wait :: '" + str(sec) + "' seconds for " + info) try: time.sleep(sec) except InterruptedError: traceback.print_stack() def getAlphaNumeric(self, length, type='letters'): """ Get random string of characters Parameters: length: Length of string, number of characters string should have type: Type of characters string should have. Default is letters Provide lower/upper/digits for different types """ alpha_num = '' if type == 'lower': case = string.ascii_lowercase elif type == 'upper': case = string.ascii_uppercase
class Test_003_AddCustomer: base_url = ReadConfig.get_app_url() username = ReadConfig.get_username() password = ReadConfig.get_password() logger = LogGen.log_gen() @pytest.mark.regression def test_add_customer(self, setup): self.logger.info("***** Test_003_AddCustomer *****") self.driver = setup self.driver.get(self.base_url) self.driver.maximize_window() self.lp = LoginPage(self.driver) self.lp.set_username(self.username) self.lp.set_password(self.password) self.lp.click_login() self.logger.info("***** Login successful *****") self.logger.info("***** Starting Add Customer Test *****") self.add_cust = AddCustomer(self.driver) self.add_cust.click_on_customers_menu() self.add_cust.click_on_customers_menu_item() self.add_cust.click_on_add_new() self.logger.info("***** Providing customer info *****") self.email = random_generator() + "@gmail.com" self.add_cust.set_email(self.email) self.add_cust.set_password("test123") self.add_cust.set_customer_roles("Guests") self.add_cust.set_manager_of_vendor("Vendor 2") self.add_cust.set_gender("Male") self.add_cust.set_first_name("Vlad") self.add_cust.set_last_name("Nire") self.add_cust.set_dob("7/05/1989") # Format: D / MM / YYYY self.add_cust.set_company_name("QA") self.add_cust.set_admin_content("This is for testing.") self.add_cust.click_on_save() self.logger.info("***** Saving customer info *****") self.logger.info("***** Add customer validation started *****") self.msg = self.driver.find_element_by_tag_name("body").text #print(self.msg) if 'customer has been added successfully.' in self.msg: self.logger.info("***** Add customer Test Passed *****") assert True else: self.driver.save_screenshot(".\\Screenshots\\" + "test_add_customer_scr.png") self.logger.error("***** Add customer Test Failed *****") assert False self.driver.close() self.logger.info("***** Ending Add customer test *****")
class Test_002_DTT_Login: base_url = ReadConfig.get_app_url() path = ".\\test_data\\login_data.xlsx" logger = LogGen.log_gen() @pytest.mark.regression def test_login_dtt(self, setup): self.logger.info("***** Test_002_DTT_Login *****") self.logger.info("***** Verifying Login DTT *****") self.driver = setup self.driver.get(self.base_url) self.lp = LoginPage(self.driver) # Get data from excel file self.rows = excel_utils.get_row_count(self.path, 'Sheet1') print(f"Number of rows in Excel: {self.rows}") status_list = [] for r in range(2, self.rows + 1): self.username = excel_utils.read_data(self.path, 'Sheet1', r, 1) self.password = excel_utils.read_data(self.path, 'Sheet1', r, 2) self.expected = excel_utils.read_data(self.path, 'Sheet1', r, 3) self.lp.set_username(self.username) self.lp.set_password(self.password) self.lp.click_login() time.sleep(5) actual_title = self.driver.title exp_title = "Dashboard / nopCommerce administration" if actual_title == exp_title: if self.expected == "Passed": self.logger.info("***** Test Passed *****") status_list.append("Passed") elif self.expected == "Failed": self.logger.info("***** Test Failed *****") status_list.append("Failed") self.lp.click_logout() elif actual_title != exp_title: if self.expected == "Passed": self.logger.info("***** Test Failed *****") status_list.append("Failed") elif self.expected == "Failed": self.logger.info("***** Test Passed *****") status_list.append("Passed") if "Failed" in status_list: self.logger.info("***** Login DTT Failed *****") self.driver.close() assert False else: self.logger.info("***** Login DTT Passed *****") self.driver.close() assert True self.logger.info("***** End of Login DTT Test *****")
class TestLoginDDT_001: baseURL=ReadConfig.get_base_URL() logger=LogGen.log_gen() Datapath="./testdata/TestDataManagerLogin.xlsx" def test_login_ddt(self,setup): self.logger.info("****** TestLoginDDT_001 started ******") self.logger.info("****** verifying login ddt test ******") self.driver=setup self.driver.get(self.baseURL) self.lp=LoginPage(self.driver) self.rows=XLUties.get_row_count(self.Datapath,"Sheet1") print("Number of rows in Excel Data ",self.rows) lst_status=[] for r in range(2,self.rows+1): self.username=XLUties.read_data(self.Datapath,"Sheet1",r,1) self.password=XLUties.read_data(self.Datapath,"Sheet1",r,2) self.exp=XLUties.read_data(self.Datapath, "Sheet1",r,3) self.lp.set_user_id(self.username) self.lp.set_password(self.password) self.lp.click_on_login() actual_title=self.driver.title expected_title="Guru99 Bank Manager HomePage" if actual_title==expected_title: if self.exp=="Pass": self.logger.info("------Passed------") self.lp.click_on_logout() self.driver.switch_to.alert.accept() lst_status.append("Pass") elif self.exp=="Fail": self.logger.info("------Failed------") self.lp.click_on_logout() time.sleep(5) self.driver.switch_to.alertaccept() lst_status.append("Fail") elif actual_title!=expected_title: if self.exp=="Pass": self.logger.info("------Failed------") lst_status.append("Fail") elif self.exp=="Fail": self.logger.info("------Passed------") lst_status.append("Pass") if "Fail" not in lst_status: self.logger.info("****** TestLoginDDT_001 Passed ******") self.driver.close() assert True else: self.logger.info("****** TestLoginDDT_001 Failed ******") self.driver.close() assert False self.logger.info("****** End of login DDT test ******") self.logger.info("**************** complete test login DDT ********************")
class Login_page(BasePage): textbox_username_id = "Email" textbox_password_id = "Password" button_login_xpath = "//input[@class='button-1 login-button']" link_logout_linktext = "Logout" text_invalidlogin_xpath = "//div[contains(text(),'Login was unsuccessful. Please correct the errors and try again.')]" text_usernametext_xpath = "//li[contains(text(),'John Smith')]" logger = LogGen.loggen() def clear_username(self): self.driver.find_element_by_id(self.textbox_username_id).clear() def clear_password(self): self.driver.find_element_by_id(self.textbox_password_id).clear() def enterEmail(self, username): self.sendKeys(username, self.textbox_username_id) def enterPassword(self, password): self.sendKeys(password, self.textbox_password_id) def clickLoginButton(self): self.elementClick(self.button_login_xpath, locatorType="xpath") def clickLogoutLink(self): self.elementClick(self.link_logout_linktext, locatorType="link") def login(self, username="", password=""): self.clear_username() self.clear_password() self.enterEmail(username) self.enterPassword(password) self.clickLoginButton() def logout(self): self.clickLogoutLink() def verify_login_failed(self): resp = self.isElementPresent(self.text_invalidlogin_xpath, locatorType="xpath") return resp def verify_login_successful(self): result = self.isElementPresent(self.text_usernametext_xpath, locatorType="xpath") return result def verifyTitle(self): return self.verifyPageTitle("Dashboard / nopCommerce administration")
class TestStatus(SeleniumDriver): logger = LogGen.loggen() def __init__(self, driver): super().__init__(driver) self.resultlist = [] def set_result(self, result, result_message): try: if result is not None: if result: self.resultlist.append("PASS") self.logger.info("### Verification Successful ::" + result_message) else: self.resultlist.append("FAIL") self.logger.info("### Verification Failed ::" + result_message) self.screenShot(result_message) else: self.resultlist.append("FAIL") self.logger.error("### Verification Failed ::" + result_message) self.screenShot(result_message) except: self.resultlist.append("FAIL") self.logger.error("### Exception Occurred !!!") self.screenShot(result_message) def mark(self, result, result_message): """ Mark the result of the verification point in a test case """ self.set_result(result, result_message) def final_mark(self, testname, result, result_message): """ Mark the final result of the verification point in a test case This needs to be called at least once in a test case This should be final test status of the test case """ self.set_result(result, result_message) if "FAIL" in self.resultlist: self.logger.error(testname + " ### TEST FAILED") self.resultlist.clear() assert True == False else: self.logger.error(testname + " ### TEST PASSED") self.resultlist.clear() assert True == True
class Test_001_Login: base_url = ReadConfig.get_app_url() username = ReadConfig.get_username() password = ReadConfig.get_password() logger = LogGen.log_gen() @pytest.mark.sanity @pytest.mark.regression def test_home_page_title(self, setup): self.logger.info("***** Test_001_Login *****") self.logger.info("***** Verifying Home Page Title *****") self.driver = setup self.driver.get(self.base_url) actual_title = self.driver.title if actual_title == "Your store. Login": self.driver.close() self.logger.info("***** Home Page Title Passed *****") assert True else: self.driver.save_screenshot(".\\screenshots\\" + "test_home_page_title.png") self.driver.close() self.logger.error("***** Home Page Title Failed *****") assert False @pytest.mark.sanity @pytest.mark.regression def test_login(self, setup): self.logger.info("***** Test_002_Login *****") self.logger.info("***** Verifying Login *****") self.driver = setup self.driver.get(self.base_url) self.lp = LoginPage(self.driver) self.lp.set_username(self.username) self.lp.set_password(self.password) self.lp.click_login() actual_title = self.driver.title if actual_title == "Dashboard / nopCommerce administration": self.logger.info("***** Login Passed *****") self.driver.close() assert True else: self.driver.save_screenshot(".\\screenshots\\" + "test_login.png") self.logger.error("***** Login Failed *****") self.driver.close() assert False
class Test_001_Login: baseURL = ReadConfig.get_application_url() username = ReadConfig.get_username() password = ReadConfig.get_password() logger = LogGen.loggen() path_to_screenshots = os.path.join('.', 'screenshots') def test_home_page_title(self, setup): self.logger.info("***Test_001_Login***") self.logger.info("***Verifying Home Page Title***") self.driver = setup self.driver.get(self.baseURL) actual_title = self.driver.title if actual_title == "Your store. Login": assert True self.logger.info("*** Home page title test is passed ***") self.driver.close() else: path_to_failed_home_page_title_test = os.path.join(self.path_to_screenshots, 'test_home_page_title_failed.png') self.driver.save_screenshot(path_to_failed_home_page_title_test) self.logger.error("*** Home page title test is failed ***") self.driver.close() assert False def test_login(self, setup): self.logger.info("***Verifying Login test***") self.driver = setup self.driver.get(self.baseURL) self.lp = LoginPage(self.driver) self.lp.set_user_name(self.username) self.lp.set_password(self.password) self.lp.click_login_button() actual_title = self.driver.title if actual_title == "Dashboard / nopCommerce administration": self.logger.info("*** Login test is passed ***") self.driver.close() assert True else: path_to_failed_login_test = os.path.join(self.path_to_screenshots, 'test_login_failed.png') self.driver.save_screenshot(path_to_failed_login_test) self.logger.error("*** Login test is failed ***") self.driver.close() assert False
class SeleniumDriver(): logger = LogGen.loggen() def __init__(self, driver): self.driver = driver def getTitle(self): return self.driver.title def getByType(self, locatorType): locatorType = locatorType.lower() if locatorType == "id": return By.ID elif locatorType == "name": return By.NAME elif locatorType == "xpath": return By.XPATH elif locatorType == "css": return By.CSS_SELECTOR elif locatorType == "class": return By.CLASS_NAME elif locatorType == "link": return By.LINK_TEXT else: self.logger.info("Locator type " + locatorType + " not correct/supported") return False def getElement(self, locator, locatorType="id"): element = None try: locatorType = locatorType.lower() byType = self.getByType(locatorType) element = self.driver.find_element(byType, locator) self.logger.info("Element Found with locator: " + locator + " and locatorType: " + locatorType) except: self.logger.info("Element not found with locator: " + locator + " and locatorType: " + locatorType) return element def elementClick(self, locator, locatorType="id"): try: element = self.getElement(locator, locatorType) element.click() self.logger.info("Clicked on element with locator: " + locator + " locatorType: " + locatorType) except: self.logger.info("Cannot click on the element with locator: " + locator + " locatorType: " + locatorType) print_stack() def sendKeys(self, data, locator, locatorType="id"): try: element = self.getElement(locator, locatorType) element.send_keys(data) self.logger.info("Sent data on element with locator: " + locator + " locatorType: " + locatorType) except: self.logger.info("Cannot send data on the element with locator: " + locator + " locatorType: " + locatorType) print_stack() def isElementPresent(self, locator, locatorType="id"): try: element = self.getElement(locator, locatorType) if element is not None: self.logger.info("Element Found") return True else: self.logger.info("Element not found") return False except: self.logger.info("Element not found") return False def elementPresenceCheck(self, locator, byType): try: elementList = self.driver.find_elements(byType, locator) if len(elementList) > 0: self.logger.info("Element Found") return True else: self.logger.info("Element not found") return False except: self.logger.info("Element not found") return False def waitForElement(self, locator, locatorType="id", timeout=10, pollFrequency=0.5): element = None try: byType = self.getByType(locatorType) self.logger.info("Waiting for maximum :: " + str(timeout) + " :: seconds for element to be clickable") wait = WebDriverWait(self.driver, timeout, poll_frequency=pollFrequency, ignored_exceptions=[ NoSuchElementException, ElementNotVisibleException, ElementNotSelectableException ]) element = wait.until(EC.element_to_be_clickable((byType, locator))) self.logger.info("Element appeared on the web page") except: self.logger.info("Element not appeared on the web page") print_stack() return element def screenShot(self, resultMessage): """ Takes screenshot of the current open web page """ fileName = resultMessage + "." + str(round( time.time() * 1000)) + ".png" screenshotDirectory = "../screenshots/" relativeFileName = screenshotDirectory + fileName currentDirectory = os.path.dirname(__file__) destinationFile = os.path.join(currentDirectory, relativeFileName) destinationDirectory = os.path.join(currentDirectory, screenshotDirectory) try: if not os.path.exists(destinationDirectory): os.makedirs(destinationDirectory) self.driver.save_screenshot(destinationFile) self.logger.info("Screenshot save to directory: " + destinationFile) except: self.logger.error("### Exception Occurred when taking screenshot") print_stack()
class AddCustomerPage: link_text_Add_new_customer_link="New Customer" xpath_customer_name_input_box="//input[@name='name']" xpath_gender_male="//input[@value='m']" xpath_gender_female="//input[@value='f']" xpath_date_of_birth_input_box="//input[@id='dob']" xpath_address_input_box="//textarea[@name='addr']" xpath_city_input_box="//input[@name='city']" xpath_state_input_box="//input[@name='state']" xpath_pin_no_input_box="//input[@name='pinno']" xpath_mobile_number_input_box="//input[@name='telephoneno']" xpath_email_id_input_box="//input[@name='emailid']" xpath_password_input_box="//input[@name='password']" xpath_submit_button="//input[@value='Submit']" xpath_reset_button="//input[@value='Reset']" logger=LogGen.log_gen() def __init__(self,driver): self.driver=driver self.driver.implicitly_wait(10) def click_on_add_new_customer_link(self): self.driver.find_element_by_link_text(self.link_text_Add_new_customer_link).click() def set_customer_name(self,name): self.driver.find_element_by_xpath(self.xpath_customer_name_input_box).clear() self.driver.find_element_by_xpath(self.xpath_customer_name_input_box).send_keys(name) def click_on_gender_male(self,gender_type): if gender_type=="male": self.driver.find_element_by_xpath(self.xpath_gender_male).click() elif gender_type=="female": self.driver.find_element_by_xpath(self.xpath_gender_female).click() else: self.logger.error("Invalid gender type") def set_date_of_birth(self,dateofbirth): self.driver.find_element_by_xpath(self.xpath_date_of_birth_input_box).clear() self.driver.find_element_by_xpath(self.xpath_date_of_birth_input_box).send_keys(dateofbirth) def set_address(self,address): self.driver.find_element_by_xpath(self.xpath_address_input_box).clear() self.driver.find_element_by_xpath(self.xpath_address_input_box).send_keys(address) def set_city(self,city): self.driver.find_element_by_xpath(self.xpath_city_input_box).clear() self.driver.find_element_by_xpath(self.xpath_city_input_box).send_keys(city) def set_state(self,state): self.driver.find_element_by_xpath(self.xpath_state_input_box).clear() self.driver.find_element_by_xpath(self.xpath_state_input_box).send_keys(state) def set_PIN_number(self,pinno): self.driver.find_element_by_xpath(self.xpath_pin_no_input_box).clear() self.driver.find_element_by_xpath(self.xpath_pin_no_input_box).send_keys(pinno) def set_mobile_number(self,mobile_number): self.driver.find_element_by_xpath(self.xpath_mobile_number_input_box).clear() self.driver.find_element_by_xpath(self.xpath_mobile_number_input_box).send_keys(mobile_number) def set_email_id(self,emailid): self.driver.find_element_by_xpath(self.xpath_email_id_input_box).clear() self.driver.find_element_by_xpath(self.xpath_email_id_input_box).send_keys(emailid) def set_password(self,password): self.driver.find_element_by_xpath(self.xpath_password_input_box).clear() self.driver.find_element_by_xpath(self.xpath_password_input_box).send_keys(password) def click_on_submit_button(self): self.driver.find_element_by_xpath(self.xpath_submit_button).click() def click_on_reset_button(self): self.driver.find_element_by_xpath(self.xpath_reset_button).click()
class Test_001_Search: logger = LogGen.loggen() # TODO сделать логгер в режиме добавления записей logger.info("Test_001_Search") path_to_screenshots = os.path.join('.', 'screenshots') # TODO добавить скриншоты yandex_search_URL = ReadConfig.get_yandex_search_url() def test_check_search_box(self, setup): self.logger.info("Checking if a search field exists") self.driver = setup self.driver.get(self.yandex_search_URL) self.yp = YandexSearchPage(self.driver) try: self.yp.find_search_box() self.logger.info( f"Test passed: Search field found by {self.yp.search_box_locator}" ) time.sleep(2) except TimeoutException: self.logger.error( f"Test failed: Search field not found by {self.yp.search_box_locator} for {self.yp.delay} seconds" ) finally: self.driver.quit() self.logger.info("---------------") def test_suggests_in_search_box(self, setup): self.logger.info("Checking suggests in search field") self.driver = setup self.driver.get(self.yandex_search_URL) self.yp = YandexSearchPage(self.driver) try: self.yp.set_text_to_search_box('Тензор') self.yp.find_suggest_box() self.yp.send_enter_to_search_box() request_results = self.yp.get_request_results() if request_results: self.search_href_in_list_of_links( request_results=request_results, link_to_search=r"https://tensor.ru/", number_results=5) else: self.logger.error( "Test failed: There is no links in result of search") except TimeoutException: # TODO добавить отработку различных ненайденок self.logger.error( f"Test failed: Suggest field not found by {self.yp.suggest_box_locator} for {self.yp.delay} seconds" ) finally: self.driver.quit() self.logger.info("---------------") def search_href_in_list_of_links(self, request_results, link_to_search: str, number_results: int): list_of_links = [] for element in request_results: element_with_link = element.find_element_by_tag_name('a') link = element_with_link.get_attribute("href") list_of_links.append(link) if link_to_search in list_of_links: index = list_of_links.index(link_to_search) + 1 if index <= number_results: self.logger.info( f"Test passed: {link_to_search} find in {index} request position" ) else: self.logger.error( f"Test failed: {link_to_search} find, but in {index} request position" ) else: self.logger.error( f"Test failed: {link_to_search} did not find in request")
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as ec from utilities.custom_logger import LogGen log = LogGen.log_gen() class SeleniumBase: def __init__(self, driver): self.driver = driver def identify_element(self, locater_type, address): element = None wait = WebDriverWait(self.driver, 20, 1) if locater_type == "id": locater = By.ID, address condition = ec.presence_of_element_located(locater) element = wait.until(condition) return element elif locater_type == "name": locater = By.NAME, address condition = ec.presence_of_element_located(locater) element = wait.until(condition) return element elif locater_type == "classname": locater = By.CLASS_NAME, address condition = ec.presence_of_element_located(locater) element = wait.until(condition) return element
class Test_Login_001: base_url = ReadConfig.get_base_URL() user_name = ReadConfig.get_user_name() password = ReadConfig.get_password() log = LogGen.log_gen() @pytest.mark.smoke def test_open_browser(self, setup): self.log.info("------Open browser test------") self.driver = setup self.driver.get(self.base_url) actual_url = self.driver.current_url if actual_url == "http://demo.guru99.com/V4/": assert True self.log.info("------ open browser test passed ------") self.driver.close() else: self.driver.save_screenshot("../screenshots/" + 'test_homepage_title.png') self.driver.close() self.log.error("------ open browser test failed ------") assert False @pytest.mark.smoke def test_home_page_title(self, setup): self.log.info("------ test login 001 -------") self.log.info("------ verifying homepage title ------") self.driver = setup self.driver.get(self.base_url) time.sleep(5) actual_title = self.driver.title if actual_title == "Guru99 Bank Home Page": assert True self.driver.close() self.log.info("------ home page title test is passed ------") else: self.driver.save_screenshot("../screenshots/" + 'test_homepage_title.png') self.driver.close() self.log.error("------ home page title test is failed ------") assert False @pytest.mark.sanity @pytest.mark.regression def test_login(self, setup): self.log.info("------ verifyin login test ------") self.driver = setup self.driver.get(self.base_url) self.log.info("--- application launched...") self.lp = LoginPage(self.driver) self.lp.set_user_id(self.user_name) self.log.info("--- user id Entered : " + self.user_name) self.lp.set_password(self.password) self.log.info("--- password Entered : " + self.password) self.lp.click_on_login() self.log.info("--- clicked on login") self.msg = self.driver.find_element_by_xpath("//body").text #if self.msg == "Manger Id : mngr285385": if "Manger Id :" + " " + self.user_name in self.msg: assert True self.log.info("------ login test is passed ------") self.driver.close() else: self.driver.save_screenshot(".\\screenshots\\" + "test_login.png") self.driver.close() self.log.error("------ login test is failed") assert False
class Test_002_Pictures: logger = LogGen.loggen() logger.info("Test_002_Pictures") path_to_screenshots = os.path.join('.', 'screenshots') # TODO добавить скриншоты yandex_search_URL = ReadConfig.get_yandex_search_url() yandex_pictures_URL = ReadConfig.get_yandex_pictures_url() def test_yandex_pictures_section_exist(self, setup): self.logger.info("Checking if a Pictures section exists") self.driver = setup self.driver.get(self.yandex_search_URL) self.yp = YandexSearchPage(self.driver) try: self.yp.find_yandex_pictures_section() self.logger.info( f"Test passed: Pictures section found by {self.yp.pictures_section_locator}" ) except TimeoutException: self.logger.error( f"Test failed: Pictures section not found by {self.yp.pictures_section_locator} for {self.yp.delay} seconds" ) finally: self.driver.quit() self.logger.info("---------------") def test_yandex_pictures_page_exist(self, setup): self.logger.info("Checking yandex pictures page exist") self.driver = setup self.driver.get(self.yandex_search_URL) self.yp = YandexSearchPage(self.driver) try: pictures_section = self.yp.find_yandex_pictures_section() pictures_section.click() self.yp.find_yandex_pictures_title() self.logger.info( f"Test passed: successful transition to the https://yandex.ru/images/" ) except TimeoutException: self.logger.error( f"Test failed: can't find picture title by {self.yp.pictures_title_locator} for {self.yp.delay} seconds" ) assert False finally: self.driver.quit() self.logger.info("---------------") def test_yandex_pictures_first_category(self, setup): self.logger.info("Checking the correctness of image search") self.driver = setup self.driver.get(self.yandex_pictures_URL) self.yp = YandexPicturesPage(self.driver) try: first_popular_request = self.yp.find_first_popular_request() first_popular_request.click() expected_text = first_popular_request.text picture_search_box = self.yp.find_picture_search_box() actual_text = picture_search_box.get_attribute("value") if expected_text == actual_text: self.logger.info( f"Test passed: the text of the first category matches with the search text" ) else: self.logger.error( f"Test failed: the text of the first category does not match the search text" ) except TimeoutException: self.logger.error( f"Test failed: can't find element {self.yp.pictures_title_locator} for {self.yp.delay} seconds" ) assert False finally: self.driver.quit() self.logger.info("---------------")
class Test_002_DDT_Login: baseURL = ReadConfig.get_application_url() path_to_excel_data = os.path.join('.', 'test_data', 'login_data.xlsx') logger = LogGen.loggen() def test_login_ddt(self, setup): self.logger.info("***Test_002_DDT_Login***") self.logger.info("***Verifying Login DDT test***") self.driver = setup self.driver.get(self.baseURL) self.lp = LoginPage(self.driver) self.rows = excel_utils.get_row_count(self.path_to_excel_data, 'Лист1') print('Number of Rows i a Excel: ', self.rows) status_list = [] for row in range(2, self.rows + 1): self.user = excel_utils.read_data(self.path_to_excel_data, 'Лист1', row, 1) self.password = excel_utils.read_data(self.path_to_excel_data, 'Лист1', row, 2) self.exp = excel_utils.read_data(self.path_to_excel_data, 'Лист1', row, 3) self.lp.set_user_name(self.user) self.lp.set_password(self.password) self.lp.click_login_button() time.sleep(2) actual_title = self.driver.title expected_title = "Dashboard / nopCommerce administration" if actual_title == expected_title: if self.exp == 'Pass': self.logger.info('*** Passed ***') self.lp.click_logout_button() status_list.append('Pass') elif self.exp == 'Fail': self.logger.error('*** Failed ***') self.lp.click_logout_button() status_list.append('Fail') elif actual_title != expected_title: if self.exp == 'Pass': self.logger.error('*** Failed ***') status_list.append('Fail') elif self.exp == 'Fail': self.logger.info('*** Passed ***') status_list.append('Pass') if 'Fail' not in status_list: self.logger.info('*** Login DDT test is passed ***') self.driver.close() assert True else: self.logger.error('*** Login DDT test is failed ***') self.driver.close() assert False self.logger.info('*** End of Login DDT Test ***') self.logger.info('\n')