How to use field_xpath method in lettuce_webdriver

Best Python code snippet using lettuce_webdriver_python

test_cases_functional.py

Source:test_cases_functional.py Github

copy

Full Screen

1# conftest.py2# Date: 2020.11.273# Author: Laurentiu Mandru4# Email: mclaurentiu79@gmail.com5# coding=utf-86"""Functional test cases for LAM - steps implementation"""7import logging8from time import sleep9from pytest_bdd import (10 given,11 scenario,12 then,13 when,14 parsers15)16logger = logging.getLogger(__name__)17@scenario('../features/functional_test_cases.feature', 'TC.01 – Access LAM online tool')18def test_tc01__access_lam_online_tool():19 """TC.01 – Access LAM online tool."""20@scenario('../features/functional_test_cases.feature', 'TC.03 – TOC for Properties - Expands and collapses')21def test_tc03_toc_for_properties_expands_and_collapses():22 """TC.03 – TOC for Properties - Expands and collapses"""23@scenario('../features/functional_test_cases.feature', 'TC.03 – TOC for Properties - Selected entry is highlighted')24def test_tc03_toc_for_properties_selected_entry_is_highlighted():25 """TC.03 – TOC for Properties - Selected entry is highlighted"""26@scenario('../features/functional_test_cases.feature', 'TC.04 – TOC for Templates - Expands and collapses')27def test_tc04_toc_for_templates_expands_and_collapses():28 """TC.04 – TOC for Templates - Expands and collapses"""29@scenario('../features/functional_test_cases.feature', 'TC.05 – TOC for Celex numbers - Expands and collapses')30def test_tc05_toc_for_celex_numbers_expands_and_collapses():31 """TC.05 – TOC for Celex numbers - Expands and collapses"""32@scenario('../features/functional_test_cases.feature', 'TC.05 – TOC for Celex numbers - Selected entry is highlighted')33def test_tc05_toc_for_celex_numbers_selected_entry_is_highlighted():34 """TC.05 – TOC for Celex numbers - Selected entry is highlighted"""35@scenario('../features/functional_test_cases.feature', 'Verify that specific properties exist')36def test_verify_that_specific_properties_exist():37 """Verify that specific properties exist"""38@scenario('../features/functional_test_cases.feature', 'Verify that specific classes exist')39def test_verify_that_specific_classes_exist():40 """Verify that specific classes exist"""41@scenario('../features/functional_test_cases.feature', 'Verify that specific CELEXs exist')42def test_verify_that_specific_celexs_exist():43 """Verify that specific CELEXs exist"""44@given(parsers.cfparse('the baseURI {base_uri:String}', extra_types=dict(String=str)))45def the_baseuri_lam_uri(browser, scenario_context, base_uri):46 """the baseURI LAM_URI."""47 if base_uri == "LAM_URL":48 from tests.config import LAM_URL49 scenario_context["base_uri"] = LAM_URL50@when(parsers.cfparse('I navigate to the location {pageLocation:String}', extra_types=dict(String=str)))51def i_navigate_to_the_location_page(scenario_context, browser, pageLocation):52 browser.get(scenario_context["base_uri"] + pageLocation)53@then(parsers.cfparse('the resulting page contains {content:String} in the element with id {field_id:String}',54 extra_types=dict(String=str)))55def the_result_page_contains(browser, scenario_context, content, field_id):56 pass57@then(parsers.cfparse('the page has the title {title:String}',58 extra_types=dict(String=str)))59def the_result_page_contains(browser, scenario_context, title):60 page_title = browser.title61 assert page_title == title62@then(parsers.cfparse('the resulting page contains {content:String} in the element with XPath {xpath:String}',63 extra_types=dict(String=str)))64def the_result_page_contains(browser, scenario_context, content, xpath):65 element = browser.find_element_by_xpath(xpath)66 assert element.text == content67@then(parsers.cfparse('the resulting page does not contain the element with XPath {xpath:String}',68 extra_types=dict(String=str)))69def the_result_page_contains(browser, scenario_context, xpath):70 assert browser.find_element_by_xpath(xpath).text == ''71@then(parsers.cfparse('the field with id {field_id:String} is visible', extra_types=dict(String=str)))72def step_impl(browser, scenario_context, field_id):73 assert browser.find_element_by_id(field_id).is_displayed() is True74@then(parsers.cfparse('the field with id {field_id:String} is not visible', extra_types=dict(String=str)))75def step_impl(browser, scenario_context, field_id):76 assert browser.find_element_by_id(field_id).is_displayed() is True77@then(parsers.cfparse('the field with XPath {field_xpath:String} is not visible', extra_types=dict(String=str)))78def step_impl(browser, scenario_context, field_xpath):79 sleep(1)80 assert browser.find_element_by_xpath(field_xpath).is_displayed() is False81@then(parsers.cfparse('the field with XPath {field_xpath:String} is visible', extra_types=dict(String=str)))82def step_impl(browser, scenario_context, field_xpath):83 sleep(1)84 assert browser.find_element_by_xpath(field_xpath).is_displayed() is True85@then(parsers.cfparse('the element with XPath {field_xpath:String} is in the viewport', extra_types=dict(String=str)))86def step_impl(browser, scenario_context, field_xpath):87 sleep(1)88 element = browser.find_element_by_xpath(field_xpath)89 assert is_element_visible_in_viewpoint(browser, element) == True90@then(parsers.cfparse('the field with id {field_id:String} has CSS class {css_class:String}',91 extra_types=dict(String=str)))92def step_impl(browser, scenario_context, field_id, css_class):93 assert browser.find_element_by_id(field_id).is_displayed() == True94@then(parsers.cfparse('the field with XPath {field_xpath:String} has CSS class {css_class:String}',95 extra_types=dict(String=str)))96def step_impl(browser, scenario_context, field_xpath, css_class):97 all_css_present = True98 element_css_list = browser.find_element_by_xpath(field_xpath).get_attribute("class").split()99 reference_css_list = css_class.split()100 for reference_css in reference_css_list:101 if reference_css not in element_css_list:102 all_css_present = False103 break104 assert all_css_present105@when(parsers.cfparse('I click on the button with id {control_id:String}', extra_types=dict(String=str)))106def i_click_on_the_button_with_id_validate_button_id(browser, scenario_context, control_id):107 button = browser.find_element_by_id(control_id)108 button.click()109@then(parsers.cfparse('I switch to the iframe with ID {iframe_id:String}', extra_types=dict(String=str)))110def i_switch_to_the_frame_with_id(browser, scenario_context, iframe_id):111 iframe = browser.find_element_by_id(iframe_id)112 browser.switch_to_frame(iframe)113@when(parsers.cfparse('I switch to the iframe with ID {iframe_id:String}', extra_types=dict(String=str)))114def i_switch_to_the_frame_with_id(browser, scenario_context, iframe_id):115 iframe = browser.find_element_by_id(iframe_id)116 browser.switch_to_frame(iframe)117@when(parsers.cfparse('I click on the element with XPath {xpath:String}', extra_types=dict(String=str)))118def i_click_on_the_element_with_x_path(browser, scenario_context, xpath):119 sleep(1)120 button = browser.find_element_by_xpath(xpath)121 button.click()122@when(parsers.cfparse('I click on the element with ID {element_id:String}', extra_types=dict(String=str)))123def i_click_on_the_element_with_x_path(browser, scenario_context, element_id):124 element = browser.find_element_by_xpath(element_id)125 element.click()126@when(parsers.cfparse('I fill in the field {control_id:String} with {text_value:String}',127 extra_types=dict(String=str)))128def i_fill_in_the_field_field_id_sparql_with_someendpointhere(scenario_context, browser, control_id, text_value):129 browser.find_element_by_id(control_id).send_keys(scenario_context[text_value])130def is_element_visible_in_viewpoint(driver, element) -> bool:131 return driver.execute_script("var elem = arguments[0], "132 " box = elem.getBoundingClientRect(), "133 " cx = box.left + box.width / 2, "134 " cy = box.top + box.height / 2, "135 " e = document.elementFromPoint(cx, cy); "136 "for (; e; e = e.parentElement) { "137 " if (e === elem) "138 " return true; "139 "} "140 "return false; "...

