serenity-bdd / serenity-cucumber

Cucumber integration for the Serenity BDD Reporting library
Other
78 stars 74 forks source link

Accept alert message and switch back to main window #234

Open contactkrsna1 opened 4 years ago

contactkrsna1 commented 4 years ago

Hi, How to achieve the below lines using serenity getDriver().switchTo().alert().accept(); getDriver().switchTo().defaultContent();

Thanks in Advance

wakaleo commented 4 years ago

The code you have here will behave identically in Serenity and Selenium

contactkrsna1 commented 4 years ago

Acually i want to use getAlert().accept(); and then move to main window. How this is done using serenity api

wakaleo commented 4 years ago

Serenity just wraps Selenium, so you would do the same as in Selenium

contactkrsna1 commented 4 years ago

Hi, Oops , i did a lot of research on Serenity and I liked it. But I am not able to reach my goal

I have a feature file with 2 scenarios Scenario 1

  1. navigate to url (is a deep link)
  2. redirect to login page where a alert message pops up 3 accepted the alert pop up 4 enter username 5 entered password 6 clicked login button After login I will go(went to) the deep link page Scenario 2
  3. given that I am on deep link page
  4. search for a word

Now here, I am getting an error saying that "org.openqa.selenium.NoSuchWindowException: no such window: target window already closed" and none of the elements are found.

Thanks In Advance

wakaleo commented 4 years ago

How would you do it with Selenium?

contactkrsna1 commented 4 years ago

Hi, in selenium we use get/navigate method

But for serenity approach below is the code

In the second scenario,

I have step defination

@Steps
DeeplinkStep deeplinksteps;

@Given("I am on the deep link page")
public void deeplink() {
    deeplinksteps.open();

}

DeeplinkStep

DeeplinkPage deeplinkPage;

@Step
public void open() {
    deeplinkPage.open();
}

Deeplink page object

@NamedUrls( { @NamedUrl(name = "page", url = "http://localhost:8080/editor.html/{1}") } ) public class Deeplink extends PageObject {

public void open() {
    open("page", withParameters("index.html"));
}

}

wakaleo commented 4 years ago

You can use getDriver() inside a PageObject or UIStepInteraction class for this