Assert in Selenium C#

后端 未结 8 825
[愿得一人]
[愿得一人] 2021-01-07 11:45

Is there a Assert class present in Selenium C# just like we have in Coded UI test.

Or I should use the Microsoft.VisualStudio.TestTools.UnitTesting.Asser

8条回答
  •  清歌不尽
    2021-01-07 12:14

    According to https://msdn.microsoft.com/en-us/library/ms182532.aspx

    [TestClass]
    public class UnitTest1
    {
        private IWebDriver driver;
        [TestInitialize]
        public void Setup()
        {
            driver = new ChromeDriver();
            driver.Url = "Your URL";
        }
    
        [TestMethod]
        public void TestMethod1()
        {
            //Your first test method
            var element = driver.FindElement(By.Id("ID"));
            Assert.IsTrue(element.Displayed);
            Assert.AreEqual(element.Text.ToLower(), "Expected text".ToLower());
        }
    
        [TestMethod]
        public void TestMethod2()
        {
            //Your second test method
        }
    
        [TestCleanup]
        public void TearDown()
        {
            driver.Quit();
        }
    }
    

提交回复
热议问题