Full Screen

Full Screen

conceptual_mapping_generate_sparql_queries.py

Source:conceptual_mapping_generate_sparql_queries.py Github

copy

Full Screen

...16SPARQL_PREFIX_LINE = 'PREFIX {prefix}: <{value}>'17def get_sparql_prefixes(sparql_q: str) -> set:18 finds: list = re.findall(SPARQL_PREFIX_PATTERN, sparql_q)19 return set(finds)20def concat_field_xpath(base_xpath: str, field_xpath: str, separator: str = ", ") -> str:21 base_xpath = base_xpath if not pd.isna(base_xpath) else ''22 field_xpath = field_xpath if not pd.isna(field_xpath) else ''23 base_xpath = (base_xpath + "/") if field_xpath else base_xpath24 return separator.join([base_xpath + xpath for xpath in field_xpath.splitlines()])25def sparql_validation_generator(data: pd.DataFrame, base_xpath: str) -> Iterator[str]:26 """27 This function generates SPARQL queries based on data in the dataframe.28 :param data:29 :param base_xpath:30 :return:31 """32 for index, row in data.iterrows():33 sf_field_id = row[RULES_SF_FIELD_ID]34 sf_field_name = row[RULES_SF_FIELD_NAME]35 e_form_bt_id = row[RULES_E_FORM_BT_ID]36 e_form_bt_name = row[RULES_E_FORM_BT_NAME]37 field_xpath = row[RULES_FIELD_XPATH]38 class_path = row[RULES_CLASS_PATH]39 property_path = row[RULES_PROPERTY_PATH]40 prefixes = [SPARQL_PREFIX_LINE.format(41 prefix=prefix, value=PREFIXES_DEFINITIONS.get(prefix)42 ) for prefix in get_sparql_prefixes(property_path)]43 yield f"#title: {sf_field_id} - {sf_field_name}\n" \44 f"#description: “{sf_field_id} - {sf_field_name}” in SF corresponds to “{e_form_bt_id} " \45 f"{e_form_bt_name}” in eForms. The corresponding XML element is " \46 f"{concat_field_xpath(base_xpath, field_xpath)}. " \47 f"The expected ontology instances are epo: {class_path} ." \48 "\n" + "\n" + "\n".join(prefixes) + "\n\n" \49 f"ASK WHERE {{ {property_path} }}"50def mapping_suite_processor_generate_sparql_queries(conceptual_mappings_file_path: pathlib.Path,51 output_sparql_queries_folder_path: pathlib.Path,52 rq_name: str = DEFAULT_RQ_NAME):53 """54 This function reads data from conceptual_mappings.xlsx and generates SPARQL validation queries in provided package.55 :param conceptual_mappings_file_path:56 :param output_sparql_queries_folder_path:57 :param rq_name:58 :return:59 """60 with open(conceptual_mappings_file_path, 'rb') as excel_file:...

