Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Find<T>() where T doesn't require a constructor that takes a By search configuration parameter #73

Closed
icnocop opened this issue Apr 7, 2016 · 5 comments
Assignees

Comments

@icnocop
Copy link
Owner

icnocop commented Apr 7, 2016

In v1.0.6 of CUITe, I am able to do the following:

            ApplicationUnderTest applicationUnderTest = ApplicationUnderTest.Launch(exeFilePath);

            StartTrialWindow startTrialWindow = new StartTrialWindow(applicationUnderTest.Process.MainWindowHandle);

            startTrialWindow.StartButton.Click();
    public class StartTrialWindow : CUITe_WinWindow
    {
        public StartTrialWindow(IntPtr windowHandle) : base("Name=Start Trial")
        {
            UITestControl mainWindow = UITestControlFactory.FromWindowHandle(windowHandle);

            this.Wrap(mainWindow);
        }

       public CUITe_WinButton StartButton { get { return Get<CUITe_WinButton>("Name~Start"); } }
    }

However when migrating to CUITe v2.0.265, I expected to do the following:

ApplicationUnderTest applicationUnderTest = ApplicationUnderTest.Launch(exeFilePath);

StartTrialWindow startTrialWindow = applicationUnderTest.Find<StartTrialWindow>();

startTrialWindow.StartButton.Click();
    public class StartTrialWindow : WinWindow
    {
        public StartTrialWindow() : base(By.Name("Start Trial"))
        {
        }

       public WinButton StartButton { get { return Find<WinButton>(By.NameContains("Start")); } }
    }

But instead, I get the following run-time exception:

System.ArgumentException: No constructor for type 'StartTrialWindow' contains arguments in the following order:
  1. By - Search configuration
at CUITe.Controls.ControlBaseFactory.Create(Type controlType, By searchConfiguration)
   at CUITe.Controls.ControlBaseFactory.Create[T](By searchConfiguration)
   at Microsoft.VisualStudio.TestTools.UITesting.UITestControlExtensions.Find[T](UITestControl self, By searchConfiguration)
   at ...
@icnocop
Copy link
Owner Author

icnocop commented Apr 7, 2016

As a work-around, I have to do StartTrialWindow startTrialWindow = new StartTrialWindow(); but this doesn't limit the search to only windows created by the application under test.

@FantasticFiasco
Copy link
Collaborator

I would love to remove or deprecate ApplicationUnderTest, CUITe_WinWindow and the other related classes. I think PageObjects and ScreenObjects are its successors.

Is there anything page objects and screen objects cannot do that you could do prior with the object repository?

With the code you have, what happens when you inherit from Screen instead of WinWindow?

@icnocop
Copy link
Owner Author

icnocop commented Apr 7, 2016

I get a compilation error if I inherit from Screen instead of WinWindow:

public class StartTrialWindow : Screen
{
    public StartTrialWindow() : base(By.Name("Start Trial"))
    {
    }

    public WinButton StartButton { get { return Find<WinButton>(By.NameContains("Start")); } }
}

'Screen' does not contain a constructor that takes 1 arguments

I expected to be able to set the title of the window (and any other search properties) in the constructor.
I think this would be important if there are multiple windows displayed by the application under test so the expected window would actually be found.

I get some other compiler errors because there are places where I assert that the window does not exist:

'StartTrialWindow' does not contain a definition for 'Exists' and no extension method 'Exists' accepting a first argument of type 'StartTrialWindow' could be found

It seems Page and PageComponent are only for HTML and Silverlight applications, but I am testing a Win32 application.

@FantasticFiasco
Copy link
Collaborator

I'll start to look into it. Thanks for pointing it out.

@icnocop
Copy link
Owner Author

icnocop commented Apr 10, 2016

I created a pull request for your review, whenever you have the time. Thank you! 😄

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

No branches or pull requests

2 participants