DEV Community

Tony Colston
Tony Colston

Posted on

1 1

responsive testing with Selenium and Python

Here is a quick script to show how you could capture images to do some responsive testing. The test is super quick and you end up with 4 images that you can look at to see if things are put on the page correctly.

I chose some break points that made sense to me. I think if you are using bootstrap your breakpoints might be different. Just change the width to whatever you want to check.

from selenium import webdriver
from selenium.webdriver.common.by import By

import time
driver = None

def checkit(w,filename):
    driver.set_window_size(w,HEIGHT)
    driver.get("https://getbootstrap.com/docs/4.0/examples/blog/")
    driver.save_screenshot(filename)

try:
    cpath = "e:\\projects\\headless\\chromedriver.exe"
    driver = webdriver.Chrome(cpath)

    HEIGHT = 768

    checkit(600,"test0.png")
    checkit(900,"test1.png")
    checkit(1200,"test2.png")
    checkit(1800,"test3.png")

finally:
    if driver is not None:
        driver.quit()

Enter fullscreen mode Exit fullscreen mode


`
If you have read the other posts I have done this code is slightly different.

I made a function called checkit to make the code more readable.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (1)

Collapse
 
mahboobnur profile image
Syed Mahboob Nur

Thats really great

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay