How to use location_once_scrolled_into_view method in Selene

Best Python code snippet using selene_python

product_search.py

Source:product_search.py Github

copy

Full Screen

1"""2@author: Juraj Holub (xholub40)3@project ITS project4@date April 20205"""6from selenium.webdriver.common.by import By7from behave import *8from steps import browser9from selenium.webdriver.common.action_chains import ActionChains10use_step_matcher("re")11@given("the web browser is at the eshop home page")12def step_impl(context):13 browser.setup(context)14 context.driver.get("http://mys01.fit.vutbr.cz:8033/")15 context.driver.set_window_size(1299, 741)16@when('the user chooses to show all "Laptops & Notebooks" from the product categories bar')17def step_impl(context):18 context.driver.find_element(By.LINK_TEXT, "Laptops & Notebooks").click()19 context.driver.find_element(By.LINK_TEXT, "Show All Laptops & Notebooks").click()20@then('the all "Laptops & Notebooks" products shows on the eshop')21def step_impl(context):22 elements = context.driver.find_elements(By.CSS_SELECTOR, ".product-layout:nth-child(1) > .product-thumb")23 assert len(elements) > 024 elements = context.driver.find_elements(By.CSS_SELECTOR, ".product-layout:nth-child(2) > .product-thumb")25 assert len(elements) > 026 elements = context.driver.find_elements(By.CSS_SELECTOR, ".product-layout:nth-child(3) > .product-thumb")27 assert len(elements) > 028 elements = context.driver.find_elements(By.CSS_SELECTOR, ".product-layout:nth-child(5) > .product-thumb")29 assert len(elements) > 030 elements = context.driver.find_elements(By.CSS_SELECTOR, ".product-layout:nth-child(4) > .product-thumb")31 assert len(elements) > 032 browser.teardown(context)33@given('the all "Laptops & Notebooks" products shows on the eshop')34def step_impl(context):35 context.execute_steps("""36 Given the web browser is at the eshop home page 37 When the user chooses to show all "Laptops & Notebooks" from the product categories bar38 """)39@when('the user changes the items view style from "Grid" into "List"')40def step_impl(context):41 context.driver.find_element(By.ID, "list-view").click()42@then("the items aligns below")43def step_impl(context):44 first_layout = context.driver.find_elements(By.CSS_SELECTOR, ".product-layout:nth-child(1) > .product-thumb")45 first_y = first_layout[0].location['y'] + first_layout[0].rect['height']46 second_layout = context.driver.find_elements(By.CSS_SELECTOR, ".product-layout:nth-child(2) > .product-thumb")47 second_y = second_layout[0].location['y'] + first_layout[0].rect['height']48 assert first_y < second_y49 browser.teardown(context)50@given('the all "Laptops & Notebooks" products align belows')51def step_impl(context):52 context.execute_steps("""53 Given the web browser is at the eshop home page 54 When the user chooses to show all "Laptops & Notebooks" from the product categories bar55 """)56@when('the user sort products by "Price\(High > Low\)"')57def step_impl(context):58 first_layout = context.driver.find_elements(By.CSS_SELECTOR, ".product-layout:nth-child(1)")59 parent_x1 = first_layout[0].location_once_scrolled_into_view['x']60 parent_x2 = first_layout[0].location_once_scrolled_into_view['x'] + first_layout[0].rect['width']61 parent_y1 = first_layout[0].location_once_scrolled_into_view['y']62 parent_y2 = first_layout[0].location_once_scrolled_into_view['y'] + first_layout[0].rect['height']63 macbook_layout = context.driver.find_elements(By.LINK_TEXT, "MacBook Pro")64 child_x1 = macbook_layout[0].location_once_scrolled_into_view['x']65 child_x2 = macbook_layout[0].location_once_scrolled_into_view['x'] + macbook_layout[0].rect['width']66 child_y1 = macbook_layout[0].location_once_scrolled_into_view['y']67 child_y2 = macbook_layout[0].location_once_scrolled_into_view['y'] + macbook_layout[0].rect['height']68 context.mac_book_is_first = parent_x1 <= child_x1 and parent_x2 >= child_x2 and parent_y1 <= child_y1 and parent_y2 >= child_y269@then('the reordered products starts with the "MacBook Pro"')70def step_impl(context):71 assert context.mac_book_is_first72 browser.teardown(context)73@when('the user select the "MackBook Air" product')74def step_impl(context):75 context.driver.find_element(By.LINK_TEXT, "MacBook Air").click()76@then('the "MackBook Air" detail page appears')77def step_impl(context):78 assert context.driver.current_url == 'http://mys01.fit.vutbr.cz:8033/index.php?route=product/product&path=18&product_id=44'...

