简体   繁体   English

如何断言 selenium c# 中包含的文本字段

[英]How to assert a text field contains in selenium c#

I have this code I'm trying to assert that a text field contains "Post Published" I can't seem to figure it out我有这个代码我试图断言一个文本字段包含“发布后”我似乎无法弄清楚

string actualvalue = driver.FindElement(By.Id("message")).Text;

actualvalue.Contains("Post published1.");

I'm not sure where to place my assertion.我不知道该把我的断言放在哪里。

You can use Assert.IsTrue for that您可以为此使用Assert.IsTrue

string actualvalue = driver.FindElement(By.Id("message")).Text;
Assert.IsTrue(actualvalue.Contains("Post published1."), actualvalue + " doesn't contains 'Post published1.'");

The message will be displayed only in case the assertion failed, ie actualvalue doesn't contains "Post published1" .只有在断言失败的情况下才会显示该消息,即actualvalue不包含"Post published1" actualvalue "Post published1"

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

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