def dragAndDropPerform(context, source, target): value = ConfigurationsManager().get_str_for_key(source, default_value=source) getLocator = json.loads(value)['locator'] BaseDriver().get_driver().execute_script( jsText() + "simulateDragDrop(arguments[0], arguments[1])", Find_PAFWebElement(typeBy(getLocator), locator(getLocator)), Find_PAFWebElement(typeBy(target), locator(target))) # ActionChains(BaseDriver().get_driver()).drag_and_drop(Find_PAFWebElement(typeBy(getLocator),locator(getLocator)), Find_PAFWebElement(typeBy(target),locator(target))).perform() ActionChains(BaseDriver().get_driver()).click_and_hold( Find_PAFWebElement(typeBy(getLocator), locator(getLocator))).release( Find_PAFWebElement(typeBy(target), locator(target))).perform()
def Find_PAFWebElement(by, locator): loc = str(locator) if str(by) == "id": rdata = BaseDriver().get_driver().find_element_by_id(loc) return rdata if str(by) == 'xpath': rdata = BaseDriver().get_driver().find_element_by_xpath(loc) return rdata elif str(by) == "name": rdata = BaseDriver().get_driver().find_element_by_name(loc) return rdata elif str(by) == "link text": rdata = BaseDriver().get_driver().find_element_by_link_text(loc) return rdata elif str(by) == "partial link text": rdata = BaseDriver().get_driver().find_element_by_partial_link_text( loc) return rdata elif str(by) == "tag name": rdata = BaseDriver().get_driver().find_element_by_tag_name(loc) return rdata elif str(by) == "css selector": rdata = BaseDriver().get_driver().find_element_by_css_name(loc) return rdata elif str(by) == "class name": rdata = BaseDriver().get_driver().find_element_by_class_selector(loc) return rdata else: print("Type of element is not recognised")
def dragSourceOnValue(context, source, targetValue): value = ConfigurationsManager().get_str_for_key(source, default_value=source) getLocator = json.loads(value)['locator'] text = "arguments[0].setAttribute('value'," + targetValue + ");if(typeof(arguments[0].onchange) === 'function'){arguments[0].onchange('');}" BaseDriver().get_driver().execute_script( text, Find_PAFWebElement(typeBy(getLocator), locator(getLocator)))
def setAfterLamdaCap(context): print("setAfterLamdaCap method called : ") ConfigurationsManager().set_object_for_key( ApplicationProperties.REMOTE_SERVER, 'http://localhost:') ConfigurationsManager().set_object_for_key( ApplicationProperties.DRIVER_NAME, 'chromeDriver') BaseDriver().stop_driver()
def waitForAlert(context, timeout): try: millisec = (int(timeout) / 1000) WebDriverWait(BaseDriver().get_driver(), int(millisec)).until( EC.alert_is_present(), 'Timed out waiting for PA creation ' + 'confirmation popup to appear.') except TimeoutException: print('')
def verifyAlertPresent(context, timeout): try: millisec = (int(timeout) / 1000) WebDriverWait(BaseDriver().get_driver(), int(millisec)).until( EC.alert_is_present(), 'Timed out waiting for PA creation ' + 'confirmation popup to appear.') except TimeoutException: PAFWebElement().verify_not_present()
def offsetDragAndDropPerform(context, source, xtarget, ytarget): value = ConfigurationsManager().get_str_for_key(source, default_value=source) getLocator = json.loads(value)['locator'] # ActionChains(BaseDriver().get_driver()).drag_and_drop_by_offset(Find_PAFWebElement(typeBy(getLocator),locator(getLocator)),int(xtarget),int(ytarget)).perform() ActionChains(BaseDriver().get_driver()).click_and_hold( Find_PAFWebElement(typeBy(getLocator), locator(getLocator))).move_by_offset( int(xtarget), int(ytarget)).release().perform()
def setbeforeLambdaCap(context, index): print("setbeforeLambdaCap method called : ") BaseDriver().stop_driver() capObj = json.loads(index) capNew = (json.dumps(capObj['cap'])).replace("'", "\"") ConfigurationsManager().set_object_for_key( ApplicationProperties.DRIVER_NAME, 'lambdaTest') ConfigurationsManager().set_object_for_key( ApplicationProperties.REMOTE_SERVER, capObj['remote.server']) ConfigurationsManager().set_object_for_key( 'lambda.additional.capabilities', capNew)
def get_a_cookie_with_a_name(context, name): BaseDriver().get_driver().get_cookie(process(name))
def setAlertText(context, text): BaseDriver().get_driver().switch_to.alert.send_keys(text)
def getAlertText(context, input): ConfigurationsManager().set_object_for_key( input, BaseDriver().get_driver().switch_to.alert.text)
def dismissAlert(self): BaseDriver().get_driver().switch_to.alert.dismiss()
def switch_to_platform(context, platform): BaseDriver().stop_driver() ResourcesManager().load_directory(["resources/" + process(platform)])
def driver(self): return PAFWebDriver(BaseDriver().get_driver())
def storeTitleIntoVariable(context, text): storeTitle = BaseDriver().get_driver().title print("title >>>>>>>>>>>>>>>>>>>>>>> : ", storeTitle) ConfigurationsManager().set_object_for_key(text, storeTitle)
def after_all(self, context): ExecutionMetaInfo().endTime = current_timestamp() BaseDriver().stop_driver()
def maximizeWindow(self): BaseDriver().get_driver().maximize_window()
def switch_to_frame(context, frame_name): BaseDriver().get_driver().switch_to_frame( PAFWebElement(frame_name).locator)
def switchWindow(context, index): BaseDriver().get_driver().switch_to_window( BaseDriver().get_driver().window_handles[int(index)])
def close(context, loc): BaseDriver().get_driver().close()
def delete_all_cookies(context): BaseDriver().get_driver().delete_all_cookies()
def add_cookie_with_value(context, name, value): BaseDriver().get_driver().add_cookie({process(name): process(value)})
def dragSourceOnValue(context, scriptData): BaseDriver().get_driver().execute_async_script(scriptData)
def mouse_move_on(context, loc): location = PAFWebElement(loc).location ActionChains(BaseDriver().get_driver()).move_by_offset( location['x'], location['y'])
def delete_cookie_with_name(context, name): BaseDriver().get_driver().delete_cookie(process(name))
def acceptAlert(self): BaseDriver().get_driver().switch_to.alert.accept()
class BaseEnvironment: def __init__(self): self.current_feature = None self.current_scenario = None self.current_step = None self.obj_scenario_meta_info = None def before_all(self, context): ProjectEnvironment.set_up() root_directory = os.path.join(OUTPUT_TEST_RESULTS_DIR, date_time()) create_directory(root_directory) os.environ['REPORT_DIR'] = root_directory before_all() def after_all(self, context): ExecutionMetaInfo().endTime = current_timestamp() BaseDriver().stop_driver() def before_feature(self, context, feature): envInfoDetails = { "browser-desired-capabilities": {}, "browser-actual-capabilities": {}, "isfw-build-info": {}, "run-parameters": {}, "execution-env-info": {} } current_feature_directory = os.path.join( os.getenv('REPORT_DIR'), 'json', re.sub('[^A-Za-z0-9]+', ' - ', re.sub('.feature', '', feature.filename))) create_directory(current_feature_directory) os.environ['CURRENT_FEATURE_DIR'] = current_feature_directory ExecutionMetaInfo().add_test( re.sub('[^A-Za-z0-9]+', ' - ', re.sub('.feature', '', feature.filename))) FeatureOverView().startTime = current_timestamp() FeatureOverView().add_class(feature.name) # driver_name = str(ConfigurationsManager().get_str_for_key('driver.name')) # driver_name[:str(driver_name).lower().index('driver')] envInfoDetails["browser-desired-capabilities"][ "browserName"] = BaseDriver().get_driver( ).capabilities['browserName'] envInfoDetails["browser-desired-capabilities"][ "cssSelectorsEnabled"] = "true" envInfoDetails["browser-desired-capabilities"][ "javascriptEnabled"] = "true" envInfoDetails["browser-desired-capabilities"][ "takesScreenshot"] = "true" envInfoDetails["browser-desired-capabilities"]["platform"] = str( ConfigurationsManager().get_str_for_key('platform')) envInfoDetails["browser-desired-capabilities"]["version"] = BaseDriver( ).get_driver().capabilities['browserVersion'] json_object = BaseDriver().get_driver().capabilities pairs = json_object.items() for key, value in pairs: # print(str(value)) envInfoDetails["browser-actual-capabilities"][key] = str(value) envInfoDetails["isfw-build-info"]["qaf-Type"] = "core" envInfoDetails["isfw-build-info"][ "qaf-Build-Time"] = current_timestamp() envInfoDetails["isfw-build-info"]["qaf-Version"] = "3.0" envInfoDetails["run-parameters"]["resources"] = str( ConfigurationsManager().get_str_for_key('env.resources')) envInfoDetails["run-parameters"]["file.feature"] = "feature/" + str( ConfigurationsManager().get_str_for_key('platform')) envInfoDetails["run-parameters"]["baseurl"] = str( ConfigurationsManager().get_str_for_key('env.baseurl')) # envInfoDetails["execution-env-info"]["java.arch"] = "64" # envInfoDetails["execution-env-info"]["java.vendor"] = "Oracle Corporation 22" envInfoDetails["execution-env-info"][ "python.version"] = platform.python_version() envInfoDetails["execution-env-info"]["os.arch"] = platform.processor() envInfoDetails["execution-env-info"]["host"] = platform.node() envInfoDetails["execution-env-info"]["os.name"] = platform.platform() envInfoDetails["execution-env-info"]["user.name"] = os.getlogin() envInfoDetails["execution-env-info"]["os.version"] = platform.version() # drivercap = json.loads(BaseDriver.__driver.capabilities) # print(BaseDriver().get_driver().capabilities['browserName']) FeatureOverView().add_envInfo(envInfoDetails) def after_feature(self, context, feature): FeatureOverView().endTime = current_timestamp() def before_scenario(self, context, scenario): self.current_scenario = scenario current_scenario_directory = os.path.join( os.getenv('CURRENT_FEATURE_DIR'), scenario.feature.name) create_directory(current_scenario_directory) os.environ['CURRENT_SCENARIO_DIR'] = current_scenario_directory self.obj_scenario_meta_info = ScenarioMetaInfo() self.obj_scenario_meta_info.startTime = current_timestamp() def after_scenario(self, context, scenario): status_name = scenario.status.name if "##" in scenario.name: x = (scenario.name).split("##") scenario.name = x[0] scenario.description = x[1] if "##" in self.current_scenario.name: x = (self.current_scenario.name).split("##") self.current_scenario.name = x[0] self.current_scenario.description = x[1] if scenario.status == Status.failed: steps = scenario.steps for step in steps: if step.status == Status.failed: error_message = step.error_message error_message = error_message.splitlines() Scenario( file_name=scenario.name).errorTrace = error_message elif step.status == Status.skipped or step.status == Status.untested: obj_step = Step() obj_step.start_behave_step(step) obj_step.stop_behave_step(step) Scenario( file_name=self.current_scenario.name).add_checkPoints( obj_step.obj_check_point) del obj_step else: checkPoints = Scenario( file_name=self.current_scenario.name).checkPoints for checkPoint in checkPoints: if checkPoint['type'] == MessageType.TestStepFail: status_name = 'failed' break ExecutionMetaInfo().update_status(status_name) FeatureOverView().update_status(status_name) self.obj_scenario_meta_info.duration = scenario.duration * 1000 self.obj_scenario_meta_info.result = status_name obj_meta_data = MetaData() obj_meta_data.name = scenario.name obj_meta_data.resultFileName = scenario.name if scenario.description: obj_meta_data.description = scenario.description obj_meta_data.reference = six.text_type(scenario.location) obj_meta_data.referece = six.text_type(scenario.location) obj_meta_data.groups = scenario.effective_tags self.obj_scenario_meta_info.metaData = obj_meta_data.to_json_dict() self.obj_scenario_meta_info.close() del self.obj_scenario_meta_info self.obj_scenario_meta_info = None Scenario(file_name=scenario.name).seleniumLog = SeleniumLogStack( ).get_all_selenium_log() BaseDriver().stop_driver() def before_step(self, context, step): self.current_step = step def after_step(self, context, step): obj_step = Step() obj_step.start_behave_step(step) obj_step.stop_behave_step(step) Scenario(file_name=self.current_scenario.name).add_checkPoints( obj_step.obj_check_point) del obj_step
def switch_to_parent_frame(context): BaseDriver().get_driver().switch_to_default_content()
def before_feature(self, context, feature): envInfoDetails = { "browser-desired-capabilities": {}, "browser-actual-capabilities": {}, "isfw-build-info": {}, "run-parameters": {}, "execution-env-info": {} } current_feature_directory = os.path.join( os.getenv('REPORT_DIR'), 'json', re.sub('[^A-Za-z0-9]+', ' - ', re.sub('.feature', '', feature.filename))) create_directory(current_feature_directory) os.environ['CURRENT_FEATURE_DIR'] = current_feature_directory ExecutionMetaInfo().add_test( re.sub('[^A-Za-z0-9]+', ' - ', re.sub('.feature', '', feature.filename))) FeatureOverView().startTime = current_timestamp() FeatureOverView().add_class(feature.name) # driver_name = str(ConfigurationsManager().get_str_for_key('driver.name')) # driver_name[:str(driver_name).lower().index('driver')] envInfoDetails["browser-desired-capabilities"][ "browserName"] = BaseDriver().get_driver( ).capabilities['browserName'] envInfoDetails["browser-desired-capabilities"][ "cssSelectorsEnabled"] = "true" envInfoDetails["browser-desired-capabilities"][ "javascriptEnabled"] = "true" envInfoDetails["browser-desired-capabilities"][ "takesScreenshot"] = "true" envInfoDetails["browser-desired-capabilities"]["platform"] = str( ConfigurationsManager().get_str_for_key('platform')) envInfoDetails["browser-desired-capabilities"]["version"] = BaseDriver( ).get_driver().capabilities['browserVersion'] json_object = BaseDriver().get_driver().capabilities pairs = json_object.items() for key, value in pairs: # print(str(value)) envInfoDetails["browser-actual-capabilities"][key] = str(value) envInfoDetails["isfw-build-info"]["qaf-Type"] = "core" envInfoDetails["isfw-build-info"][ "qaf-Build-Time"] = current_timestamp() envInfoDetails["isfw-build-info"]["qaf-Version"] = "3.0" envInfoDetails["run-parameters"]["resources"] = str( ConfigurationsManager().get_str_for_key('env.resources')) envInfoDetails["run-parameters"]["file.feature"] = "feature/" + str( ConfigurationsManager().get_str_for_key('platform')) envInfoDetails["run-parameters"]["baseurl"] = str( ConfigurationsManager().get_str_for_key('env.baseurl')) # envInfoDetails["execution-env-info"]["java.arch"] = "64" # envInfoDetails["execution-env-info"]["java.vendor"] = "Oracle Corporation 22" envInfoDetails["execution-env-info"][ "python.version"] = platform.python_version() envInfoDetails["execution-env-info"]["os.arch"] = platform.processor() envInfoDetails["execution-env-info"]["host"] = platform.node() envInfoDetails["execution-env-info"]["os.name"] = platform.platform() envInfoDetails["execution-env-info"]["user.name"] = os.getlogin() envInfoDetails["execution-env-info"]["os.version"] = platform.version() # drivercap = json.loads(BaseDriver.__driver.capabilities) # print(BaseDriver().get_driver().capabilities['browserName']) FeatureOverView().add_envInfo(envInfoDetails)
def set_attribute_value_is(context, loc, attr, value): element = PAFWebElement(loc) BaseDriver().get_driver().execute_script( "arguments[0].{attr} = arguments[1]".format(attr=process(attr)), element, process(value))