Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would highly recommend using the Page Object Model. In this you create a class for each page and then abstract items away.</p> <p>I wrote a blog post on writing maintainable tests <a href="http://www.theautomatedtester.co.uk/blog/2010/writing-maintainable-tests.htm" rel="nofollow noreferrer">here</a>. You can see my blog post on the Page object model <a href="http://www.theautomatedtester.co.uk/tutorials/selenium/page-object-pattern.htm" rel="nofollow noreferrer">here</a></p> <p>So your object could be like below.</p> <pre><code>public class Home { private readonly ISelenium _selenium; /// &lt;summary&gt; /// Instantiates a new Home Page object. Pass in the Selenium object created in the test SetUp(). /// When the object in instantiated it will navigate to the root /// &lt;/summary&gt; /// &lt;param name="selenium"&gt;Selenium Object created in the tests public Home(ISelenium selenium) { this._selenium = selenium; if (!selenium.GetTitle().Contains("home")) { selenium.Open("/"); } } /// &lt;summary&gt; /// Navigates to Selenium Tutorials Page. Selenium object wll be passed through /// &lt;/summary&gt; /// &lt;returns&gt;SeleniumTutorials representing the selenium_training.htm&lt;/returns&gt; public SeleniumTutorials ClickSelenium() { _selenium.Click("link=selenium"); _selenium.WaitForPageToLoad("30000"); return new SeleniumTutorials(_selenium); } /// &lt;summary&gt; /// Click on the blog or blog year and then wait for the page to load /// &lt;/summary&gt; /// &lt;param name="year"&gt;blog or blog year /// &lt;returns&gt;Object representing /blog.* pages&lt;/returns&gt; public Blog ClickBlogYear(string year) { _selenium.Click("link=" + year); _selenium.WaitForPageToLoad("30000"); return new Blog(_selenium); } // Add more methods as you need them } public class SeleniumXPathTutorial { private readonly ISelenium _selenium; public const string FirstInput = "number1"; public const string SecondInput = "number2"; public const string Total = "total"; public SeleniumXPathTutorial(ISelenium selenium) { this._selenium = selenium; } public bool IsInputOnScreen(string locator) { return _selenium.IsElementPresent(locator); } } </code></pre> <p>and then the test class would be like</p> <pre><code>[TestFixture] public class SiteTests { private ISelenium selenium; [SetUp] public void Setup() { selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.theautomatedtester.co.uk"); selenium.Start(); } [TearDown] public void Teardown() { selenium.Stop(); } [Test] public void ShouldLoadHomeThenGoToXpathTutorial() { Home home = new Home(selenium); SeleniumTutorials seleniumTutorials = home.ClickSelenium(); SeleniumXPathTutorial seleniumXPathTutorial = seleniumTutorials.ClickXpathTutorial(); Assert.True(seleniumXPathTutorial. IsInputOnScreen(SeleniumXPathTutorial.FirstInput)); Assert.True(seleniumXPathTutorial .IsInputOnScreen(SeleniumXPathTutorial.SecondInput)); Assert.True(seleniumXPathTutorial .IsInputOnScreen(SeleniumXPathTutorial.Total)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload