stirno / FluentAutomation

Simple Fluent API for UI Automation
http://fluent.stirno.com
MIT License
234 stars 98 forks source link

In v3, when will the Multi-browser Win32 events be implemented #113

Open dmcquiston opened 10 years ago

dmcquiston commented 10 years ago

Started testing the v3 library and the multi-browser functionality (parallel...nice!!!) is working great. I had a test that called

I.Press("{ENTER}");

I received a NotImplementedException. When do you think this functionality will be implemented?

Also, I am really new to Sizzle selectors, do you know where I can find detailed beginner documentation on how to form these properly. Having some trouble.

I should also mention that our company is running IE8 as a standard and I know that there are some differences about how these selectors/jQuery works in IE8 as well. My specific/current problem is that the "input[type=submit]" selector is not working for IE8. Previously I was using the I.Press("{ENTER}"); which worked in all browsers. I changed that over to the I.Click method.

Any guidance would be most appreciated.

stirno commented 10 years ago

The Win32 related events don't work with multiple browsers because we can't guarantee the focused window at the time of execution (users/other apps/etc can steal focus).

For v3.1 I intend to add a proper, fluent controlled, Keys collection and non-win32 based support for these events. For now, when using Selenium you can do this:

I.Append(OpenQA.Selenium.Keys.Enter).To("#textbox");

This uses Selenium to send the enter keypress to any input control that supports it. I use Append instead of Enter because Enter attempts to clear the field of contents, many field types don't support that operation so I think this should work more consistently until we get 1st class support for these operations that don't rely on Win32.

You can probably read through the sizzle selector doc page to learn about some of the special bits that Sizzle brings to the table but mostly its the CSS3 reference spec implementation. Theres a lot of documents out there, not terribly well organized but worth searching and digging into.

As for the selector issue with IE8, usually this is related to IE's compatibility mode being enabled -- basically attribute based selectors match on the incorrect data in this scenario. For many situations you can use the jQuery pseudo selectors to get around this. In the case of looking for the submit button, you can use :submit pseudo selector that handles this particular wrinkle for you.

dmcquiston commented 10 years ago

Thanks for getting back so quickly. I tried what you recommended:

I.Append(OpenQA.Selenium.Keys.Enter).To("#textbox");

And I was able to get it to work in FF and Chrome without issue. However, in IE8, I had to throw an additional Thread.Sleep(10000); in the validation method on my target page, see Scenario below. If I do not include that Thread.Sleep, it will throw an exception in IE8 FluentAutomation.Exceptions.FluentException : Waited [5000ms] for action. When I was using the Win32 Enter key, I wasn't receiving such an Exception.

Scenario: starting point, login page => enter uid, pwd, click submit (hit enter key in a text box w/in form) => finishing point, verify login page.

