Search code examples
c#assert

How to compare if one assert OR other assert are true


I have an APP that is in english and in spanish. I have automated some flows, using english language, so the asserts are in english. Now, I want to automate it in spanish, so the only thing I need to do is to add asserts in spanish.

How can I add spanish asserts and check IF one OR other = true THEN ok, in order to be able reuse easily all the code I have?

This how I use the asserts:

if (_app.Query(x => x.Class("SystemWebView").Css("BUTTON#button_home_back")).Length > 0)
{
    _app.WaitForElement(e => e.Css("BUTTON#button_home_back"), "Timeout waiting for the Home screen", new TimeSpan(0, 1, 0), null, null);

    Assert.AreEqual(_app.Query(e => e.Css("ion-title"))[0].TextContent, "englishString");                                        
     _app.Tap(x => x.Class("SystemWebView").Css("BUTTON#button_home_back"));
}

_app.Screenshot("englishString");
break;

Solution

  • If i were to do that, i would use dictionary and enum. something like this

    enum Lang { English, Spanish }
    
    Lang CurrentLang = Lang.English;
    
    Dictionary<Lang, string> Asserts = new Dictionary<Lang, string>{
        {Lang.English, "englishString"},
        {Lang.Spanish, "spanishString"}
    };
    

    Then

    Assert.AreEqual(_app.Query(e => e.Css("ion-title"))[0].TextContent, Asserts[CurrentLang]);