简体   繁体   中英

Using I.Expect.Text with fluentautomation

Does I.Expect.Text(" sometext ") require the In method with specified selector?

I ask ask as some tests I've inherited don't have the In method appended, and our tests pass, even when I know that the supplied text does not exist on page.

I have looked at the docs, re http://fluent.stirno.com/docs/#asserts-text - and it doesn't seem clear (to me anyhow) that the In selector HAS to be present. I am assuming that it needs to be present.

I guess what I am asking is that if the In method does need to be appended in order for the assertion to work correctly, how would I fluently state does "sometext" appear in any div or p tag or class on page, or should I be using Ids throughout. I see something useful at https://github.com/stirno/FluentAutomation/issues/133 .

So something like the following that could be wrapped into an extension method on AssertSyntaxProvider, however it appears heavy-handed/clunky?

        var texts = I.Find("html").Elements.Select(el => el.Item2().Text);
        I.Assert.True(() => texts.Any(t => t.Contains("statement1")));
        I.Assert.True(() => texts.Any(t => t.Contains("statement2")));
        I.Assert.True(() => texts.Any(t => t.Contains("statement3")));

Help appreciated!!

Last thing - this is an awesome Library!!!

Yes, In is required as its the executing block of the chain. Its been awhile since I've been able to focus on expanding FluentAutomation so It hasn't become any nicer to make assertions against multiple elements.

I do have a nice plan for this that I just haven't had time to implement.

As for your specific test, You're close to what I'd use for now:

I.Open("http://fluent.stirno.com");
var elements = I.FindMultiple("*").Children.Select(x => x());
I.Assert.True(() => elements.Any(x => x.Element.Text.Contains("v3.0 Released!")));

v3.1 will have some better methods for dealing with this but this at least uses Sizzle's * selector to get every element (warning: could be real slow so maybe use "div,p,span" or similar if you can limit it).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM