Permalink
Browse files

added ListWrapper

  • Loading branch information...
1 parent a83dd57 commit e95f7d155abe303bff7a43ce61c67768bac42bf0 @shashankshetty shashankshetty committed May 13, 2013
@@ -3,15 +3,11 @@
using System.Linq;
using System.Threading;
using System.Web;
-
using FluentAssert;
-
using FluentBrowserAutomation.Controls;
using FluentBrowserAutomation.Declarative;
using FluentBrowserAutomation.Framework;
-
using JetBrains.Annotations;
-
using OpenQA.Selenium;
namespace FluentBrowserAutomation
@@ -60,6 +56,7 @@ public interface IBrowserContext
SpanWrapper SpanWithText([NotNull] string spanText);
IEnumerable<SpanWrapper> Spans();
TableWrapper TableWithId([NotNull] string id);
+ ListWrapper ListWithId([NotNull] string id);
IEnumerable<TableWrapper> Tables();
TextBoxWrapper TextBoxWithId([NotNull] string id);
TextBoxWrapper TextBoxWithLabel([NotNull] string label);
@@ -211,7 +208,7 @@ public IEnumerable<TextBoxWrapper> Hiddens()
public BrowserContext IdOfFieldWithFocusShouldBe(string expectedId)
{
- var id = Browser.SwitchTo().ActiveElement().GetAttribute("id");
+ string id = Browser.SwitchTo().ActiveElement().GetAttribute("id");
id.ShouldBeEqualTo(expectedId);
return this;
}
@@ -271,13 +268,23 @@ public LinkWrapper LinkWithId(string id)
public LinkWrapper LinkWithText(string text)
{
- var htmlEscapedText = HttpUtility.HtmlEncode(text);
+ string htmlEscapedText = HttpUtility.HtmlEncode(text);
const string howFound = "link with visible text '{0}'";
var link = Browser.FindElements(By.LinkText(text)).FirstOrDefault() ?? GetElementsByTagType("a").FirstOrDefault(x =>
- {
- var attribute = x.GetAttribute("innerHTML");
- return attribute == htmlEscapedText || attribute == text;
- });
+ {
+ string
+ attribute
+ =
+ x
+ .
+ GetAttribute
+ ("innerHTML");
+ return
+ attribute ==
+ htmlEscapedText ||
+ attribute ==
+ text;
+ });
return new LinkWrapper(link, String.Format(howFound, text), this);
}
@@ -369,6 +376,13 @@ public TableWrapper TableWithId(string id)
return new TableWrapper(table, String.Format(howFound, id), this);
}
+ public ListWrapper ListWithId(string id)
+ {
+ const string howFound = "list with id '{0}'";
+ var list = TryGetElementByIdAndTagType(id, "ul");
+ return new ListWrapper(list, String.Format(howFound, id), this);
+ }
+
public IEnumerable<TableWrapper> Tables()
{
const string howFound = "type 'table'";
@@ -392,7 +406,7 @@ public IEnumerable<TextBoxWrapper> TextBoxes()
public IBrowserContext WaitUntil(Func<IBrowserContext, bool> func, int secondsToWait = 10)
{
- for (var i = 0; i < secondsToWait; i++)
+ for (int i = 0; i < secondsToWait; i++)
{
try
{
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using FluentBrowserAutomation.Accessors;
+using OpenQA.Selenium;
+
+namespace FluentBrowserAutomation.Controls
+{
+ public class ListWrapper : BasicInfoWrapper
+ {
+ public ListWrapper(IWebElement list, string howFound, IBrowserContext browserContext)
+ : base(list, howFound, browserContext)
+ {
+ }
+
+ public IEnumerable<ListItemWrapper> Rows()
+ {
+ var items = Element.FindElements(By.TagName("li"))
+ .Select((x, i) =>
+ new ListItemWrapper(x, String.Format("{0}, item with index {1}", HowFound, i), BrowserContext));
+
+ return items;
+ }
+ }
+
+ public class ListItemWrapper : BasicInfoWrapper
+ {
+ public ListItemWrapper(IWebElement listItem, string howFound, IBrowserContext browserContext)
+ : base(listItem, howFound, browserContext)
+ {
+ }
+
+ public ReadOnlyText Text()
+ {
+ return new ReadOnlyText(HowFound, Element.Text);
+ }
+ }
+}
@@ -88,6 +88,7 @@
<Compile Include="Controls\Children.cs" />
<Compile Include="Controls\ContainerWrapper.cs" />
<Compile Include="Controls\ImageWrapper.cs" />
+ <Compile Include="Controls\ListWrapper.cs" />
<Compile Include="Controls\MissingInputWrapper.cs" />
<Compile Include="Controls\Properties\IAmInputThatCanBeChanged.cs" />
<Compile Include="Controls\Properties\IAmSelectionInput.cs" />

0 comments on commit e95f7d1

Please sign in to comment.