Regarding the :submit pseudo selector, the code looks like the following and still does not work (it doesn't get clicked and just sits waiting for the next action, which is the page switching:

I.Click(":submit");

When I try to find the element with I.Find(":submit"), it did find the element. But trying to pass it in didn't work...again using IE8. Compatibility Mode is not enabled from what I can see. Seems like the Click method for IE8 may be experiencing issues.

Let me know if there is something that I am missing here. If this is a true issue, I'd be happy to walk you through what is happening on my machine. Thanks again for your quick responses.

dmcquiston commented 10 years ago

any idea on what may be the problem, see above comment

stirno commented 10 years ago

Oops, missed your response. Paul or I will try and repro on a VM with IE8 soon. The InnerException message when using the Append method would be helpful to have.

dmcquiston commented 10 years ago

No worries. There were no inner exceptions, but here were the exceptions (and stacks) that I received:

Exception Message: Waited [5000ms] for action: Expected DOM Element [body] text to match expression [t => t.Contains(value(Platform.IntegrationTests.Pages.DeveloperPortalPage+<>c__DisplayClass2).name)] but it was actually [].

Exception Stack: at Platform.IntegrationTests.Pages.DeveloperPortalPage.ValidateLoggedIn(String name) in c:...\Automation\Tests\IntegrationTests\Platform.IntegrationTests\Pages\DeveloperPortalPage.cs:line 22 at Platform.IntegrationTests.LoginTests.LoginSuccess() in c:...\Automation\Tests\IntegrationTests\Platform.IntegrationTests\LoginTests.cs:line 26

---OR---

Exception Message: Unexpected exception in WaitUntil -- Element is no longer valid

Exception Stack:
at Platform.IntegrationTests.Pages.DeveloperPortalPage.ValidateLoggedIn(String name) in c:\LocalStorage\Development\Projects\ABBNET\trunk\Automation\Tests\IntegrationTests\Platform.IntegrationTests\Pages\DeveloperPortalPage.cs:line 22 at Platform.IntegrationTests.LoginTests.LoginSuccess() in c:\LocalStorage\Development\Projects\ABBNET\trunk\Automation\Tests\IntegrationTests\Platform.IntegrationTests\LoginTests.cs:line 26 Result StackTrace: at Platform.IntegrationTests.LoginTests.LoginSuccess() in c:\LocalStorage\Development\Projects\ABBNET\trunk\Automation\Tests\IntegrationTests\Platform.IntegrationTests\LoginTests.cs:line 34

There are no InnerExceptions on either of those.

stirno commented 10 years ago

Can you post the code being used for the Wait? Depending on the complexity of the page, selecting against the tag can be.. interesting.

Also, "Element is no longer valid" usually happens when the test stores a reference to an element using I.Find() and then attempts to use it later, and Selenium is no longer willing to play nice with it.

dmcquiston commented 10 years ago

Sorry I haven't gotten back to you, been busy.

Here is my code. We are using the PageObject as recommended for non-brittle tests:

Login Page:

public class LoginPage : PageObject<LoginPage>
{
    public LoginPage(FluentTest test)
        : base(test)
    {
        Url = "{login_url}";
        At = () => I.Assert.Exists("#frmDefault");
    }

    public DeveloperPortalPage LoginSuccess(string userName, string password)
    {
        Login(userName, password);
        return this.Switch<DeveloperPortalPage>();
    }

    private void Login(string userName, string password)
    {
        I.Enter(userName).In("input[name=USER]");
        I.Enter(password).In("input[name=PASSWORD]");
        I.Append(OpenQA.Selenium.Keys.Enter).To("input[name=PASSWORD]"); 
    }
}

Portal page that the login page gets sent to after login:

public class DeveloperPortalPage : PageObject<DeveloperPortalPage>
{
    public DeveloperPortalPage(FluentTest test)
        : base(test)
    {
        At = () => I.Assert.Exists(PortalPageHeader);
    }

    public DeveloperPortalPage ValidateLoggedIn(string name)
    {
        Thread.Sleep(10000);
        I.Assert.Text(t => t.Contains(name)).In(PortalPageHeader);
        return this;
    }

    private const string PortalPageHeader = "body";
}

and this is the unit test, validates that there is the text "Logged in" on the DeveloperPortal page:

[TestFixture]
public class LoginTests : FluentTest
{
    [Test]
    public void LoginSuccess()
    {
        try
        {
            SeleniumWebDriver.Bootstrap(Browser.InternetExplorer);

            new LoginPage(this)
                .Go()
                .LoginSuccess(_userName, _password)
                .ValidateLoggedIn("Logged in");
        }
        catch (Exception ex)
        {
            string t = ex.Message;
            Assert.Fail("Exception Message: {0}{2}{2}Exception Stack: {1}", ex.Message, ex.StackTrace, Environment.NewLine);
        }
    }
}
dmcquiston commented 10 years ago

Awesome news releasing 3.0, congrats! I know you have been busy, and I haven't been the most responsive but please let me know if there is anything else I can provide to solve this issue. Thanks!

dmcquiston commented 10 years ago

Any luck trying to reproduce this issue?