수색…


비고

이것은 매우 기본적인 예제 또는 Selenium을 시작하여 페이지에 액세스하여 사용하고 NUnit에서 Selenium을 종료합니다.

간단한 셀레늄 - NUnit

전제 조건 :

  • Selenium 및 필수 브라우저 드라이버가 설치되어 있습니다 (Nuget에서 사용 가능).
  • NUnit이 VS에 설치되었고 프로젝트에 추가되었습니다.
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using System;
[TestFixture]
public class GoToGoogle
{
    //The WebDriver object
    IWebDriver driver;
    //Ran before test cases
    [TestFixtureSetUp]
    public void setup()
    {
        //Initialize the webdriver
        //An example of IE
        driver = new InternetExplorerDriver();
        //Firefox Example
        //driver = new FirefoxDriver();
        //An example of Chrome
        //driver = new ChromeDriver();

        //Wait x seconds to find the element and then fail, x = 5 here
        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
    }
    //Ran after the test case has completed
    [TestFixtureTearDown]
    public void tearDown()
    {
        driver.Quit();
    }
    [Test]
    public void gotoGoogle()
    {
        //going to google.com
        driver.Navigate().GoToUrl("www.google.com");
        //Assert we are on google.com
        Assert.AreEqual(driver.Title, "Google");
        //Getting the search field
        IWebElement searchField = driver.FindElement(By.Name("q"));
        //Typing in the search field
        searchField.SendKeys("Selenium Tutorial");
        //Submitting
        searchField.Submit();

    }


}


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow