简体   繁体   中英

Change Method to Assert that the Text Returned Either Contains Text entered or Equals Text Entered (C# Selenium)

I have the following code:

   bool ColorExistsByName(string colorNameV)
    {
        var colorName = colorPage.ColorList.CategoryList.FirstOrDefault(c => c.GetText().Contains(colorNameV));
        if (colorName == null) {
            return false;
        }
        return colorName.ExistsAndDisplayed;
    }

I need to edit this so that it can either Contain OR Equal colorNameV... what's the best way to do this?

EDIT

Sorry - I wasn't clear enough. I need to somehow add a parameter (wholeWord) so that sometimes, it can use contains, and sometimes it can use equals (if we're using wholeWord) - is it possible to use parameter like this? (We already have functionality written for wholeWord parameter in order to check if wholeWord is written)

But your command c.GetText().Contains(colorNameV) does exactly what you want. If you want to test "Contains", that's what this function does. If you want to test equals, it also works, since the c.GetText() will contain colorNameV and nothing else (will contain just itself). It works for both of your cases.

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