0

I have an automated Appium test for a UWP Windows application. When a button is clicked it will fire an API call and then display something once the call has completed. Depending on how fast my test runs and the speed of the network call, immediately after clicking the button, I will be in one of two states:

  1. A progress spinner will be visible
  2. The progress spinner will not be visible (may have been and gone) and the result will be displayed.

I have written verbose code that checks for each of these conditions sequentially, however, it would nicer to combine it into one wait, that checks for either condition. It seems other language bindings have a way to combine expressions with an or (e.g. this answer for Java).

var wait = new WebDriverWait(_session.Driver, TimeSpan.FromSeconds(10));

// would like to combine the following conditions
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(By.XPath("some Xpath"))));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("some other Xpath")));
Rossco
  • 742
  • 7
  • 19

1 Answers1

2

Inside the wait.until method you can define your own code function. Your two lines are checking one object is visible, and one object is not visible - and your question is you want that as an either (an or) so it's a bit custom.

        var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
        wait.Until(d => {
                if ((!d.FindElement(By.XPath("some xpath")).Displayed) || (d.FindElement(By.XPath("some other Xpath")).Displayed))
                   return true;
                else
                   return false;
        });

If you want your test to have one line, you'll just need to squirrel this away in a method in a POM class or base class.

However, if you're doing functional testing, i'd advise you keep it as two lines. IF it's one line, you'll get one fail and not know which check failed. If it's two lines you'll be told which object is misbehaving.

Also worth noting that If it's not there already, I'm not sure you're going to find much new stuff coming in the SeleniumExtras. Selenium Extras is a spin off library/project because in c# you're expected to know how to use lambdas. In selenium 3.11:

  • Marked .NET ExpectedConditions obsolete. Using the ExpectedConditions class provides no benefit over directly using lambda functions (anonymous methods) directly in one’s code

Looking at the github project, it was last updated 2 years ago.

They probably will be updated and kept in line going forwards, there's no reason to believe they won't be - but it's always good to have your own approach so you can be more flexible as you need.

RichEdwards
  • 2,205
  • 2
  • 2
  • 15