picoe / Eto

Cross platform GUI framework for desktop and mobile applications in .NET
Other
3.57k stars 325 forks source link

Coded tests with WinAppDriver/Selenium: cannot set the Name/Id of Eto controls #1871

Open borjafdezgauna opened 3 years ago

borjafdezgauna commented 3 years ago

I am trying to write coded tests for my Eto forms app.

I have set both the Id and Tag of the Eto controls I use (mostly TextBox) and, using WinAppDriver with the WPF version of the app, have writtten a simple UI test in Visual Studio.

I have only been able to find the window element using FindElementByName(), but neither this method nor any of its alternatives (ByTag(), ByAccessibilityId()) work with any of the controls.

I have inspected the UI controls using WinAppDriver UI Recorder v1.1 and it seems that the Name property of the controls is not set. Is there any workaround for this? Any way to set the value of the WPF controls' Name property from Eto?

//Sample UI test code with a reference to Appium.WebDriver

AppiumOptions appOptions = new AppiumOptions();
Windows<WindowsElement> session = new WindowsDriver<WindowsElement>(new Url(/*PATH TO EXE*/), appOptions;
var window = session.FindElementByName("Merit Editor"); //<- this works. It's the title displayed on the window
var textbox = session.FindElementByName("MyTextBox");//<-this fails, no matter which alternative I use
cwensley commented 3 years ago

Hey @borjafdezgauna, thanks for reporting the issue!

You're not doing anything wrong, Eto's ID and Tag properties are not tied to the backend platform in any way currently. However, it might not be a bad idea, though some investigation needs to be done to ensure it won't break anything.

As for a workaround, you could potentially add this style in your WPF startup before your app starts:

Eto.Style.Add<Eto.Forms.Control>(null, c => {
    c.LoadComplete += (sender, e) =>
    {
        if (!string.IsNullOrEmpty(c.ID) && c.Handler is Eto.Wpf.Forms.IWpfFrameworkElement handler)
        {
            handler.ContainerControl.Name = c.ID;
        }
    };
});

Hope this helps!

borjafdezgauna commented 3 years ago

Wow, that did the trick! I still need to fix a pair of things for my old WinForms project to work fully on Eto.Forms, but that was simply awesome! Thank you very much for the fast workaround 👍