How do I use Selenium in C#?

后端 未结 9 926
孤街浪徒
孤街浪徒 2020-12-01 06:38

Selenium.

I downloaded the C# client drivers and the IDE. I managed to record some tests and successfully ran them from the IDE. But now I want to do that using C#. I

9条回答
  •  -上瘾入骨i
    2020-12-01 07:29

    To set up the IDE for Selenium in conjunction with C# is to use Visual Studio Express. And you can use NUnit as the testing framework. The below links provide you more details. It seems you have set up what is explained in the first link. So check the second link for more details on how to create a basic script.

    How to setup C#, NUnit and Selenium client drivers on Visual Studio Express for Automated tests

    Creating a basic Selenium web driver test case using NUnit and C#

    Sample code from the above blog post:

    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    // Step a
    using OpenQA.Selenium;
    using OpenQA.Selenium.Support;
    using OpenQA.Selenium.Firefox;
    using NUnit.Framework;
    
    namespace NUnitSelenium
    {
        [TestFixture]
        public class UnitTest1
        {
            [SetUp]
            public void SetupTest()
            {
            }
    
            [Test]
            public void Test_OpeningHomePage()
            {
                // Step b - Initiating webdriver
                IWebDriver driver = new FirefoxDriver();
                // Step c: Making driver to navigate
                driver.Navigate().GoToUrl("http://docs.seleniumhq.org/");
    
                // Step d
                IWebElement myLink = driver.FindElement(By.LinkText("Download"));
                myLink.Click();
    
                // Step e
                driver.Quit();
    
                )
    
            }
        }
    

提交回复
热议问题