class APIUtilily: """ This class includes basic reusable api utility helpers. """ log = log_utils.custom_logger(logging.INFO) def get_api_response(self, endpoint): """ This method is used to return the api response :return: This method return the api response """ res = None try: response = requests.get(endpoint) response.raise_for_status() if response.status_code == 200: res = response else: res = None except HTTPError as http_err: self.log.error(f'HTTP Error occurred.\n{http_err}') print_stack() except Exception as ex: self.log.error(f'Failed to get the response, other error occurred.\n{ex}') print_stack() return res
class ExecutionStatus(UIHelpers): log = log_utils.custom_logger(logging.INFO) def __init__(self, driver): super().__init__(driver) self.result_list = [] def set_result(self, result, test_name): try: if result is not None: if result: self.result_list.append("PASS") self.log.info("### STEP SUCCESSFUL :: " + test_name) else: image = self.take_screenshots(test_name) error = "### STEP FAILED :: " + test_name self.result_list.append("FAIL") self.log.error(error) allure.attach.file( image, attachment_type=allure.attachment_type.PNG) else: image = self.take_screenshots(test_name) error = "### STEP FAILED :: " + test_name self.result_list.append("FAIL") self.log.error(error) allure.attach.file(image, attachment_type=allure.attachment_type.PNG) except Exception as ex: image = self.take_screenshots(test_name) self.result_list.append("FAIL") self.log.error("### EXCEPTION OCCURRED :: {}".format(ex)) allure.attach.file(image, attachment_type=allure.attachment_type.PNG) def mark(self, test_step, result): self.set_result(result=result, test_name=test_step) def mark_final(self, result, test_step): self.set_result(result, test_step) # noinspection PyBroadException try: if "FAIL" in self.result_list: self.result_list.clear() assert True is False else: self.result_list.clear() assert True is True, "### TEST SUCCESSFUL :: " + test_step except Exception: pytest.fail("### TEST FAILED :: " + test_step, pytrace=False)
class DataReader: """ This class includes basic reusable data helpers. """ log = log_utils.custom_logger(logging.INFO) config = ConfigUtility() def __init__(self): self.cur_path = os.path.abspath(os.path.dirname(__file__)) def load_test_data(self): """ This methods is used for loading excel file data for UI cases :return: it returns excel records """ records = None # noinspection PyBroadException prop = self.config.load_properties_file() base_test_data = prop.get('RAFT', 'base_test_data') ui_file_path = os.path.join( self.cur_path, r"../TestData/{}.xlsx".format(base_test_data)) try: if ui_file_path is not None: records = exc.iget_records(file_name=ui_file_path) except Exception as ex: self.log.error("Failed to load test data.\n{}".format(ex)) return records def get_data(self, tc_name, column_name): """ This method is used for returning column data specific to ui test case name :param tc_name: it takes test case name as input parameter :param column_name: it takes the name of the column for which value has to be returned :return: """ value = None excel_records = self.load_test_data() # noinspection PyBroadException try: if excel_records is not None: for record in excel_records: if record['TC_Name'] == tc_name: value = record[column_name] break else: continue except Exception as ex: self.log.error("Failed to get test data.\n{}".format(ex)) return value
class ConfigUtility: """ This class includes basic reusable config_helpers. """ log = log_utils.custom_logger(logging.INFO) def __init__(self): self.cur_path = os.path.abspath(os.path.dirname(__file__)) self.config_path = os.path.join(self.cur_path, r"../ConfigFiles/config.ini") def load_properties_file(self): """ This method loads the properties/ini file :return: this method returns config reader instance. """ config = None try: # noinspection PyBroadException config = ConfigParser() config.read(self.config_path) except Exception as ex: self.log.error("Failed to load ini/properties file.", ex) print_stack() return config def change_properties_file(self, section, property_name, property_value): """ This method is used to change the property value :param section: property section in ini file :param property_name: property name to change :param property_value: property value to set :return: it returns boolean value for successful change property operation """ try: config = self.load_properties_file() config[section][property_name] = property_value with open(self.config_path, 'w') as configfile: config.write(configfile) time.sleep(1) return True except Exception as ex: self.log.error("Failed to change ini/properties file.", ex) print_stack() return False
class DriverFactory: """ This class contains the reusable methods for getting the driver instances """ log = custom_logger(logging.INFO) config = ConfigUtility() def __init__(self, platform): self.platform = platform self.cur_path = os.path.abspath(os.path.dirname(__file__)) self.prop = self.config.load_properties_file() def get_driver_instance(self): if self.platform == "android": app_location = os.path.join( self.cur_path, r"../MobileApp/", self.prop.get('Cap_Android', 'app_name')) desired_caps = { 'automationName': self.prop.get('Cap_Android', 'automation_name'), 'deviceName': self.prop.get('Cap_Android', 'device_name'), 'udid': self.prop.get('Cap_Android', 'ud_id'), 'platformName': 'android', 'platformVersion': self.prop.get('Cap_Android', 'platform_version'), 'appPackage': self.prop.get('Cap_Android', 'app_package'), 'appActivity': self.prop.get('Cap_Android', 'app_activity'), 'app': app_location, 'noReset': self.prop.get('Cap_Android', 'no_reset'), 'autoGrantPermissions': self.prop.get('Cap_Android', 'auto_grant_permissions') } driver = webdriver.Remote(command_executor=self.prop.get( 'Grid', 'appium_server'), desired_capabilities=desired_caps) return driver elif self.platform == "ios": pass
class BaseAPI: """This class defines the method and element identifications for main page.""" log = log_utils.custom_logger(logging.INFO) def __init__(self): self.config = ConfigUtility() self.api = APIUtilily() self.prop = self.config.load_properties_file() # self.log = log_utils.custom_logger(logging.INFO) def verify_users(self): """ This function is used to verify users :return: this function returns boolean status of element located """ result = False res = self.api.get_api_response( endpoint=self.prop.get('RAFT', 'base_api')) if res is not None: res = res.json() self.log.info(res) result = True return result def verify_valid_user(self, email, first_name, last_name): """ This function is used to verify email and username of a particular user :param last_name: user first name :param first_name: user last name :param email: user email address :return: status of the valid user """ result = False res = self.api.get_api_response( endpoint=self.prop.get('RAFT', 'base_api')) if res is not None: res = res.json() self.log.info(res) if email == res['data'][0]['email'] and \ first_name == res['data'][0]['first_name'] and \ last_name == res['data'][0]['last_name']: result = True return result
class DataReader: log = log_utils.custom_logger(logging.INFO) config = ConfigUtility() def __init__(self): self.cur_path = os.path.abspath(os.path.dirname(__file__)) def load_test_data(self): records = None prop = self.config.load_properties_file() base_test_data = prop.get('RAFT', 'test_data') ui_file_path = os.path.join( self.cur_path, r"../TestData/{}.xlsx".format(base_test_data)) try: if ui_file_path is not None: records = exc.iget_records(file_name=ui_file_path) except Exception as ex: self.log.error("Failed to load test data.", ex) return records def get_data(self, tc_name, column_name): value = None excel_records = self.load_test_data() try: if excel_records is not None: for record in excel_records: if record['TC_Name'] == tc_name: value = record[column_name] break else: continue except Exception as ex: self.log.error("Failed to get test data.", ex) return value
class ConfigUtility: log = log_utils.custom_logger(logging.INFO) def __init__(self): self.cur_path = os.path.abspath(os.path.dirname(__file__)) self.config_path = os.path.join(self.cur_path, r"../ConfigFiles/config.ini") def load_properties_file(self): config = None try: # noinspection PyBroadException config = ConfigParser() config.read(self.config_path) except Exception as ex: self.log.error("Failed to load ini/properties file.", ex) return config def change_properties_file(self, section, property_name, property_value): flag = False try: config = self.load_properties_file() config[section][property_name] = property_value with open(self.config_path, 'w') as configfile: config.write(configfile) time.sleep(1) flag = True except Exception as ex: self.log.error("Failed to change ini/properties file.", ex) return flag
class DriverFactory: """ This class contains the reusable methods for getting the driver instances """ log = custom_logger(logging.INFO) config = ConfigUtility() def __init__(self, browser, platform, environment, url=""): self.platform = platform self.browser = browser self.environment = environment self.url = url self.cur_path = os.path.abspath(os.path.dirname(__file__)) self.prop = self.config.load_properties_file() def get_driver_instance(self): if self.browser == "chrome": chrome_capabilities = webdriver.DesiredCapabilities.CHROME chrome_capabilities['platform'] = self.platform chrome_capabilities['browserName'] = 'chrome' chrome_capabilities['javascriptEnabled'] = True options = chromeOptions() options.add_argument("--disable-infobars") options.add_argument("--disable-extensions") options.add_argument("--disable-notifications") options.add_argument("--start-maximized") options.add_argument("--disable-web-security") options.add_argument("--no-proxy-server") options.add_argument("--enable-automation") options.add_argument("--disable-save-password-bubble") options.add_experimental_option('prefs', {'credentials_enable_service': False, 'profile': {'password_manager_enabled': False}}) driver = webdriver.Remote( command_executor=self.prop.get('GRID', 'GRID_SERVER'), desired_capabilities=chrome_capabilities, options=options) elif self.browser == "firefox": firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX firefox_capabilities['platform'] = self.platform firefox_capabilities['browserName'] = 'firefox' firefox_capabilities['javascriptEnabled'] = True firefox_capabilities['marionette'] = True options = ffOptions() options.log.level = 'trace' driver = webdriver.Remote(command_executor=self.prop.get('GRID', 'GRID_SERVER'), desired_capabilities=firefox_capabilities, options=options) elif self.browser == "safari": safari_capabilities = webdriver.DesiredCapabilities.SAFARI safari_capabilities['platform'] = self.platform safari_capabilities['browserName'] = 'safari' safari_capabilities['javascriptEnabled'] = True driver = webdriver.Remote( command_executor=self.prop.get('GRID', 'GRID_SERVER'), desired_capabilities=safari_capabilities) elif self.browser == "edge": edge_capabilities = webdriver.DesiredCapabilities.EDGE edge_capabilities['platform'] = self.platform edge_capabilities['browserName'] = 'MicrosoftEdge' edge_capabilities['javascriptEnabled'] = True driver = webdriver.Remote( command_executor=self.prop.get('GRID', 'GRID_SERVER'), desired_capabilities=edge_capabilities) elif self.browser == "sauce": username = self.prop.get('CLOUD', 'sl_username') automate_key = self.prop.get('CLOUD', 'sl_key') url = "https://" + username + ":" + automate_key + "@ondemand.saucelabs.com:443/wd/hub" caps = {} caps['browserName'] = "Safari" caps['appiumVersion'] = "1.8.1" caps['deviceName'] = "iPhone X Simulator" caps['deviceOrientation'] = "portrait" caps['platformVersion'] = "11.3" caps['platformName'] = "iOS" caps['name'] = "iPhone X Execution" driver = webdriver.Remote( command_executor=url, desired_capabilities=caps) elif self.browser == "browserstack_desktop": username = self.prop.get('CLOUD', 'bs_username') automate_key = self.prop.get('CLOUD', 'bs_key') url = "http://" + username + ":" + automate_key + "@hub.browserstack.com:80/wd/hub" caps = {} caps['browser'] = 'Firefox' caps['browser_version'] = '61.0' caps['os'] = 'OS X' caps['os_version'] = 'High Sierra' caps['resolution'] = '1024x768' caps['name'] = "Mac Safari Execution" caps['browserstack.debug'] = True caps['browserstack.networkLogs'] = True driver = webdriver.Remote( command_executor=url, desired_capabilities=caps) elif self.browser == "browserstack_mobile": username = self.prop.get('CLOUD', 'bs_username') automate_key = self.prop.get('CLOUD', 'bs_key') url = "http://" + username + ":" + automate_key + "@hub-cloud.browserstack.com/wd/hub" caps={} caps['device'] = 'Google Pixel' caps['os_version'] = '7.1' caps['name'] = "Google Pixcel Execution" driver = webdriver.Remote( command_executor=url, desired_capabilities=caps) elif self.browser == "local_edge": driver_location = os.path.join(self.cur_path, r"../ExternalDrivers/MicrosoftWebDriver.exe") os.environ["webdriver.edge.driver"] = driver_location edge_capabilities = webdriver.DesiredCapabilities.EDGE driver = webdriver.Edge(capabilities=edge_capabilities, executable_path=driver_location) elif self.browser == "local_firefox": driver_location = os.path.join(self.cur_path, r"../ExternalDrivers/geckodriver.exe") os.environ["webdriver.gecko.driver"] = driver_location browser_profile = webdriver.FirefoxProfile() browser_profile.set_preference("dom.webnotifications.enabled", False) options = ffOptions() options.log.level = 'trace' firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX firefox_capabilities['marionette'] = True driver = webdriver.Firefox(capabilities=firefox_capabilities, executable_path=driver_location, options=options, log_path='/tmp/geckodriver.log', firefox_profile=browser_profile) elif self.browser == "local_chrome": driver_location = os.path.join(self.cur_path, r"../ExternalDrivers/chromedriver.exe") os.environ["webdriver.chrome.driver"] = driver_location options = chromeOptions() options.add_argument("--disable-infobars") options.add_argument("--disable-extensions") options.add_argument("--disable-notifications") options.add_argument("--start-maximized") options.add_argument("--disable-web-security") options.add_argument("--no-proxy-server") options.add_argument("--enable-automation") options.add_argument("--disable-save-password-bubble") options.add_experimental_option('prefs', {'credentials_enable_service': False, 'profile': {'password_manager_enabled': False}}) driver = webdriver.Chrome(driver_location, options=options) else: driver_location = os.path.join(self.cur_path, r"../ExternalDrivers/chromedriver.exe") os.environ["webdriver.chrome.driver"] = driver_location options = chromeOptions() options.add_argument("--disable-infobars") options.add_argument("--disable-extensions") options.add_argument("--disable-notifications") options.add_argument("--start-maximized") options.add_argument("--disable-web-security") options.add_argument("--no-proxy-server") options.add_argument("--enable-automation") options.add_argument("--disable-save-password-bubble") options.add_experimental_option('prefs', {'credentials_enable_service': False, 'profile': {'password_manager_enabled': False}}) driver = webdriver.Chrome(driver_location, options=options) if "chrome" in self.browser: driver.fullscreen_window() if self.environment == "staging": test_data = self.prop.get('RAFT', 'staging_test_data') self.config.change_properties_file('RAFT', 'base_test_data', test_data) self.url = self.prop.get('RAFT', 'staging_url') self.config.change_properties_file('RAFT', 'base_url', self.url) elif self.environment == "prod": test_data = self.prop.get('RAFT', 'prod_test_data') self.config.change_properties_file('RAFT', 'base_test_data', test_data) self.url = self.prop.get('RAFT', 'prod_url') self.config.change_properties_file('RAFT', 'base_url', self.url) else: test_data = self.prop.get('RAFT', 'staging_test_data') self.config.change_properties_file('RAFT', 'base_test_data', test_data) self.url = self.prop.get('RAFT', 'staging_url') self.config.change_properties_file('RAFT', 'base_url', self.url) driver.get(self.url) return driver
class MainPageTests(unittest.TestCase): """ This class contains the executable test cases. """ data_reader = DataReader() log = log_utils.custom_logger(logging.INFO) def setUp(self): self.main_page = MainPage(self.driver) self.exe_status = ExecutionStatus(self.driver) def tearDown(self): self.driver.delete_all_cookies() @pytest.fixture(autouse=True) def class_level_setup(self, request): """ This method is used for one time setup of test execution process. :return: it returns nothing """ if self.data_reader.get_data(request.function.__name__, "Runmode") != "Y": pytest.skip("Excluded from current execution run.") @allure.testcase("Verify Main Screen Elements Test") def test_verify_main_screen_elements(self): """ This test is validating the main screen elements. (positive scenario) :return: return test status """ test_name = sys._getframe().f_code.co_name self.log.info("###### TEST EXECUTION STARTED :: " + test_name + " ######") with allure.step("Verify Main Screen Elements"): result = self.main_page.verify_main_screen_elements() self.exe_status.mark_final(test_step=test_name, result=result) @allure.testcase("Valid User Input Test") def test_valid_user_input(self): """ This test is validating the successful user input. (positive scenario) :return: return test status """ test_name = sys._getframe().f_code.co_name self.log.info("###### TEST EXECUTION STARTED :: " + test_name + " ######") user_input = self.data_reader.get_data(test_name, "Text_Message") with allure.step("Verify User Input"): result = self.main_page.verify_valid_user_input(user_input) self.exe_status.mark_final(test_step=test_name, result=result) @allure.testcase("Valid Addition Test") def test_valid_addition(self): """ This test is validating the successful addition. (positive scenario) :return: return test status """ test_name = sys._getframe().f_code.co_name self.log.info("###### TEST EXECUTION STARTED :: " + test_name + " ######") num1 = self.data_reader.get_data(test_name, "Number_A") num2 = self.data_reader.get_data(test_name, "Number_B") expected_text = self.data_reader.get_data(test_name, "Expected") with allure.step("Verify valid addition functionality"): result = self.main_page.verify_addition_functionality(num1, num2, expected=expected_text) self.exe_status.mark_final(test_step=test_name, result=result) @allure.testcase("Invalid Addition Test") def test_invalid_addition(self): """ This test is validating the unsuccessful addition. (negative scenario) :return: return test status """ test_name = sys._getframe().f_code.co_name self.log.info("###### TEST EXECUTION STARTED :: " + test_name + " ######") num1 = self.data_reader.get_data(test_name, "Number_A") num2 = self.data_reader.get_data(test_name, "Number_B") expected_text = self.data_reader.get_data(test_name, "Expected") with allure.step("Verify invalid addition functionality"): result = self.main_page.verify_addition_functionality(num1, num2, expected=expected_text) self.exe_status.mark_final(test_step=test_name, result=result) if __name__ == '__main__': unittest.main(verbosity=2)
class MainTest(unittest.TestCase): """ This class contains the executable test cases. """ data_reader = DataReader() config = ConfigUtility() log = log_utils.custom_logger(logging.INFO) def setUp(self): self.mainpage = Mainpage(self.driver) self.exe_status = ExecutionStatus(self.driver) self.prop = self.config.load_properties_file() # def tearDown(self): # self.login_page.logout_from_app() def string_generator(self, string_size=8, chars=string.ascii_uppercase + string.digits): """ This function is used to generate random string :return: it returns random string """ return ''.join(random.choice(chars) for _ in range(string_size)) @pytest.fixture(autouse=True) def class_level_setup(self, request): """ This method is used for one time setup of test execution process. :return: it returns nothing """ if self.data_reader.get_data(request.function.__name__, "Runmode") != "Y": pytest.skip("Excluded from current execution run.") @allure.testcase("Validate startscan btn Test") def test_validate_start_scan_buttons(self): """ This test is used to verify the start scan button availability. (positive scenario) :return: return test status """ test_name = sys._getframe().f_code.co_name self.log.info("###### TEST EXECUTION STARTED :: " + test_name + " ######") with allure.step("Validate startscan btn Test successful"): result = self.mainpage.verify_start_scan_button() self.exe_status.mark_final( test_step="Validate startscan btnSuccessful", result=result) @allure.testcase("Validate stopscan btn Test") def test_validate_stop_scan_buttons(self): """ This test is is used to verify the stop scan button availability. (positive scenario) :return: return test status """ test_name = sys._getframe().f_code.co_name self.log.info("###### TEST EXECUTION STARTED :: " + test_name + " ######") with allure.step("Validate stopscan btn Successful"): result = self.mainpage.verify_stop_scan_button() self.exe_status.mark_final( test_step="Validate stopscan btn Successful", result=result) def test_validate_vertical_scroll_find_element(self): """ This method is used to verify scrolling the page vertically (positive scenario) :return: return test status """ test_name = sys._getframe().f_code.co_name self.log.info("###### TEST EXECUTION STARTED :: " + test_name + " ######") with allure.step( "Validate vertical scroll and find element Successful"): result = self.mainpage.verify_medical_screen_elements() self.exe_status.mark_final( test_step= "Validate vertical scroll and find find element Successful", result=result) def test_validate_connecting_medical_device_to_app(self): """ This method is used to verify connecting of medical device with app (positive scenario) :return: return test status """ test_name = sys._getframe().f_code.co_name self.log.info("###### TEST EXECUTION STARTED :: " + test_name + " ######") with allure.step( "Validate connecting medical device with app Successful"): result = self.mainpage.verify_medicaldevice_pairing() self.exe_status.mark_final( test_step="connecting medical device with app", result=result) def test_validate_retrieve_all_buttons(self): """ This method is used to verify pressing on all retrieve buttons (positive scenario) :return: return test status """ test_name = sys._getframe().f_code.co_name self.log.info("###### TEST EXECUTION STARTED :: " + test_name + " ######") with allure.step( "Validate pressing on all retrive buttons is Successful"): result = self.mainpage.verify_retrieve_all_buttons() self.exe_status.mark_final( test_step="pressing on all retrieve buttons", result=result) if __name__ == '__main__': unittest.main(verbosity=2)
class UIHelpers(): """ UI Helpers class to contains all ui helper methods. """ log = log_utils.custom_logger(logging.INFO) def __init__(self, driver): self.driver = driver def get_locator_type(self, locator_type): """ This method is used for getting locator type for element :param locator_type: it takes the locator type parameter ex- xpath, id :return: it returns the element identification based on locator type """ try: locator_type = locator_type.lower() if locator_type == "id": return MobileBy.ID elif locator_type == "xpath": return MobileBy.XPATH elif locator_type == "name": return MobileBy.NAME elif locator_type == "class": return MobileBy.CLASS_NAME elif locator_type == "link": return MobileBy.LINK_TEXT elif locator_type == "partiallink": return MobileBy.PARTIAL_LINK_TEXT except: self.log.error("Locator Type '" + locator_type + "' is not listed.") def wait_for_element_to_be_present(self, locator_properties, locator_type="xpath", max_time_out=10): """ This function is used for explicit waits till element present :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element located or not """ try: WebDriverWait( self.driver, max_time_out, ignored_exceptions=[StaleElementReferenceException]).until( EC.presence_of_element_located( (self.get_locator_type(locator_type), locator_properties))) return True except: return False def wait_for_element_to_be_clickable(self, locator_properties, locator_type="xpath", max_time_out=10): """ This function is used for explicit waits till element clickable :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element located or not """ try: WebDriverWait( self.driver, max_time_out, ignored_exceptions=[StaleElementReferenceException]).until( EC.element_to_be_clickable( (self.get_locator_type(locator_type), locator_properties))) return True except: self.log.error( "Exception occurred while waiting for element to be clickable." ) return False def wait_for_element_to_be_displayed(self, locator_properties, locator_type="xpath", max_time_out=10): """ This function is used for explicit waits till element displayed :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element located or not """ try: WebDriverWait( self.driver, max_time_out, ignored_exceptions=[StaleElementReferenceException]).until( EC.visibility_of_element_located( (self.get_locator_type(locator_type), locator_properties))) return True except: self.log.error( "Exception occurred while waiting for element to be visible.") return False def wait_for_element_to_be_invisible(self, locator_properties, locator_type="xpath", max_time_out=10): """ This function is used for explicit waits till element displayed :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element located or not """ try: WebDriverWait( self.driver, max_time_out, ignored_exceptions=[StaleElementReferenceException]).until( EC.invisibility_of_element_located( (self.get_locator_type(locator_type), locator_properties))) return True except: return False def is_element_present(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to return the boolean value for element present :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element present or not """ flag = False try: if self.wait_for_element_to_be_present(locator_properties, locator_type, max_time_out): self.log.info("Element present with locator_properties: " + locator_properties + " and locator_type: " + locator_type) flag = True else: self.log.error( "Element not present with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error("Exception occurred during element identification.") return flag def verify_element_not_present(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to return the boolean value for element present :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element present or not """ flag = False try: if self.wait_for_element_to_be_invisible(locator_properties, locator_type, max_time_out): self.log.info("Element invisible with locator_properties: " + locator_properties + " and locator_type: " + locator_type) flag = True else: self.log.error("Element is visible with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error( "Exception occurred during element to be invisible.") return flag def is_element_displayed(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to return the boolean value for element displayed :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element displayed or not """ try: if self.wait_for_element_to_be_displayed(locator_properties, locator_type, max_time_out): self.log.info("Element found with locator_properties: " + locator_properties + " and locator_type: " + locator_type) return True else: self.log.error("Element not found with locator_properties: " + locator_properties + " and locator_type: " + locator_type) return False except: self.log.error("Exception occurred during element identification.") return False def is_element_clickable(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to return the boolean value for element clickable :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element clickable or not """ try: if self.wait_for_element_to_be_clickable(locator_properties, locator_type, max_time_out): self.log.info( "Element is clickable with locator_properties: " + locator_properties + " and locator_type: " + locator_type) return True else: self.log.error( "Element is not clickable with locator_properties: " + locator_properties + " and locator_type: " + locator_type) return False except: self.log.error("Exception occurred during element identification.") return False def is_element_checked(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to return the boolean value for element checked/ selected :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element present or not """ flag = False try: if self.is_element_present(locator_properties, locator_type, max_time_out): element = self.get_element(locator_properties, locator_type, max_time_out) if element.is_selected(): self.log.info( "Element is selected/ checked with locator_properties: " + locator_properties + " and locator_type: " + locator_type) flag = True else: self.log.error( "Element is not selected/ checked with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: flag = False return flag def verify_elements_located(self, locator_dict, max_timeout=10): """ This method is used to return the boolean value according to element presents on page :param locator_dict: this parameter takes the list of locator value and it's type :param max_timeout: this is the maximum time to wait for particular element :return: it returns the boolean value according to element presents on page """ flag = False result = [] try: for locator_prop in locator_dict.keys(): prop_type = locator_dict[locator_prop] if self.wait_for_element_to_be_present(locator_prop, prop_type, max_timeout): self.log.info("Element found with locator_properties: " + locator_prop + " and locator_type: " + locator_dict[locator_prop]) flag = True else: self.log.error( "Element not found with locator_properties: " + locator_prop + " and locator_type: " + locator_dict[locator_prop]) flag = False result.append(flag) except Exception as ex: self.log.error( "Exception occurred during element identification: ", ex) if False in result: return False else: return True def get_element(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to get the element according to the locator type and property :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the element value """ element = None try: if self.wait_for_element_to_be_present(locator_properties, locator_type, max_time_out): element = self.driver.find_element(locator_type, locator_properties) self.log.info("Element found with locator_properties: " + locator_properties + " and locator_type: " + locator_type) else: self.log.error("Element not found with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error("Exception occurred during element identification.") return element def get_element_list(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to get the element list according to the locator type and property :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the element values as a list """ element = None try: if self.wait_for_element_to_be_present(locator_properties, locator_type, max_time_out): element = self.driver.find_elements(locator_type, locator_properties) self.log.info("Elements found with locator_properties: " + locator_properties + " and locator_type: " + locator_type) else: self.log.error("Elements not found with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error("Exception occurred during getting elements.") return element def get_text_from_element(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to get the element's inner text value according to the locator type and property :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the element inner text value """ result_text = "" try: element = self.get_element(locator_properties, locator_type, max_time_out) result_text = element.text if len(result_text) == 0: result_text = element.get_attribute("innerText") elif len(result_text) != 0: self.log.info("The text is: '" + result_text + "'") result_text = result_text.strip() except: self.log.error("Exception occurred during text retrieval.") print_stack() return result_text def get_attribute_value_from_element(self, attribute_name, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to get the element's attribute value according to the locator type and property :param attribute_name: it takes the attribute name as parameter :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the element attribute value """ attribute_value = "" try: element = self.get_element(locator_properties, locator_type, max_time_out) attribute_value = element.get_attribute(attribute_name) if attribute_value is not None: self.log.info(attribute_name.upper() + " value is: " + attribute_value) else: self.log.error(attribute_name.upper() + " value is empty.") except: self.log.error( "Exception occurred during attribute value retrieval.") return attribute_value def mouse_click_action(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to perform mouse click action according to the locator type and property :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns nothing """ try: if self.is_element_clickable(locator_properties, locator_type, max_time_out): element = self.get_element(locator_properties, locator_type, max_time_out) element.click() self.log.info( "Clicked on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) else: self.log.error( "Unable to click on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error("Exception occurred during mouse click action.") def mouse_click_action_on_element_present(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to perform mouse click action according to the locator type and property :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns nothing """ try: if self.is_element_present(locator_properties, locator_type, max_time_out): element = self.get_element(locator_properties, locator_type, max_time_out) element.click() self.log.info( "Clicked on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) else: self.log.error( "Unable to click on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error("Exception occurred during mouse click action.") def move_to_element_and_click(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used when element is not receiving the direct click :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns nothing """ try: if self.is_element_clickable(locator_properties, locator_type, max_time_out): element = self.get_element(locator_properties, locator_type, max_time_out) actions = ActionChains(self.driver) actions.move_to_element(element).click().perform() self.log.info( "Clicked on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) else: self.log.error( "Unable to click on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error("Exception occurred during mouse click action.") def enter_text_action(self, text_value, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to enter the value in text input field :param text_value: it takes input string as parameter :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns nothing :return: """ element = None try: element = self.get_element(locator_properties, locator_type, max_time_out) element.clear() element.send_keys(text_value) self.log.info( "Sent data to the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error( "Unable to send data on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) return element def verify_text_contains(self, actual_text, expected_text): """ This method verifies that actual text in the expected string :param actual_text: it takes actual keyword/ substring :param expected_text: it takes the string value to search actual keyword in it :return: it return boolean value according to verification """ self.log.info("Actual Text From Application Web UI --> :: " + actual_text) self.log.info("Expected Text From Application Web UI --> :: " + expected_text) if expected_text.lower() in actual_text.lower(): self.log.info("### VERIFICATION TEXT CONTAINS !!!") return True else: self.log.info("### VERIFICATION TEXT DOES NOT CONTAINS !!!") return False def verify_text_match(self, actual_text, expected_text): """ This method verifies the exact match of actual text and expected text :param actual_text: it takes actual string value :param expected_text: it takes the expected string value to match with :return: it return boolean value according to verification """ self.log.info("Actual Text From Application Web UI --> :: " + actual_text) self.log.info("Expected Text From Application Web UI --> :: " + expected_text) if expected_text.lower() == actual_text.lower(): self.log.info("### VERIFICATION TEXT MATCHED !!!") return True else: self.log.error("### VERIFICATION TEXT DOES NOT MATCHED !!!") return False def take_screenshots(self, file_name_initials): """ This method takes screen shot for reporting :param file_name_initials: it takes the initials for file name :return: it returns the destination directory of screenshot """ file_name = file_name_initials + "." + str(round( time.time() * 1000)) + ".png" cur_path = os.path.abspath(os.path.dirname(__file__)) screenshot_directory = os.path.join(cur_path, r"../Logs/Screenshots/") destination_directory = os.path.join(screenshot_directory, file_name) try: if not os.path.exists(screenshot_directory): os.makedirs(screenshot_directory) self.driver.save_screenshot(destination_directory) self.log.info("Screenshot saved to directory: " + destination_directory) except Exception as ex: self.log.error("### Exception occurred:: ", ex) print_stack() return destination_directory def vertical_scroll(self, scroll_view, class_name, text): """ This function is used for vertical scroll :param scroll_view: class name for scrollView :param class_name: class name for text view :param text: text of the element :return: this function returns nothing """ try: self.driver.find_element_by_android_uiautomator( "new UiScrollable(new UiSelector().scrollable(true)" + ".className(\"" + scroll_view + "\")).scrollIntoView(new UiSelector()" + ".className(\"" + class_name + "\").text(\"" + text + "\"))") self.log.info("Vertically scrolling into the view.") except Exception as ex: self.log.error( "Exception occurred while vertically scrolling into the view: ", ex) def horizontal_scroll(self, scroll_view, class_name, text): """ This function is used for horizontal scroll :param scroll_view: class name for scroll view :param class_name: class name for text view :param text: text of the element :return: this function returns nothing """ try: self.driver.find_element_by_android_uiautomator( "new UiScrollable(new UiSelector().scrollable(true)" + ".className(\"" + scroll_view + "\")).setAsHorizontalList().scrollIntoView(new UiSelector()" + ".className(\"" + class_name + "\").text(\"" + text + "\"))") self.log.info("Horizontally scrolling into the view.") except Exception as ex: self.log.error( "Exception occurred while horizontally scrolling into the view: ", ex) @staticmethod def wait_for_sync(self, seconds=5): time.sleep(seconds)
class UIHelpers: """ UI Helpers class to contains all ui helper methods. """ def __init__(self, driver): self.driver = driver log = log_utils.custom_logger(logging.INFO) def get_title(self): """ This method is used for getting the page title. :return: this method returns nothing. """ page_title = "" try: page_title = self.driver.title if page_title is None: self.log.error("Page title value is empty.") except: self.log.error( "Exception occurred while retrieving the page title.") return page_title def get_locator_type(self, locator_type): """ This method is used for getting locator type for element :param locator_type: it takes the locator type parameter ex- xpath, id :return: it returns the element identification based on locator type """ try: locator_type = locator_type.lower() if locator_type == "id": return By.ID elif locator_type == "xpath": return By.XPATH elif locator_type == "name": return By.NAME elif locator_type == "class": return By.CLASS_NAME elif locator_type == "link": return By.LINK_TEXT elif locator_type == "partiallink": return By.PARTIAL_LINK_TEXT except: self.log.error("Locator Type '" + locator_type + "' is not listed.") def wait_for_element_to_be_present(self, locator_properties, locator_type="xpath", max_time_out=10): """ This function is used for explicit waits till element present :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element located or not """ try: WebDriverWait( self.driver, max_time_out, ignored_exceptions=[StaleElementReferenceException]).until( EC.presence_of_element_located( (self.get_locator_type(locator_type), locator_properties))) return True except: return False def wait_for_element_to_be_clickable(self, locator_properties, locator_type="xpath", max_time_out=10): """ This function is used for explicit waits till element clickable :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element located or not """ try: WebDriverWait( self.driver, max_time_out, ignored_exceptions=[StaleElementReferenceException]).until( EC.element_to_be_clickable( (self.get_locator_type(locator_type), locator_properties))) return True except: self.log.error( "Exception occurred while waiting for element to be clickable." ) return False def wait_for_element_to_be_displayed(self, locator_properties, locator_type="xpath", max_time_out=10): """ This function is used for explicit waits till element displayed :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element located or not """ try: WebDriverWait( self.driver, max_time_out, ignored_exceptions=[StaleElementReferenceException]).until( EC.visibility_of_element_located( (self.get_locator_type(locator_type), locator_properties))) return True except: self.log.error( "Exception occurred while waiting for element to be visible.") return False def wait_for_element_to_be_invisible(self, locator_properties, locator_type="xpath", max_time_out=10): """ This function is used for explicit waits till element displayed :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element located or not """ try: WebDriverWait( self.driver, max_time_out, ignored_exceptions=[StaleElementReferenceException]).until( EC.invisibility_of_element_located( (self.get_locator_type(locator_type), locator_properties))) return True except: return False def is_element_present(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to return the boolean value for element present :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element present or not """ flag = False try: if self.wait_for_element_to_be_present(locator_properties, locator_type, max_time_out): self.log.info("Element present with locator_properties: " + locator_properties + " and locator_type: " + locator_type) flag = True else: self.log.error( "Element not present with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error("Exception occurred during element identification.") return flag def verify_element_not_present(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to return the boolean value for element present :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element present or not """ flag = False try: if self.wait_for_element_to_be_invisible(locator_properties, locator_type, max_time_out): self.log.info("Element invisible with locator_properties: " + locator_properties + " and locator_type: " + locator_type) flag = True else: self.log.error("Element is visible with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error( "Exception occurred during element to be invisible.") return flag def is_element_displayed(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to return the boolean value for element displayed :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element displayed or not """ try: if self.wait_for_element_to_be_displayed(locator_properties, locator_type, max_time_out): self.log.info("Element found with locator_properties: " + locator_properties + " and locator_type: " + locator_type) return True else: self.log.error("Element not found with locator_properties: " + locator_properties + " and locator_type: " + locator_type) return False except: self.log.error("Exception occurred during element identification.") return False def is_element_clickable(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to return the boolean value for element clickable :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element clickable or not """ try: if self.wait_for_element_to_be_clickable(locator_properties, locator_type, max_time_out): self.log.info( "Element is clickable with locator_properties: " + locator_properties + " and locator_type: " + locator_type) return True else: self.log.error( "Element is not clickable with locator_properties: " + locator_properties + " and locator_type: " + locator_type) return False except: self.log.error("Exception occurred during element identification.") return False def is_element_checked(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to return the boolean value for element checked/ selected :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the boolean value according to the element present or not """ flag = False try: if self.is_element_present(locator_properties, locator_type, max_time_out): element = self.get_element(locator_properties, locator_type, max_time_out) if element.is_selected(): self.log.info( "Element is selected/ checked with locator_properties: " + locator_properties + " and locator_type: " + locator_type) flag = True else: self.log.error( "Element is not selected/ checked with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: flag = False return flag def verify_elements_located(self, locator_dict, max_timeout=10): """ This method is used to return the boolean value according to element presents on page :param locator_dict: this parameter takes the list of locator value and it's type :param max_timeout: this is the maximum time to wait for particular element :return: it returns the boolean value according to element presents on page """ flag = False result = [] try: for locator_prop in locator_dict.keys(): prop_type = locator_dict[locator_prop] if self.wait_for_element_to_be_present(locator_prop, prop_type, max_timeout): self.log.info("Element found with locator_properties: " + locator_prop + " and locator_type: " + locator_dict[locator_prop]) flag = True else: self.log.error( "Element not found with locator_properties: " + locator_prop + " and locator_type: " + locator_dict[locator_prop]) flag = False result.append(flag) except Exception as ex: self.log.error( "Exception occurred during element identification: ", ex) if False in result: return False else: return True def get_element(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to get the element according to the locator type and property :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the element value """ element = None try: if self.wait_for_element_to_be_present(locator_properties, locator_type, max_time_out): element = self.driver.find_element(locator_type, locator_properties) self.log.info("Element found with locator_properties: " + locator_properties + " and locator_type: " + locator_type) else: self.log.error("Element not found with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error("Exception occurred during element identification.") return element def get_element_list(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to get the element list according to the locator type and property :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the element values as a list """ element = None try: if self.wait_for_element_to_be_present(locator_properties, locator_type, max_time_out): element = self.driver.find_elements(locator_type, locator_properties) self.log.info("Elements found with locator_properties: " + locator_properties + " and locator_type: " + locator_type) else: self.log.error("Elements not found with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error("Exception occurred during getting elements.") return element def get_text_from_element(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to get the element's inner text value according to the locator type and property :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the element inner text value """ result_text = "" try: element = self.get_element(locator_properties, locator_type, max_time_out) result_text = element.text if len(result_text) == 0: result_text = element.get_attribute("innerText") elif len(result_text) != 0: self.log.info("The text is: '" + result_text + "'") result_text = result_text.strip() except: self.log.error("Exception occurred during text retrieval.") print_stack() return result_text def get_attribute_value_from_element(self, attribute_name, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to get the element's attribute value according to the locator type and property :param attribute_name: it takes the attribute name as parameter :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns the element attribute value """ attribute_value = "" try: element = self.get_element(locator_properties, locator_type, max_time_out) attribute_value = element.get_attribute(attribute_name) if attribute_value is not None: self.log.info(attribute_name.upper() + " value is: " + attribute_value) else: self.log.error(attribute_name.upper() + " value is empty.") except: self.log.error( "Exception occurred during attribute value retrieval.") return attribute_value def mouse_click_action(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to perform mouse click action according to the locator type and property :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns nothing """ try: if self.is_element_clickable(locator_properties, locator_type, max_time_out): element = self.get_element(locator_properties, locator_type, max_time_out) element.click() self.log.info( "Clicked on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) else: self.log.error( "Unable to click on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error("Exception occurred during mouse click action.") def scroll_into_element(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to scroll to invisible element in a dropdown :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns nothing """ try: element = self.get_element(locator_properties, locator_type, max_time_out) self.driver.execute_script("return arguments[0].scrollIntoView();", element) if self.wait_for_element_to_be_present(locator_properties, locator_type, max_time_out): self.log.info( "Clicked on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error("Exception occurred during scrolling to element.") def mouse_click_action_on_element_present(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to perform mouse click action according to the locator type and property :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns nothing """ try: if self.is_element_present(locator_properties, locator_type, max_time_out): element = self.get_element(locator_properties, locator_type, max_time_out) element.click() self.log.info( "Clicked on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) else: self.log.error( "Unable to click on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error("Exception occurred during mouse click action.") def move_to_element_and_click(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used when element is not receiving the direct click :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns nothing """ try: if self.is_element_clickable(locator_properties, locator_type, max_time_out): element = self.get_element(locator_properties, locator_type, max_time_out) actions = ActionChains(self.driver) actions.move_to_element(element).click().perform() self.log.info( "Clicked on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) else: self.log.error( "Unable to click on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error("Exception occurred during mouse click action.") def enter_text_action(self, text_value, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used to enter the value in text input field :param text_value: it takes input string as parameter :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it returns nothing :return: """ element = None try: element = self.get_element(locator_properties, locator_type, max_time_out) element.clear() element.send_keys(text_value) self.log.info( "Sent data to the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) except: self.log.error( "Unable to send data on the element with locator_properties: " + locator_properties + " and locator_type: " + locator_type) return element def verify_text_contains(self, actual_text, expected_text): """ This method verifies that actual text in the expected string :param actual_text: it takes actual keyword/ substring :param expected_text: it takes the string value to search actual keyword in it :return: it return boolean value according to verification """ if expected_text.lower() in actual_text.lower(): self.log.info("### TEXT CONTAINS VERIFICATION PASSED !!!") return True else: self.log.error( "### TEXT VERIFICATION FAILED:\nActual Text --> {}\nExpected Text --> {}" .format(actual_text, expected_text)) return False def verify_text_match(self, actual_text, expected_text): """ This method verifies the exact match of actual text and expected text :param actual_text: it takes actual string value :param expected_text: it takes the expected string value to match with :return: it return boolean value according to verification """ if expected_text.lower() == actual_text.lower(): self.log.info("### TEXT VERIFICATION PASSED !!!") return True else: self.log.error( "### TEXT VERIFICATION FAILED:\nActual Text --> {}\nExpected Text --> {}" .format(actual_text, expected_text)) return False def take_screenshots(self, file_name_initials): """ This method takes screen shot for reporting :param file_name_initials: it takes the initials for file name :return: it returns the destination directory of screenshot """ file_name = file_name_initials + "." + str(round( time.time() * 1000)) + ".png" cur_path = os.path.abspath(os.path.dirname(__file__)) screenshot_directory = os.path.join(cur_path, r"../Logs/Screenshots/") destination_directory = os.path.join(screenshot_directory, file_name) try: if not os.path.exists(screenshot_directory): os.makedirs(screenshot_directory) self.driver.save_screenshot(destination_directory) self.log.info("Screenshot saved to directory: " + destination_directory) except Exception as ex: self.log.error("### Exception occurred:: ", ex) print_stack() return destination_directory def page_scrolling(self, direction="up"): """ This methos is used for page scrolling :param direction: it takes the scrolling direction value as parameter :return: it returns nothing """ if direction == "up": self.driver.execute_script("window.scrollBy(0, -1000);") elif direction == "down": self.driver.execute_script("window.scrollBy(0, 1000);") def switch_to_created_object_frame(self, locator_properties, locator_type="xpath", max_time_out=10): """ This method is used for switching to the frame where element is located :param locator_properties: it takes locator string as parameter :param locator_type: it takes locator type as parameter :param max_time_out: this is the maximum time to wait for particular element :return: it return nothing """ try: frames = self.get_element_list("//iframe") for frame in frames: frame_name = frame.get_attribute('name') if frame_name is not None: self.driver.switch_to.frame(frame_name) result = self.is_element_present(locator_properties, locator_type, max_time_out) if not result: self.driver.switch_to.default_content() continue else: self.log.info("Element found on frame: " + str(frame_name)) break else: self.driver.switch_to.default_content() continue except: self.log.error("Element not present on the page.") def switch_to_default_content(self): """ This function is used to return to the default frame of the page :return: it returns nothing """ try: self.driver.switch_to.default_content() except: self.log.error( "Exception occurred while switching to default content..") def wait_for_sync(self, seconds=5): time.sleep(seconds) def press_action_key(self, key=Keys.ENTER): actions = ActionChains(self.driver) actions.key_down(key).key_up(key).perform() def navigate_to_url(self, url, element): """ This function is used to navigate to specific url :return: it returns boolean value for successful navigation based on page title """ flag = False try: self.driver.get(url) if self.is_element_displayed(element): flag = True except: flag = False self.log.error("Exception occurred while navigating to the url.") return flag @staticmethod def string_generator(string_size=8, chars=string.ascii_uppercase + string.digits): """ This function is used to generate random string :return: it returns random string """ return ''.join(random.choice(chars) for _ in range(string_size)) @staticmethod def digit_generator(string_size=10, chars=string.digits): """ This function is used to generate random digits :return: it returns random string """ return ''.join(random.choice(chars) for _ in range(string_size))
class MainPage(BaseHelpers): """This class defines the method and element identifications for main page.""" log = log_utils.custom_logger(logging.INFO) def __init__(self, driver): super().__init__(driver) self.driver = driver team_A_super_tackle = "//android.widget.Button[@resource-id='com.example.android.prokabaddi:id/button_STackle']" team_B_super_tackle = "//android.widget.Button[@resource-id='com.example.android.prokabaddi:id/button_STackle_b']" team_A_do_or_die_raid = "//android.widget.Button[@resource-id='com.example.android.prokabaddi:id/button_DRaid']" team_B_do_or_die_raid = "//android.widget.Button[@resource-id='com.example.android.prokabaddi:id/button_DRaid']" team_A_touch = "//android.widget.Button[@resource-id='com.example.android.prokabaddi:id/button_Touch']" team_B_touch = "//android.widget.Button[@resource-id='com.example.android.prokabaddi:id/button_Touch_b']" team_A_all_out = "//android.widget.Button[@resource-id='com.example.android.prokabaddi:id/button_AllOut']" team_B_all_out = "//android.widget.Button[@resource-id='com.example.android.prokabaddi:id/button_AllOut_b']" team_A_bonus = "//android.widget.Button[@resource-id='com.example.android.prokabaddi:id/button_Bonus']" team_B_bonus = "//android.widget.Button[@resource-id='com.example.android.prokabaddi:id/button_Bonus_b']" team_A_tackle = "//android.widget.Button[@resource-id='com.example.android.prokabaddi:id/button_Tackle']" team_B_tackle = "//android.widget.Button[@resource-id='com.example.android.prokabaddi:id/button_Tackle_b']" reset_button = "//android.widget.Button[@text='RESET']" team_A_score_view = "//android.widget.TextView[@resource-id='com.example.android.prokabaddi:id/team_a_score']" team_B_score_view = "//android.widget.TextView[@resource-id='com.example.android.prokabaddi:id/team_b_score']" def verify_main_screen_elements(self): """ This function is used to verify all the elements present on the main screen :return: this function returns boolean status of element located """ result = False _xpath_prop = "xpath" locator_dict = { self.team_A_super_tackle: _xpath_prop, self.team_B_super_tackle: _xpath_prop, self.team_A_do_or_die_raid: _xpath_prop, self.team_B_do_or_die_raid: _xpath_prop, self.team_A_touch: _xpath_prop, self.team_B_touch: _xpath_prop, self.team_A_all_out: _xpath_prop, self.team_B_all_out: _xpath_prop, self.team_A_bonus: _xpath_prop, self.team_B_bonus: _xpath_prop, self.team_A_tackle: _xpath_prop, self.team_B_tackle: _xpath_prop, self.reset_button: _xpath_prop, self.team_A_score_view: _xpath_prop, self.team_B_score_view: _xpath_prop } result = self.verify_elements_located(locator_dict) if not result: self.log.error("Main screen element verification failed.") return result def verify_super_tackle_functionality(self, move_point): """ This function is used to verify super tackle functionality. :return: this function returns boolean status for super tackle functionality. """ result = True self.mouse_click_action(self.team_A_super_tackle) self.wait_for_sync(1) actual_point = self.get_text_from_element(self.team_A_score_view) if not self.verify_text_match(actual_point, str(move_point)): self.log.error("Super tackle move point is not correct.") result = False return result def verify_reset_button_functionality(self): """ This function is used to verify reset functionality. :return: this function returns boolean status for reset functionality. """ result = True self.mouse_click_action(self.reset_button) self.wait_for_sync(1) actual_score_value = self.get_text_from_element(self.team_A_score_view) if not self.verify_text_match(actual_score_value, "0"): self.log.error("Reset button functionality is not working.") result = False return result
class DriverFactory: """ This class contains the reusable methods for getting the driver instances """ log = custom_logger(logging.INFO) config = ConfigUtility() def __init__(self, browser, platform, environment, url=""): self.platform = platform self.browser = browser self.environment = environment self.url = url self.cur_path = os.path.abspath(os.path.dirname(__file__)) self.prop = self.config.load_properties_file() def get_driver_instance(self): if self.browser == "chrome": chrome_capabilities = webdriver.DesiredCapabilities.CHROME chrome_capabilities['platform'] = self.platform chrome_capabilities['browserName'] = 'chrome' chrome_capabilities['javascriptEnabled'] = True options = chromeOptions() options.add_argument("--disable-infobars") options.add_argument("--disable-extensions") options.add_argument("--disable-notifications") options.add_argument("--start-maximized") options.add_argument("--disable-web-security") options.add_argument("--no-proxy-server") options.add_argument("--enable-automation") options.add_argument("--disable-save-password-bubble") options.add_experimental_option( 'prefs', { 'credentials_enable_service': False, 'profile': { 'password_manager_enabled': False } }) driver = webdriver.Remote(command_executor=self.prop.get( 'GRID', 'GRID_SERVER'), desired_capabilities=chrome_capabilities, options=options) elif self.browser == "firefox": firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX firefox_capabilities['platform'] = self.platform firefox_capabilities['browserName'] = 'firefox' firefox_capabilities['javascriptEnabled'] = True firefox_capabilities['marionette'] = True options = ffOptions() options.log.level = 'trace' driver = webdriver.Remote( command_executor=self.prop.get('GRID', 'GRID_SERVER'), desired_capabilities=firefox_capabilities, options=options) elif self.browser == "safari": safari_capabilities = webdriver.DesiredCapabilities.SAFARI safari_capabilities['platform'] = self.platform safari_capabilities['browserName'] = 'safari' safari_capabilities['javascriptEnabled'] = True driver = webdriver.Remote(command_executor=self.prop.get( 'GRID', 'GRID_SERVER'), desired_capabilities=safari_capabilities) elif self.browser == "sauce": username = self.prop.get('CLOUD', 'sl_username') automate_key = self.prop.get('CLOUD', 'sl_key') url = "https://{}:{}@ondemand.saucelabs.com:443/wd/hub".format( username, automate_key) caps = { 'browserName': "Safari", 'appiumVersion': "1.8.1", 'deviceName': "iPhone X Simulator", 'deviceOrientation': "portrait", 'platformVersion': "11.3", 'platformName': "iOS", 'name': "iPhone X Execution" } driver = webdriver.Remote(command_executor=url, desired_capabilities=caps) elif self.browser == "browserstack_web": username = self.prop.get('CLOUD', 'bs_username') automate_key = self.prop.get('CLOUD', 'bs_key') url = "http://{}:{}@hub.browserstack.com:80/wd/hub".format( username, automate_key) caps = { 'browser': 'Firefox', 'browser_version': '61.0', 'os': 'OS X', 'os_version': 'High Sierra', 'resolution': '1024x768', 'name': "Mac Safari Execution", 'browserstack.debug': True, 'browserstack.networkLogs': True } driver = webdriver.Remote(command_executor=url, desired_capabilities=caps) elif self.browser == "browserstack_mobile": username = self.prop.get('CLOUD', 'bs_username') automate_key = self.prop.get('CLOUD', 'bs_key') url = "http://{}:{}@hub.browserstack.com:80/wd/hub".format( username, automate_key) caps = { 'device': 'Google Pixel', 'os_version': '7.1', 'name': "Google Pixcel Execution" } driver = webdriver.Remote(command_executor=url, desired_capabilities=caps) elif self.browser == "local_chrome": options = chromeOptions() options.add_argument("--disable-infobars") options.add_argument("--disable-extensions") options.add_argument("--disable-notifications") options.add_argument("--start-maximized") options.add_argument("--disable-web-security") options.add_argument("--no-proxy-server") options.add_argument("--enable-automation") options.add_argument("--disable-save-password-bubble") options.add_experimental_option( 'prefs', { 'credentials_enable_service': False, 'profile': { 'password_manager_enabled': False } }) driver = webdriver.Chrome(ChromeDriverManager().install(), options=options) elif self.browser == "local_firefox": browser_profile = webdriver.FirefoxProfile() browser_profile.set_preference("dom.webnotifications.enabled", False) options = ffOptions() options.log.level = 'trace' firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX firefox_capabilities['marionette'] = True driver = webdriver.Firefox( capabilities=firefox_capabilities, executable_path=GeckoDriverManager().install(), options=options, service_log_path='/tmp/geckodriver.log', firefox_profile=browser_profile) else: options = chromeOptions() options.add_argument("--disable-infobars") options.add_argument("--disable-extensions") options.add_argument("--disable-notifications") options.add_argument("--start-maximized") options.add_argument("--disable-web-security") options.add_argument("--no-proxy-server") options.add_argument("--enable-automation") options.add_argument("--disable-save-password-bubble") options.add_experimental_option( 'prefs', { 'credentials_enable_service': False, 'profile': { 'password_manager_enabled': False } }) driver = webdriver.Chrome(ChromeDriverManager().install(), options=options) if "chrome" in self.browser: driver.fullscreen_window() if self.environment == "staging": test_data = self.prop.get('RAFT', 'staging_test_data') self.config.change_properties_file('RAFT', 'base_test_data', test_data) self.url = self.prop.get('RAFT', 'staging_url') self.config.change_properties_file('RAFT', 'base_url', self.url) elif self.environment == "prod": test_data = self.prop.get('RAFT', 'prod_test_data') self.config.change_properties_file('RAFT', 'base_test_data', test_data) self.url = self.prop.get('RAFT', 'prod_url') self.config.change_properties_file('RAFT', 'base_url', self.url) else: test_data = self.prop.get('RAFT', 'staging_test_data') self.config.change_properties_file('RAFT', 'base_test_data', test_data) self.url = self.prop.get('RAFT', 'staging_url') self.config.change_properties_file('RAFT', 'base_url', self.url) driver.get(self.url) return driver
class DriverFactory: log = custom_logger(logging.INFO) config = ConfigUtility() def __init__(self, browser, platform, environment, url=""): self.platform = platform self.browser = browser self.environment = environment self.url = url self.cur_path = os.path.abspath(os.path.dirname(__file__)) self.prop = self.config.load_properties_file() def get_driver_instance(self): if self.browser == "chrome": chrome_capabilities = webdriver.DesiredCapabilities.CHROME chrome_capabilities['platform'] = self.platform chrome_capabilities['browserName'] = 'chrome' chrome_capabilities['javascriptEnabled'] = True options = chromeOptions() options.add_argument("--disable-infobars") options.add_argument("--disable-extensions") options.add_argument("--disable-notifications") options.add_argument("--start-maximized") options.add_argument("--disable-web-security") options.add_argument("--no-proxy-server") options.add_argument("--enable-automation") options.add_argument("--disable-save-password-bubble") options.add_experimental_option( 'prefs', { 'credentials_enable_service': False, 'profile': { 'password_manager_enabled': False } }) driver = webdriver.Remote(command_executor=self.prop.get( 'GRID', 'GRID_SERVER'), desired_capabilities=chrome_capabilities, options=options) elif self.browser == "firefox": firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX firefox_capabilities['platform'] = self.platform firefox_capabilities['browserName'] = 'firefox' firefox_capabilities['javascriptEnabled'] = True firefox_capabilities['marionette'] = True options = ffOptions() options.log.level = 'trace' driver = webdriver.Remote( command_executor=self.prop.get('GRID', 'GRID_SERVER'), desired_capabilities=firefox_capabilities, options=options) elif self.browser == "safari": safari_capabilities = webdriver.DesiredCapabilities.SAFARI safari_capabilities['platform'] = self.platform safari_capabilities['browserName'] = 'safari' safari_capabilities['javascriptEnabled'] = True driver = webdriver.Remote(command_executor=self.prop.get( 'GRID', 'GRID_SERVER'), desired_capabilities=safari_capabilities) else: test_data = self.prop.get('RAFT', 'staging_test_data') self.config.change_properties_file('RAFT', 'base_test_data', test_data) self.url = self.prop.get('RAFT', 'staging_url') self.config.change_properties_file('RAFT', 'base_url', self.url) driver.get(self.url) return driver
class ExecutionStatus(UIHelpers): """ This class contains the methods to conclude the execution status. """ log = log_utils.custom_logger(logging.INFO) def __init__(self, driver): super().__init__(driver) self.result_list = [] def set_result(self, result, test_name): """ This method is used for setting the execution result. :param result: this parameter takes the execution status value pass/fail. :param test_name: this parameter takes the execution status description. :return: this method returns nothing. """ try: if result is not None: if result: self.result_list.append("PASS") self.log.info("### STEP SUCCESSFUL :: " + test_name) else: image = self.take_screenshots(test_name) error = "### STEP FAILED :: " + test_name self.result_list.append("FAIL") self.log.error(error) allure.attach.file( image, attachment_type=allure.attachment_type.PNG) else: image = self.take_screenshots(test_name) error = "### STEP FAILED :: " + test_name self.result_list.append("FAIL") self.log.error(error) allure.attach.file(image, attachment_type=allure.attachment_type.PNG) except Exception as ex: image = self.take_screenshots(test_name) self.result_list.append("FAIL") self.log.error("### EXCEPTION OCCURRED :: {}".format(ex)) allure.attach.file(image, attachment_type=allure.attachment_type.PNG) def mark(self, test_step, result): """ This method handles intermediate assertions and saves the result for final mark. :param result: this parameter takes the execution status value pass/fail. :param test_step: it takes the test case name value :return: this method returns nothing. """ self.set_result(result=result, test_name=test_step) def mark_final(self, result, test_step): """ This method handles final assertion and saves the result for final mark. :param test_step: it takes the test case name value :param result: this parameter takes the execution status value pass/fail. :return: this method returns nothing. """ self.set_result(result, test_step) # noinspection PyBroadException try: if "FAIL" in self.result_list: self.result_list.clear() assert True is False else: self.result_list.clear() assert True is True, "### TEST SUCCESSFUL :: " + test_step except Exception: pytest.fail("### TEST FAILED :: " + test_step, pytrace=False)
""" This module contains the all test cases.""" import sys import allure import pytest import logging from SupportLibraries.ui_helpers import UIHelpers import FrameworkUtilities.logger_utility as log_utils from PageObjects.MainPageObjects.main_page import MainPage from FrameworkUtilities.data_reader_utility import DataReader from FrameworkUtilities.execution_status_utility import ExecutionStatus data_reader = DataReader() log = log_utils.custom_logger(logging.INFO) @allure.story('[DEMO] - Automate the basic functionality') @allure.feature('Web App Input Tests') @pytest.mark.usefixtures("get_driver", "initialize") class TestMainPage: """ This class contains the executable test cases. """ @pytest.fixture(scope='function') def initialize(self): self.main_page = MainPage(self.driver) self.exe_status = ExecutionStatus(self.driver) self.ui_helpers = UIHelpers(self.driver) def cleanup(): self.driver.delete_all_cookies()
class MainPageTests(unittest.TestCase): """ This class contains the executable test cases. """ data_reader = DataReader() config = ConfigUtility() log = log_utils.custom_logger(logging.INFO) def setUp(self): self.main_page = MainPage(self.driver) self.exe_status = ExecutionStatus(self.driver) self.prop = self.config.load_properties_file() def tearDown(self): pass # self.login_page.logout_from_app() @pytest.fixture(autouse=True) def class_level_setup(self, request): """ This method is used for one time setup of test execution process. :return: it returns nothing """ if self.data_reader.get_data(request.function.__name__, "Runmode") != "Y": pytest.skip("Excluded from current execution run.") @allure.testcase("Verify Main Screen Elements") def test_verify_main_screen_elements(self): """ This test is validating the presence of main screen elements. :return: return test status """ test_name = sys._getframe().f_code.co_name self.log.info("###### TEST EXECUTION STARTED :: " + test_name + " ######") with allure.step("Verify Presence of Main Screen Elements Successful"): result = self.main_page.verify_main_screen_elements() self.exe_status.mark_final( test_step="Verify Presence of Main Screen Elements Successful", result=result) def test_verify_supertackle_reset(self): """ This test is validating the presence of main screen elements. :return: return test status """ test_name = sys._getframe().f_code.co_name self.log.info("###### TEST EXECUTION STARTED :: " + test_name + " ######") with allure.step("Verify Super Tackle Functionality"): result_1 = self.main_page.verify_super_tackle_functionality( self.data_reader.get_data(test_name, "MovePoint")) self.exe_status.mark(test_step="Verify Super Tackle Functionality", result=result_1) with allure.step("Verify Reset Button Functionality"): result = self.main_page.verify_reset_button_functionality() self.exe_status.mark_final( test_step="Verify Reset Button Functionality", result=result)
class Mainpage(BaseHelpers): """This class defines the method and element identifications for Main page.""" config = ConfigUtility() log = custom_logger(logging.INFO) # def __init__(self, driver): # super().__init__(driver) # self.driver = driver # self.mp = MainPage # self.prop = self.config.load_properties_file() # # welcome_page_login_link = "//android.widget.TextView[contains(@text, 'Login')]" # email = "//android.widget.TextView[contains(@text,'Email')]//following::android.widget.EditText[1]" # password = "******" # login_button = "//android.widget.TextView[contains(@text, 'Log in')]" # logout_button = "//android.widget.TextView[contains(@text, 'Logout')]" # logout_scroll_view_class = "android.widget.ScrollView" # logout_text_class = "android.widget.TextView" # logout_text = "Logout" # number_firstpage = "//android.widget.TextView[@text='NUM 1']" number_secondpage = "//android.widget.TextView[@text='NUM 2']" start_scan_button = "//android.widget.Button[@text='START SCAN']" stop_scan_button = "//android.widget.Button[@text='STOP SCAN']" init_with_mac = "//android.widget.Button[@text='INIT WITH MAC']" disconnect_button = "//android.widget.Button[@text='DISCONNECT']" connect_button = "//android.widget.Button[@text='CONNECT']" connected = "//android.widget.TextView[@text='Connected']" disconnected = "//android.widget.TextView[@text='Disconnected']" start_observing_button = "//android.widget.Button[@text='START OBSERVING']" stop_observing_button = "//android.widget.Button[@text='STOP OBSERVING']" test_cache = "//android.widget.Button[@text='TEST CACHE']" clear_cache = "//android.widget.Button[@text='CLEAR CACHE']" scanning = "//android.widget.TextView[@text='Scanning']" bond_status1 = "//android.widget.TextView[@text='Bond Status: Not bonded']" bond_status2 = "//android.widget.TextView[@text='Bond Status: Bonded']" connection_status1 = "//android.widget.TextView=[@text='Connection Status: RxBleConnectionState{CONNECTING}']" connection_status2 = "//android.widget.TextView=[@text='Connection Status: RxBleConnectionState{DISCONNECTED}']" scroll_grey_screen = "//android.widget.ScrollView=[@text='']" pairing_request_ok = "//android.widget.Button=[@text='OK']" show_device_info = "//android.widget.Button=[@text='SHOW DEVICE INFO']" # retrieve buttons retrieve_new = "//android.widget.Button[@text='RETRIEVE NEW']" retrieve_all = "//android.widget.Button[@text='RETRIEVE ALL']" retrieve_oldest = "//android.widget.Button[@text='RETRIEVE OLDEST']" retrieve_newest = "//android.widget.Button[@text='RETRIEVE NEWEST']" retrieve_sequence_num = "//android.widget.Button[@text='RETRIEVE SEQ. #']" retrieve_from_sequence_num = "//android.widget.Button[@text='RETRIEVE FROM SEQ. #']" # state buttons save_state = "//android.widget.Button=[@text='SAVE STATE']" restore_state = "//android.widget.Button=[@text='RESTORE STATE']" # GET buttons get_features = "//android.widget.Button=[@text='GET FEATURES']" get_current_time = "//android.widget.Button=[@text='GET CURRENT TIME']" get_battery_level = "//android.widget.Button=[@text='GET BATTERY LEVEL']" get_local_timeinfo = "//android.widget.Button=[@text='GET LOCAL TIME INFO']" get_refresh_timeinfo = "//android.widget.Button=[@text='GET REF TIME INFO']" get_model_number = "//android.widget.Button=[@text='GET MODEL #']" get_manufacture_name = "//android.widget.Button=[@text='GET MAN. NAME']" get_serial_number = "//android.widget.Button=[@text='GET SERIAL #']" get_hw_rev = "//android.widget.Button=[@text='GET HW REV']" get_fw_rev = "//android.widget.Button=[@text='GET FW REV']" get_sw_rev = "//android.widget.Button=[@text='GET SW REV']" get_sys_id = "//android.widget.Button=[@text='GET SYS ID']" get_pnp_id = "//android.widget.Button=[@text='GET PNP ID']" get_Fw_Rev_class = "android.widget.Button" get_Fw_Rev_Text = "GET FW REV" scroll_view_class = "android.widget.ScrollView" stpo_scan = "STOP SCAN" # medical device info medical_device_info_1 = "//android.widget.TextView[@text='Contour7830H6086398 (54:6C:0E:CB:D5:E1)']" # Contour medical_device_info_2 = "//android.widget.TextView[@text='meter+06647277 (10:CE:A9:3B:D7:57)']" # Accu-Chek Guide def verify_start_scan_button(self): """ This method is used to verify the start scan button availabilty. :return: this method returns boolean value for element present start scan button """ self.mouse_click_action_on_element_present(self.number_secondpage) result = self.is_element_present(self.start_scan_button, max_time_out=30) if not result: self.log.error("Unable to find start scan button") return result def verify_stop_scan_button(self): """ This method is used to verify the stop scan button availabilty. :return: this method returns boolean value for element present stop scan button """ result = self.is_element_present(self.stop_scan_button) if not result: self.log.error("Unable to find stop scan button.") return result def verify_medical_screen_elements(self): """ This method is used to verify scrolling the page vertically. :return: this method returns boolean value for element present and scrolling successful """ self.vertical_scroll(self.scroll_view_class, self.get_Fw_Rev_class, self.get_Fw_Rev_Text) self.vertical_scroll(self.scroll_view_class, self.get_Fw_Rev_class, self.stpo_scan) self.wait_for_sync() result = self.is_element_present(self.stop_scan_button) if not result: self.log.error("Unable to scroll application.") return result def verify_medicaldevice_pairing(self): """ This method is used to verify connecting of medical device with app (positive scenario) :return: return test status """ self.mouse_click_action_on_element_present(self.number_firstpage) self.mouse_click_action_on_element_present(self.start_scan_button) self.mouse_click_action_on_element_present(self.stop_scan_button) self.mouse_click_action_on_element_present(self.medical_device_info_2) self.mouse_click_action_on_element_present(self.connect_button) self.wait_for_sync() self.wait_for_sync() self.wait_for_sync() result = self.is_element_present(self.retrieve_all) if not result: self.log.error("Unable to connect medical device.") return result def verify_retrieve_all_buttons(self): """ This method is used to verify pressing on all retrieve buttons (positive scenario) :return: return test status """ self.wait_for_sync() self.wait_for_sync() self.mouse_click_action_on_element_present(self.retrieve_all) self.device_back_button_click() self.wait_for_sync() self.mouse_click_action_on_element_present(self.retrieve_oldest) self.device_back_button_click() self.wait_for_sync() self.mouse_click_action_on_element_present(self.retrieve_newest) self.device_back_button_click() self.wait_for_sync() self.mouse_click_action_on_element_present(self.retrieve_new) self.wait_for_sync() self.device_back_button_click() self.wait_for_sync() self.mouse_click_action_on_element_present(self.retrieve_sequence_num) self.wait_for_sync() self.device_back_button_click() self.wait_for_sync() self.mouse_click_action_on_element_present( self.retrieve_from_sequence_num) self.wait_for_sync() self.device_back_button_click() result = self.is_element_present(self.retrieve_from_sequence_num) if not result: self.log.error("Unable to press all the retrieve buttons.") return result