3

How to open a new tab in the Chrome browser?

  • I can open at the beginning of a test:

              AtataContext.Configure()
                  .UseChrome()
                  .WithArguments("new tab")
    
  • I tried to press the shortcuts "CTRL + T:

    [PressKeys("control" + "t", TriggerEvents.AfterClick)]

OR

.Press("^t");

1 Answers1

3

Update for Atata v2.2+

New methods were added in Atata v2.2.0 to Go class:

  • Go.ToNewWindow<TPage>(...)
  • Go.ToNewWindowAsTab<TPage>(...)

Solution for older Atata version

Apparently CTRL+T combination doesn't work anymore for chromedriver. But we can use window.open() JavaScript which also opens new tab.

AtataContext.Current.Driver.ExecuteScript("window.open()");

// You also need to switch to newly opened tab.
Go.ToNextWindow<OrdinaryPage>(); // Set the type of your page object instead of OrdinaryPage.
Go.ToUrl("/someurl"); // Set URL.

You can also extract this code block to a method:

public static TPage CreateAndSwitchToNewTab<TPage>(string url)
    where TPage : Page<TPage>
{
    AtataContext.Current.Driver.ExecuteScript("window.open()");

    var page = Go.ToNextWindow<TPage>();
    Go.ToUrl(url);

    return page;
}

And use it in tests in a form of:

CreateAndSwitchToNewTab<ProductsPage>("/products")
    .PageTitle.Should.Contain("Products");
Yevgeniy Shunevych
  • 1,136
  • 6
  • 11