简体   繁体   English

如何比较一个断言或其他断言为真

[英]How to compare if one assert OR other assert are true

I have an APP that is in english and in spanish. 我有一个英文和西班牙文的APP。 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? 我如何添加西班牙语断言并检查是否一个或另一个= true,然后确定,以便能够轻松重用我拥有的所有代码?

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;

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]); 

You could create a method that returns the correct string based on the language. 您可以创建一个根据语言返回正确字符串的方法。

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

By the time you do this assert you must already know in which language the app is running so you should definitely do the assert against the exact string for that language, not in a a || b 在执行此断言时,您必须已经知道应用程序以哪种语言运行,因此,您绝对应该针对该语言的确切字符串进行断言,而不要a || b a || b fashion, because you want the assert to fail in case there is a Spanish title when the app should be in English. a || b时尚,因为您希望断言失败,以防应用程序使用英语时出现西班牙语标题。

The way you implement the method that returns localized resources depends purely on the way localization is built in your app. 实现返回本地化资源的方法的方式完全取决于在应用程序中构建本地化的方式。 In case of test you may want to hardcode the strings in tests instead to make sure you are not depending on the localization infrastructure to be functional. 在进行测试的情况下,您可能需要对测试中的字符串进行硬编码,以确保您不依赖于本地化基础架构来发挥作用。 Or you can separately run tests to make sure this infrastructure works. 或者,您可以单独运行测试以确保该基础结构正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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