问题
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