Created
March 4, 2012 04:06
-
-
Save OdaShinsuke/1970625 to your computer and use it in GitHub Desktop.
PageObject パターンを実装してみた。多分こんな感じ
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 OpenQA.Selenium.IE; | |
using PageObjects; | |
namespace WebDriverTest { | |
[TestFixture] | |
public class PageObjectTest { | |
[Test] | |
public void 検索() { | |
var driver = new InternetExplorerDriver(); | |
try { | |
var top = Top.Create(driver); | |
var result = top.Search("Microsoft"); | |
result.検索結果件数.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 System.Text.RegularExpressions; | |
using OpenQA.Selenium; | |
using OpenQA.Selenium.Remote; | |
namespace PageObjects { | |
public class Result { | |
private readonly RemoteWebDriver driver; | |
internal Result(RemoteWebDriver driver) { | |
this.driver = driver; | |
} | |
private IWebElement lbl件数 { | |
get { return driver.FindElementById("count"); } | |
} | |
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; | |
using OpenQA.Selenium; | |
using OpenQA.Selenium.Remote; | |
using OpenQA.Selenium.Support.UI; | |
namespace PageObjects { | |
public class Top { | |
public static Top Create(RemoteWebDriver driver) { | |
var instance = new Top(driver); | |
driver.Url = "http://www.bing.com"; | |
return instance; | |
} | |
private readonly RemoteWebDriver driver; | |
private Top(RemoteWebDriver driver) { | |
this.driver = driver; | |
} | |
private IWebElement txt条件 { | |
get { return driver.FindElementByName("q"); } | |
} | |
private IWebElement btn検索 { | |
get { | |
return driver.FindElementByXPath( | |
"//input[@type='submit' and @name='go']"); | |
} | |
} | |
public Result Search(String 条件) { | |
this.txt条件.Clear(); | |
this.txt条件.SendKeys(条件); | |
this.btn検索.Click(); | |
var wait = new WebDriverWait(this.driver, new TimeSpan(0, 0, 10)); | |
var expectedTitle = string.Format("{0} - Bing", 条件); | |
wait.Until(ExpectedConditions.TitleIs(expectedTitle)); | |
return new Result(driver); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment