Giter VIP home page Giter VIP logo

elmasekar / unittest-scroll Goto Github PK

View Code? Open in Web Editor NEW
14.0 1.0 5.0 1 KB

A sample repo to help you scroll webpage in automation test in UnitTest on LambdaTest. Run your python automation test scripts on Lambdatest.

Home Page: https://www.lambdatest.com/unittest-testing/?utm_source=github&utm_medium=about&utm_campaign=unittest_scroll

Python 100.00%
unittest unittest-framework unittest-scroll automated-testing automation automation-testing lambdatest python-unittest scroll-webpage test-automation

unittest-scroll's Introduction

How to scroll webpage in automation test in UnitTest on LambdaTest

If you want to test scrolling of a webpage using an automation test in UnitTest on LambdaTest, you can use the follwing steps. You can refer to sample test repo here.

Steps

Scrolling to bottom of the page

To scroll to the bottom of the page, you can use the following line of code (refer to scroll.py for full code):

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

Infitinite scroll

If you want to scroll to a page with infinite loading, like social network ones, facebook etc. You can use the following code (refer to scroll.py for full code):

SCROLL_PAUSE_TIME = 0.5

# Get scroll height
last_height = driver.execute_script("return document.body.scrollHeight")

#controls how many times scrolled to bottom
scroll_pass = 0

#change to True for infinite scroll
while scroll_pass < 10:
    # Scroll down to bottom
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

    # Wait to load page
    time.sleep(SCROLL_PAUSE_TIME)

    # Calculate new scroll height and compare with last scroll height
    new_height = driver.execute_script("return document.body.scrollHeight")
    if new_height == last_height:
        break
    last_height = new_height 
    scroll_passs+=1

Run your test

python scroll.py

Links:

LambdaTest Community

unittest-scroll's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.