Full Screen

Full Screen

position_and_size_tests.py

Source:position_and_size_tests.py Github

copy

Full Screen

1# Licensed to the Software Freedom Conservancy (SFC) under one2# or more contributor license agreements. See the NOTICE file3# distributed with this work for additional information4# regarding copyright ownership. The SFC licenses this file5# to you under the Apache License, Version 2.0 (the6# "License"); you may not use this file except in compliance7# with the License. You may obtain a copy of the License at8#9# http://www.apache.org/licenses/LICENSE-2.010#11# Unless required by applicable law or agreed to in writing,12# software distributed under the License is distributed on an13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14# KIND, either express or implied. See the License for the15# specific language governing permissions and limitations16# under the License.17import pytest18from selenium.webdriver.common.by import By19def testShouldBeAbleToDetermineTheLocationOfAnElement(driver, pages):20 pages.load("xhtmlTest.html")21 location = driver.find_element(By.ID, "username").location_once_scrolled_into_view22 assert location["x"] > 023 assert location["y"] > 024@pytest.mark.parametrize('page', (25 'coordinates_tests/simple_page.html',26 'coordinates_tests/page_with_empty_element.html',27 'coordinates_tests/page_with_transparent_element.html',28 'coordinates_tests/page_with_hidden_element.html'),29 ids=('basic', 'empty', 'transparent', 'hidden'))30def testShouldGetCoordinatesOfAnElement(page, driver, pages):31 pages.load(page)32 element = driver.find_element(By.ID, "box")33 _check_location(element.location_once_scrolled_into_view, x=10, y=10)34 _check_location(element.location, x=10, y=10)35def testShouldGetCoordinatesOfAnInvisibleElement(driver, pages):36 pages.load("coordinates_tests/page_with_invisible_element.html")37 element = driver.find_element(By.ID, "box")38 _check_location(element.location_once_scrolled_into_view, x=0, y=0)39 _check_location(element.location, x=0, y=0)40def testShouldScrollPageAndGetCoordinatesOfAnElementThatIsOutOfViewPort(driver, pages):41 pages.load("coordinates_tests/page_with_element_out_of_view.html")42 element = driver.find_element(By.ID, "box")43 windowHeight = driver.get_window_size()["height"]44 _check_location(element.location_once_scrolled_into_view, x=10)45 assert 0 <= element.location_once_scrolled_into_view["y"] <= (windowHeight - 100)46 _check_location(element.location, x=10, y=5010)47@pytest.mark.xfail_marionette48def testShouldGetCoordinatesOfAnElementInAFrame(driver, pages):49 pages.load("coordinates_tests/element_in_frame.html")50 driver.switch_to_frame(driver.find_element(By.NAME, "ifr"))51 element = driver.find_element(By.ID, "box")52 _check_location(element.location_once_scrolled_into_view, x=25, y=25)53 _check_location(element.location, x=10, y=10)54@pytest.mark.xfail_marionette55def testShouldGetCoordinatesOfAnElementInANestedFrame(driver, pages):56 pages.load("coordinates_tests/element_in_nested_frame.html")57 driver.switch_to_frame(driver.find_element(By.NAME, "ifr"))58 driver.switch_to_frame(driver.find_element(By.NAME, "ifr"))59 element = driver.find_element(By.ID, "box")60 _check_location(element.location_once_scrolled_into_view, x=40, y=40)61 _check_location(element.location, x=10, y=10)62def testShouldGetCoordinatesOfAnElementWithFixedPosition(driver, pages):63 pages.load("coordinates_tests/page_with_fixed_element.html")64 element = driver.find_element(By.ID, "fixed")65 _check_location(element.location_once_scrolled_into_view, y=0)66 _check_location(element.location, y=0)67 driver.find_element(By.ID, "bottom").click()68 _check_location(element.location_once_scrolled_into_view, y=0)69 assert element.location["y"] > 070def testShouldCorrectlyIdentifyThatAnElementHasWidthAndHeight(driver, pages):71 pages.load("xhtmlTest.html")72 shrinko = driver.find_element(By.ID, "linkId")73 size = shrinko.size74 assert size["width"] > 075 assert size["height"] > 076def _check_location(location, **kwargs):77 try:78 # python 2.x79 expected = kwargs.viewitems()80 actual = location.viewitems()81 except AttributeError:82 # python 3.x83 expected = kwargs.items()84 actual = location.items()...

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 Selene 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