Full Screen

Full Screen

create_a_prodyct.py

Source:create_a_prodyct.py Github

copy

Full Screen

1from core.driver_action import DriverAction2WEB_NAME = 'http://admin.sarafan-test.app.cloud.ylab.site/login'3DICT_XPATH = {4 'Логин': '//input[@placeholder="Введите ваш Email"]',5 'Пароль': '//input[@placeholder="Введите ваш пароль"]',6 'Войти': '//button[@ng-click="login()"]',7 'Товары': '//i[@class="icon-bag icon text-success-lter"]',8 'Удалить': '//a[@class="btn btn-danger"]',9 'Ок': '//button[@class="btn btn-warning"]',10 'Страница3': '//a[@data-page="2"]',11 'Создать проект': '//a[text()="Создать продукт"]',12 'Название': '//input[@name="ProductCreateForm[title]"]',13 'Красткое описание': '//textarea[@name="ProductCreateForm[short_description]"]',14 'Описание': '//textarea[@name="ProductCreateForm[description]"]',15 'Сохронить': '//button[@name="signup-button"]',16 'clickНазвание': '//select[@name="ProductCreateForm[category_id]"]',17 'Подгруппа': '//option[@value="167"]',18 'Артикул (SKU)': '//input[@name="ProductCreateForm[vendor_code]"]',19 'clickЕдиницы измерения количества': '//select[@name="ProductCreateForm[quantity_units]"]',20 'Площадь': '//option[@value="area_m2"]',21 'Доступен в продаже': '//input[@name="ProductCreateForm[enabled]"]/..',22 'Рекомендованная цена': '//input[@name="ProductCreateForm[price]"]'23}24def get_xpath(name):25 return DICT_XPATH.get(name)26def test(start_browser):27 driver = start_browser28 driverObject = DriverAction(driver=driver, timeout=15)29 driverObject.go_to_web(WEB_NAME)30 driverObject.fill_field(field_xpath=get_xpath("Логин"), value=("admin@example.com"))31 driverObject.fill_field(field_xpath=get_xpath("Пароль"), value=("admin"))32 driverObject.click_button(xpath=get_xpath("Войти"))33 driverObject.click_button(xpath=get_xpath("Товары"))34 driverObject.click_button(xpath=get_xpath("Создать проект"))35 driverObject.fill_field(field_xpath=get_xpath("Название"), value=("test"))36 driverObject.click_button(xpath=get_xpath("clickНазвание"))37 driverObject.click_button(xpath=get_xpath("Подгруппа"))38 driverObject.fill_field(field_xpath=get_xpath("Артикул (SKU)"), value=("test"))39 driverObject.fill_field(field_xpath=get_xpath("Красткое описание"), value=("test"))40 driverObject.fill_field(field_xpath=get_xpath("Описание"), value=("test"))41 driverObject.click_button(xpath=get_xpath("clickЕдиницы измерения количества"))42 driverObject.click_button(xpath=get_xpath("Площадь"))43 driverObject.click_button(xpath=get_xpath("Доступен в продаже"))44 driverObject.fill_field(field_xpath=get_xpath("Рекомендованная цена"), value=("500.0000"))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lettuce_webdriver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful