Assert in Selenium C#

后端 未结 8 759
[愿得一人]
[愿得一人] 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();
        }
    }
    
    0 讨论(0)
  • 2021-01-07 12:18

    Yes, you would use the Assert class in your unit test framework, in your case MSTest.

    The Selenium library doesn't have responsibility over test framework type of functions, including asserts.

    You can use FluentAssertions which supports many different frameworks including MSTest which might minimize changes needed if you need to switch frameworks for any reason.

    0 讨论(0)
提交回复
热议问题