Created
February 19, 2012 02:53
-
-
Save OdaShinsuke/1861739 to your computer and use it in GitHub Desktop.
BingSearch_WebDriver_cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text.RegularExpressions; | |
using OpenQA.Selenium; | |
using OpenQA.Selenium.Support.UI; | |
namespace WebDriverTest { | |
public class BingSearch { | |
public static BingSearch Create(IWebDriver driver) { | |
var instance = new BingSearch(driver); | |
driver.Url = "http://www.bing.com"; | |
return instance; | |
} | |
private readonly IWebDriver driver; | |
private BingSearch(IWebDriver driver) { | |
this.driver = driver; | |
} | |
private static readonly By LOCATOR_条件 = By.Name("q"); | |
private IWebElement txt条件 { | |
get { return driver.FindElement(LOCATOR_条件); } | |
} | |
private static readonly By LOCATOR_検索 = By.XPath("//input[@type='submit' and @name='go']"); | |
private IWebElement btn検索 { | |
get { return driver.FindElement(LOCATOR_検索); } | |
} | |
private static readonly By LOCATOR_件数 = By.Id("count"); | |
private IWebElement lbl件数 { | |
get { return driver.FindElement(LOCATOR_件数); } | |
} | |
public void Input検索条件(string 条件) { | |
this.txt条件.Clear(); | |
this.txt条件.SendKeys(条件); | |
} | |
public void Click検索() { | |
this.btn検索.Click(); | |
var wait = new WebDriverWait(this.driver, new TimeSpan(0, 0, 10)); | |
// wait.Until(ExpectedConditions.TitleIs("Microsoft - Bing")); | |
wait.Until(d => d.Title == "Microsoft - Bing"); | |
} | |
public string Get検索結果件数() { | |
return Regex.Match(this.lbl件数.Text, "(?<=of ).*(?= results)").Value; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text.RegularExpressions; | |
using System.Threading; | |
using NUnit.Framework; | |
using OpenQA.Selenium.IE; | |
using OpenQA.Selenium.Support.UI; | |
using System; | |
namespace WebDriverTest { | |
[TestFixture] | |
public class NoPageObectTest { | |
[Test] | |
public void 検索() { | |
var driver = new InternetExplorerDriver(); | |
try { | |
driver.Navigate().GoToUrl("http://www.bing.com"); | |
var txt条件 = driver.FindElementByName("q"); | |
txt条件.Clear(); | |
txt条件.SendKeys("Microsoft"); | |
var btn検索 = driver.FindElementByXPath("//input[@type='submit' and @name='go']"); | |
btn検索.Click(); | |
var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 10)); | |
wait.Until(ExpectedConditions.TitleIs("Microsoft - Bing")); | |
var lbl件数 = driver.FindElementById("count"); | |
Regex.Match(lbl件数.Text, "(?<=of ).*(?= results)").Value.Is("527,000,000"); | |
} finally { | |
driver.Quit(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using NUnit.Framework; | |
using WebDriverTest; | |
using OpenQA.Selenium.IE; | |
namespace WebDriverTest { | |
[TestFixture] | |
public class PageObjectTest { | |
[Test] | |
public void 検索() { | |
var driver = new InternetExplorerDriver(); | |
try { | |
var instance = BingSearch.Create(driver); | |
instance.Input検索条件("Microsoft"); | |
instance.Click検索(); | |
instance.Get検索結果件数().Is("527,000,000"); | |
} finally { | |
driver.Quit(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment