How to assert a text field contains in selenium c#

☆樱花仙子☆ 提交于 2020-07-23 11:52:29

问题


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.


回答1:


You can use Assert.IsTrue for that

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, i.e. actualvalue doesn't contains "Post published1".



来源:https://stackoverflow.com/questions/35901716/how-to-assert-a-text-field-contains-in-selenium-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!