Skip to main content

Window and tab actions

I have an open browser

Opens a browser if none are open

Example

  Given I have an open browser
When I navigate to "https://todomvc.com/examples/react/dist"
Then I should have 1 open browser
I have no open browser

Closes all open browsers

Example

  Given I have no open browser
When I navigate to "https://todomvc.com/examples/react/dist"
Then I should have 1 open browser
I start a new browser

Starts a new browser session (or switches to exising one if it is already open).

Example

 Given I have no open browser
When I start a new browser
Then I should have 1 open browser
I close the[ current] browser

Closes the current browser session (or does nothing if one is not open).

Where

  • [ current] including the word current is optional and makes no difference, since v1.3.0

Example

  When I navigate to "https://todomvc.com/examples/react/dist"
And I close the current browser
And I navigate to "https://todomvc.com/examples/vue/"
And I close the browser
I start a browser for <name>

Starts a new browser session with the given name (closes any existing browser of that name first).

Where

  • <name> is a name assigned to the browser session

Example

  When I start a browser for React
And I navigate to "https://todomvc.com/examples/react/dist"
And I start a browser for Vue
And I navigate to "https://todomvc.com/examples/vue/"
Then I should have 2 open browsers
I switch to <name>

Switches to a named browser session (starts a new browser if one of that name is not already open). All browser actions performed after this will execute in the named session.

Where

  • <name> is the name of the browser session to switch to

Example

  When I start a browser for React
And I navigate to "https://todomvc.com/examples/react/dist"
And I start a browser for Vue
And I navigate to "https://todomvc.com/examples/vue/"
And I switch to React
Then the current URL should contain "react"
I close the browser for <name>

Closes a named browser session (does nothing if one of that name is not open).

Where

  • <name> is the name of the browser session to close

Example

  When I start a browser for React
And I navigate to "https://todomvc.com/examples/react/dist"
And I close the browser for React
I start a new browser <tab|window>

Starts a new browser tab or window (or starts a new browser session if one is not open).

Where

  • <tab|window> is either tab or window

Example

  When I navigate to "https://google.com"
And I start a new browser tab
And I navigate to "https://todomvc.com/examples/react/dist"
I switch to <tab|window> <occurrence>

Switches to a previously opened tab or window occurrence.

Where

  • <tab|window> is either tab or window
  • <occurrence> is the tab or window occurrence to switch to (1st opened is occurrence 1, 2nd is 2, ..)

    • Note: the occurrence number of the default tab/window in a new browser session is 0

Example

  When I navigate to "https://google.com"
And I start a new browser tab
And I navigate to "https://todomvc.com/examples/react/dist"
And I switch to window 1
Then the page title should contain "Google"
I close <tab|window> <occurrence>

Closes a previously opened tab or window occurrence.

Where

  • <tab|window> is either tab or window
  • <occurrence> is the tab or window occurrence to close to (1st opened is occurrence 1, 2nd is 2, ..)

    • Note: you cannot close the default tab/window opened by starting a new browser session with this DSL. Use I close the[ current] browser instead in that case.

Example

  When I navigate to "https://google.com"
And I start a new browser tab
And I navigate to "https://todomvc.com/examples/react/dist"
And I close tab 1
Then the page title should contain "Google"

If used in conjunction with @Try, will switch to the parent window regardless of whether or not a tab or window was closed (since 3.12.4).

I switch to the child <tab|window>

Switches to the most recently opened child tab or window (without closing the parent window)

Where

  • <tab|window> is either tab or window

Example

  Given the new window button can be located by name "newbrowserwindow123"
When I navigate to "https://nxtgenaiacademy.com/multiplewindows/"
And I click the new window button
And I switch to the child window
I close the child <tab|window>

Closes the currently active child tab or window and passes control back to the parent window.

Where

  • <tab|window> is either tab or window

Example

  Given the new tab button can be located by name "newbrowsertab453"
When I navigate to "https://nxtgenaiacademy.com/multiplewindows/"
And I click the new tab button
And I switch to the child tab
And I close the child tab

If used in conjunction with @Try, will switch to the parent window regardless of whether or not a child window was closed (since 3.12.4).

I switch to child <tab|window> <occurrence>

Switches to a child tab or window occurrence (without closing the parent window) or reports and error if there is no child window.

Where

  • <tab|window> is either tab or window
  • <occurrence> is the tab or window occurrence to switch to (1st opened is occurrence 1, 2nd is 2, ..)

Example

  Given the new window button can be located by name "newbrowserwindow123"
When I navigate to "https://nxtgenaiacademy.com/multiplewindows/"
And I click the new window button
And I switch to child window 1
I close child <tab|window> <occurrence>

Closes a child tab or window occurrence and passes control back to the parent window.

Where

  • <tab|window> is either tab or window
  • <occurrence> is the tab or window occurrence to close (1st opened is occurrence 1, 2nd is 2, ..)

Example

  Given the new tab button can be located by name "newbrowsertab453"
When I navigate to "https://nxtgenaiacademy.com/multiplewindows/"
And I click the new tab button
And I switch to child tab 1
And I close child tab 1

If used in conjunction with @Try, will switch to the parent window regardless of whether or not a child window was closed (since 3.12.4).

I switch to the parent <tab|window>

Switches to the parent window of the currently active window (without closing the currently active window) or stays on the root window if there is no other window open.

Where

  • <tab|window> is either tab or window

Example

  Given the new window button can be located by name "newbrowserwindow123"
When I navigate to "https://nxtgenaiacademy.com/multiplewindows/"
And I click the new window button
And I switch to child window 1
And I switch to the parent window
I switch to the root <tab|window>

Switches to the topmost parent window (without closing the currently active window) or stays on the current window if it is the root window.

Where

  • <tab|window> is either tab or window

Example

  Given the new window button can be located by name "newbrowserwindow123"
When I navigate to "https://nxtgenaiacademy.com/multiplewindows/"
And I click the new window button
And I switch to child window 1
And I switch to the root window
I <maximize|maximise> the window

Maximizes the currently active browser window to fill the entire screen area.

Where

  • <maximize|maximise> is either maximize or maximise (makes no difference)

Example

  When I navigate to "https://todomvc.com/examples/react/dist"
And I maximize the window
I resize the window to width <w> and height <h>

Resizes the currently active browser window to the given dimensions.

Where

  • <w> is the width in pixels
  • <h> is the height in pixels

Example

  When I navigate to "https://todomvc.com/examples/react/dist"
And I resize the window to width 1280 and height 720
I send "<keys>"

Sends a sequence of keys to the browser (for emulating keyboard shortcuts).

Where

  • <keys> is a , or + (since v2.53.0) separated list of keys to send.

    • Keys can be single keyboard characters or any supported key constants
    • Note: Keys behave differently on different platforms

Example

   When I navigate to "https://google.com"
And I send "COMMAND+t"
I set the window position to x <x> and y <y>

Positions the currently active browser window to the given co-ordinates.

Where

  • <x> is the x co-ordinate
  • <y> is the y co-ordinate

Example

  When I navigate to "https://todomvc.com/examples/react/dist"
And I set the window position to x 40 and y 20
I send "<keys>"

Sends a sequence of keys to the browser (for emulating keyboard shortcuts).

Where

  • <keys> is a , or + (since v2.53.0) separated list of keys to send.

    • Keys can be single keyboard characters or any supported key constants
    • Note: Keys behave differently on different platforms

Example

   When I navigate to "https://google.com"
And I send "COMMAND+t"