Skip to content

[Bug] Cross-platform tests are not consistent  #148

@anpin

Description

@anpin

Describe the bug

Hi, first thanks for your effort with this project it really seems like I can optimize my UI tests with it. Second, I'm trying to test sample MAUI app and unfortunately my basic test is failing on Windows, but running fine on Android and I'm yet to try iOS.

image

 Message: 
OpenQA.Selenium.WebDriverException : An element could not be located on the page using the given search parameters.

  Stack Trace: 
RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
AppiumDriver`1.Execute(String driverCommandToExecute, Dictionary`2 parameters)
RemoteWebDriver.FindElement(String mechanism, String value)
RemoteWebDriver.FindElementByXPath(String xpath)
<>c__DisplayClass19_0.<XPath>b__0(ISearchContext context)
By.FindElement(ISearchContext context)
RemoteWebDriver.FindElement(By by)
<>c__DisplayClass32_0.<AttemptWaitForDriverElement>b__0(IWebDriver driver)
DefaultWait`1.Until[TResult](Func`2 condition)
BasePage.AttemptWaitForDriverElement(By locator, TimeSpan timeout, IWebDriver appDriver)
BasePage.VerifyPageShown(Nullable`1 timeout)
BasePage.ctor(RemoteWebDriver app, Nullable`1 traitTimeout)
BasePage.ctor()
MainPageBase.ctor()
WinMainPage.ctor()
MainPageTest.ctor(UiTestFixture fixtureBase) line 9

I've looked at the samples and figured I have to use different methods for constructing the test page depending on a platform, so I did this

public class MainPage : MainPageBase
{
    protected override By GetBy(string id) => By.Id(id);

    protected override IWebElement GetElement(string id) => FindElement(By.Id(id));
}

public class WinMainPage : MainPageBase
{
    
    protected override By GetBy(string id) => WindowsByExtras.AutomationId(id);
    protected override IWebElement GetElement(string id) => this.WindowsApp.FindElement(GetBy(id));
}

public abstract class MainPageBase : BasePage
{

    protected override By Trait => GetBy("MainPage");
    public IWebElement Button => GetElement("button");
    protected abstract By GetBy(string id);
    protected abstract IWebElement GetElement(string id) ;
}

What is the expected behavior?

Test is able to discover an element using its AutomationId across multiple platforms using a single method e.g. By.Id(automationId)

Package

No response

Other information

You can find repro here https://github.com/anpin/maui_ui_tests

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions