Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Accept alert message and switch back to main window #234

Open
contactkrsna1 opened this issue May 24, 2020 · 7 comments
Open

Accept alert message and switch back to main window #234

contactkrsna1 opened this issue May 24, 2020 · 7 comments

Comments

@contactkrsna1
Copy link

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

Thanks in Advance

@wakaleo
Copy link
Member

wakaleo commented May 24, 2020

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

@contactkrsna1
Copy link
Author

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

@wakaleo
Copy link
Member

wakaleo commented May 24, 2020

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

@contactkrsna1
Copy link
Author

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
Copy link
Member

wakaleo commented May 24, 2020

How would you do it with Selenium?

@contactkrsna1
Copy link
Author

contactkrsna1 commented May 24, 2020

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
Copy link
Member

wakaleo commented May 24, 2020

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants