Search code examples
seleniumbddlettuce

Set browser window size in a step


Im trying to write tests for a responsive website, and I want to write a step like so:

Given I am in the desktop view

or

Given I am in the mobile view

How can I accomplish this in lettuce?

I've found this answer, but I cant figure out where to plug this, or if this is the best thing to do. Any help would be much appreciated.


Solution

  • This is how I finally accomplished this:

    SCREEN_SIZES = {
        "desktop": (1020, 768),
        "tablet": (768, 1024),
        "mobile": (320, 460)
    }
    
    @step(ur'I am in the "(?P<breakpoint>(desktop|tablet|mobile))" view')
    def set_viewport(step, breakpoint):
        """ Changes the resolution of the window """
        # Set the window size
        world.browser.driver.set_window_size(*SCREEN_SIZES[breakpoint])