Skip to content

Instantly share code, notes, and snippets.

@kawakawa
Last active December 14, 2015 20:08
Show Gist options
  • Save kawakawa/5141514 to your computer and use it in GitHub Desktop.
Save kawakawa/5141514 to your computer and use it in GitHub Desktop.
Visual Studio2012でSeleniumを使用する際のソースサンプル。 Bing検索サイトでseleniumを検索します。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
namespace SeleniumDemo
{
[TestFixture]
public class SeleniumTest
{
private IWebDriver webDriver=null;
[SetUp]
public void Setup()
{
webDriver = new InternetExplorerDriver();
}
[TearDown]
public void Teardown()
{
webDriver.Quit();
}
[Test]
public void BingでSelenium検索()
{
var expected = "selenium - Bing";
webDriver.Navigate().GoToUrl("http://www.bing.com/");
var sercheQuery = webDriver.FindElement(By.Id("sb_form_q"));
sercheQuery.SendKeys("selenium");
sercheQuery.Submit();
var waitTime = new WebDriverWait(webDriver, TimeSpan.FromSeconds(5));
waitTime.Until(n => { return n.Title.StartsWith("selenium"); });
var actual = webDriver.Title;
Assert.AreEqual(expected,actual);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment