1

I want to test the following application: https://romashov.tech/chat

This is the code of my MainPage:

using Atata;
using _ = Chat.Tests.Model.MainPage;

namespace Chat.Tests.Model
{
    [Url("")]
    public class MainPage : Page<_>
    {
        [FindById("send")]
        public Button<_> Send { get; private set; }
    }
}

When I run my test I have the following exception:

OpenQA.Selenium.UnhandledAlertException : unexpected alert open: {Alert text : Your name:} (Session info: chrome=75.0.3770.100)

How I can define it in page class? How I can put a nickname in this alert?

Dmitry Romashov
  • 174
  • 2
  • 14

1 Answers1

1

You can add a method (with name EnterAs or somehow else) to your page object which will handle prompt alert using WebDriver API:

using Atata;
using OpenQA.Selenium;

namespace Chat.UITests
{
    using _ = MainPage;

    public class MainPage : Page<_>
    {
        [FindFirst]
        public TextInput<_> Message { get; private set; }

        [FindByClass("send-button")]
        public Button<_> Send { get; private set; }

        public _ EnterAs(string name)
        {
            IAlert alert = Driver.SwitchTo().Alert();
            alert.SendKeys(name);
            alert.Accept();

            Driver.SwitchTo().DefaultContent();

            return Owner;
        }
    }
}

Then use it in the test this way:

Go.To<MainPage>().
    EnterAs("SomeUser").
    Message.Set("test message").
    Send.Click();
Yevgeniy Shunevych
  • 1,136
  • 6
  • 11