How to confirm that a Switch has changed state, using WaitFor or WaitForElement?

Apologies for the newbie question... I have the code below that taps on a Switch if it is not already in the desired state. What I would like to do, is to add a WaitFor operation after doing the tap to confirm that the Switch does actually change state as a result of the tap. I want to use a WaitFor-style operation rather than just perform another Query to allow it some time to change state. I'm sure it cannot be that much different in syntax to the Query shown below, but I'm not quite sure how to do it. Can anybody help please?

        app.ScrollDownTo(
            styleIdForControl,
            null,
            ScrollStrategy.Gesture,
            timeToWait);
        AppResult[] matches = app.Query(styleIdForControl);
        Assert.IsTrue(
            matches.Length == 1,
            String.Format("WaitForElement for the '{0}' switch using Marked returned a number of matches other than 1", controlName));

        if (app.Query(c => c.Marked(styleIdForControl).Invoke("isChecked").Value<bool>()).First()
            != expectedValue)
        {
            app.Tap(styleIdForControl);

            // TODO - check that the switch does change state, using WaitFor or WaitForElement with expectedValue

        }

Best Answer

Answers

  • JohnHardmanJohnHardman GBUniversity mod

    @MalcolmSmith - Many thanks. Very helpful, and gives me the template to follow for other bits later on. Thanks, John H.

Sign In or Register to comment.