Skip to content

Commit

Permalink
Updated element wrappers with virtual properties and methods for over…
Browse files Browse the repository at this point in the history
…rides, and added partial item matching
  • Loading branch information
jamesmcroft committed Apr 28, 2022
1 parent 099e68f commit 24ec861
Show file tree
Hide file tree
Showing 89 changed files with 1,319 additions and 487 deletions.
8 changes: 0 additions & 8 deletions src/Legerity.Android/Elements/Core/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,5 @@ public static implicit operator Button(AppiumWebElement element)
{
return new Button(element as AndroidElement);
}

/// <summary>
/// Clicks the button.
/// </summary>
public void Click()
{
this.Element.Click();
}
}
}
10 changes: 5 additions & 5 deletions src/Legerity.Android/Elements/Core/CheckBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public CheckBox(AndroidElement element)
/// <summary>
/// Gets a value indicating whether the check box is in the checked state.
/// </summary>
public bool IsChecked => this.Element.GetAttribute("Checked") == CheckedValue;
public virtual bool IsChecked => this.GetAttribute("Checked") == CheckedValue;

/// <summary>
/// Allows conversion of a <see cref="AndroidElement"/> to the <see cref="CheckBox"/> without direct casting.
Expand Down Expand Up @@ -57,27 +57,27 @@ public static implicit operator CheckBox(AppiumWebElement element)
/// <summary>
/// Checks the check box on.
/// </summary>
public void CheckOn()
public virtual void CheckOn()
{
if (this.IsChecked)
{
return;
}

this.Element.Click();
this.Click();
}

/// <summary>
/// Checks the check box off.
/// </summary>
public void CheckOff()
public virtual void CheckOff()
{
if (!this.IsChecked)
{
return;
}

this.Element.Click();
this.Click();
}
}
}
14 changes: 7 additions & 7 deletions src/Legerity.Android/Elements/Core/DatePicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,35 @@ public DatePicker(AndroidElement element)
/// This will be in the format, 'ddd, MMM d'.
/// </para>
/// </summary>
public TextView DateTextView => this.Element.FindElement(By.Id("android:id/date_picker_header_date"));
public virtual TextView DateTextView => this.Element.FindElement(By.Id("android:id/date_picker_header_date"));

/// <summary>
/// Gets the element associated with the year text.
/// <para>
/// This will be in the format, 'YYYY'.
/// </para>
/// </summary>
public TextView YearTextView => this.Element.FindElement(By.Id("android:id/date_picker_header_year"));
public virtual TextView YearTextView => this.Element.FindElement(By.Id("android:id/date_picker_header_year"));

/// <summary>
/// Gets the element associated with the day picker.
/// </summary>
public View DayPickerView => this.Element.FindElement(By.Id("android:id/day_picker_view_pager"));
public virtual View DayPickerView => this.Element.FindElement(By.Id("android:id/day_picker_view_pager"));

/// <summary>
/// Gets the element associated with the next month button.
/// </summary>
public Button NextMonthButton => this.Element.FindElementByAndroidUIAutomator("UiSelector().description(\"Next month\")");
public virtual Button NextMonthButton => this.Element.FindElementByAndroidUIAutomator("UiSelector().description(\"Next month\")");

/// <summary>
/// Gets the element associated with the previous month button.
/// </summary>
public Button PreviousMonthButton => this.Element.FindElementByAndroidUIAutomator("UiSelector().description(\"Previous month\")");
public virtual Button PreviousMonthButton => this.Element.FindElementByAndroidUIAutomator("UiSelector().description(\"Previous month\")");

/// <summary>
/// Gets the selected date/time value.
/// </summary>
public DateTime SelectedDate => this.GetCurrentViewDate();
public virtual DateTime SelectedDate => this.GetCurrentViewDate();

/// <summary>
/// Allows conversion of a <see cref="AndroidElement"/> to the <see cref="DatePicker"/> without direct casting.
Expand Down Expand Up @@ -107,7 +107,7 @@ public static implicit operator DatePicker(AppiumWebElement element)
/// Sets the selected date of the date picker.
/// </summary>
/// <param name="date">The date to set to.</param>
public void SetDate(DateTime date)
public virtual void SetDate(DateTime date)
{
DateTime currentViewDate = this.GetCurrentViewDate();

Expand Down
12 changes: 6 additions & 6 deletions src/Legerity.Android/Elements/Core/EditText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public EditText(AndroidElement element)
/// <summary>
/// Gets the text value of the text box.
/// </summary>
public string Text => this.Element.Text;
public virtual string Text => this.Element.Text;

/// <summary>
/// Allows conversion of a <see cref="AndroidElement"/> to the <see cref="EditText"/> without direct casting.
Expand Down Expand Up @@ -54,7 +54,7 @@ public static implicit operator EditText(AppiumWebElement element)
/// Sets the text of the text box to the specified text.
/// </summary>
/// <param name="text">The text to display.</param>
public void SetText(string text)
public virtual void SetText(string text)
{
this.ClearText();
this.AppendText(text);
Expand All @@ -64,18 +64,18 @@ public void SetText(string text)
/// Appends the specified text to the text box.
/// </summary>
/// <param name="text">The text to append.</param>
public void AppendText(string text)
public virtual void AppendText(string text)
{
this.Element.Click();
this.Click();
this.Element.SendKeys(text);
}

/// <summary>
/// Clears the text from the text box.
/// </summary>
public void ClearText()
public virtual void ClearText()
{
this.Element.Click();
this.Click();
this.Element.Clear();
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/Legerity.Android/Elements/Core/RadioButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ public RadioButton(AndroidElement element)
/// <summary>
/// Gets a value indicating whether the radio button is selected.
/// </summary>
public bool IsSelected =>
this.Element.GetAttribute("Checked").Equals(
"True",
StringComparison.CurrentCultureIgnoreCase);
public virtual bool IsSelected =>
this.GetAttribute("Checked").Equals("True", StringComparison.CurrentCultureIgnoreCase);

/// <summary>
/// Allows conversion of a <see cref="AndroidElement"/> to the <see cref="RadioButton"/> without direct casting.
Expand Down
22 changes: 19 additions & 3 deletions src/Legerity.Android/Elements/Core/Spinner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Spinner(AndroidElement element)
/// <summary>
/// Gets the currently selected item.
/// </summary>
public string SelectedItem => this.GetSelectedItem();
public virtual string SelectedItem => this.GetSelectedItem();

/// <summary>
/// Allows conversion of a <see cref="AndroidElement"/> to the <see cref="Spinner"/> without direct casting.
Expand Down Expand Up @@ -59,9 +59,9 @@ public static implicit operator Spinner(AppiumWebElement element)
/// <param name="name">
/// The name of the item to select.
/// </param>
public void SelectItem(string name)
public virtual void SelectItem(string name)
{
this.Element.Click();
this.Click();

var locator =
new ByAndroidUIAutomator(
Expand All @@ -71,6 +71,22 @@ public void SelectItem(string name)
item.Click();
}

/// <summary>
/// Selects an item in the combo-box with the specified partial item name.
/// </summary>
/// <param name="partialName">The partial name match for the item to select.</param>
public virtual void SelectItemByPartialName(string partialName)
{
this.Click();

var locator =
new ByAndroidUIAutomator(
$"new UiScrollable(new UiSelector()).scrollIntoView(new UiSelector().textContains(\"{partialName}\"));");
AndroidElement item = this.Driver.FindElement(locator);

item.Click();
}

private string GetSelectedItem()
{
TextView textElement = this.Element.FindElement(By.ClassName("android.widget.TextView"));
Expand Down
13 changes: 6 additions & 7 deletions src/Legerity.Android/Elements/Core/Switch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Legerity.Android.Elements.Core
{
using System;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;

Expand All @@ -8,8 +9,6 @@ namespace Legerity.Android.Elements.Core
/// </summary>
public class Switch : AndroidElementWrapper
{
private const string ToggleOnValue = "true";

/// <summary>
/// Initializes a new instance of the <see cref="Switch"/> class.
/// </summary>
Expand All @@ -24,7 +23,7 @@ public Switch(AndroidElement element)
/// <summary>
/// Gets a value indicating whether the toggle switch is in the on position.
/// </summary>
public bool IsOn => this.Element.GetAttribute("Checked") == ToggleOnValue;
public virtual bool IsOn => this.GetAttribute("Checked").Equals("True", StringComparison.CurrentCultureIgnoreCase);

/// <summary>
/// Allows conversion of a <see cref="AndroidElement"/> to the <see cref="Switch"/> without direct casting.
Expand Down Expand Up @@ -57,27 +56,27 @@ public static implicit operator Switch(AppiumWebElement element)
/// <summary>
/// Toggles the switch on.
/// </summary>
public void ToggleOn()
public virtual void ToggleOn()
{
if (this.IsOn)
{
return;
}

this.Element.Click();
this.Click();
}

/// <summary>
/// Toggles the switch off.
/// </summary>
public void ToggleOff()
public virtual void ToggleOff()
{
if (!this.IsOn)
{
return;
}

this.Element.Click();
this.Click();
}
}
}
2 changes: 1 addition & 1 deletion src/Legerity.Android/Elements/Core/TextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public TextView(AndroidElement element)
/// <summary>
/// Gets the text value of the text view.
/// </summary>
public string Text => this.Element.Text;
public virtual string Text => this.Element.Text;

/// <summary>
/// Allows conversion of a <see cref="AndroidElement"/> to the <see cref="TextView"/> without direct casting.
Expand Down
9 changes: 4 additions & 5 deletions src/Legerity.Android/Elements/Core/ToggleButton.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Legerity.Android.Elements.Core
{
using System;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;

Expand All @@ -8,8 +9,6 @@ namespace Legerity.Android.Elements.Core
/// </summary>
public class ToggleButton : Button
{
private const string ToggleOnValue = "true";

/// <summary>
/// Initializes a new instance of the <see cref="ToggleButton"/> class.
/// </summary>
Expand All @@ -24,7 +23,7 @@ public ToggleButton(AndroidElement element)
/// <summary>
/// Gets a value indicating whether the toggle button is in the on position.
/// </summary>
public bool IsOn => this.Element.GetAttribute("Checked") == ToggleOnValue;
public virtual bool IsOn => this.GetAttribute("Checked").Equals("True", StringComparison.CurrentCultureIgnoreCase);

/// <summary>
/// Allows conversion of a <see cref="AndroidElement"/> to the <see cref="ToggleButton"/> without direct casting.
Expand Down Expand Up @@ -57,7 +56,7 @@ public static implicit operator ToggleButton(AppiumWebElement element)
/// <summary>
/// Toggles the button on.
/// </summary>
public void ToggleOn()
public virtual void ToggleOn()
{
if (this.IsOn)
{
Expand All @@ -70,7 +69,7 @@ public void ToggleOn()
/// <summary>
/// Toggles the button off.
/// </summary>
public void ToggleOff()
public virtual void ToggleOff()
{
if (!this.IsOn)
{
Expand Down
8 changes: 0 additions & 8 deletions src/Legerity.Android/Elements/Core/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,5 @@ public static implicit operator View(AppiumWebElement element)
{
return new View(element as AndroidElement);
}

/// <summary>
/// Clicks the element.
/// </summary>
public void Click()
{
this.Element.Click();
}
}
}
1 change: 0 additions & 1 deletion src/Legerity.Core/Web/WebAppManagerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class WebAppManagerOptions : AppManagerOptions
/// <summary>
/// Initializes a new instance of the <see cref="WebAppManagerOptions"/> class.
/// </summary>

public WebAppManagerOptions()
{
}
Expand Down
10 changes: 1 addition & 9 deletions src/Legerity.IOS/Elements/Core/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Button(IOSElement element)
/// <summary>
/// Gets the button's label content.
/// </summary>
public string Label => this.Element.GetLabel();
public virtual string Label => this.Element.GetLabel();

/// <summary>
/// Allows conversion of a <see cref="IOSElement"/> to the <see cref="Button"/> without direct casting.
Expand Down Expand Up @@ -52,13 +52,5 @@ public static implicit operator Button(AppiumWebElement element)
{
return new Button(element as IOSElement);
}

/// <summary>
/// Clicks the button.
/// </summary>
public void Click()
{
this.Element.Click();
}
}
}
2 changes: 1 addition & 1 deletion src/Legerity.IOS/Elements/Core/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Label(IOSElement element)
/// <summary>
/// Gets the text value of the label.
/// </summary>
public string Text => this.Element.GetLabel();
public virtual string Text => this.Element.GetLabel();

/// <summary>
/// Allows conversion of a <see cref="IOSElement"/> to the <see cref="Label"/> without direct casting.
Expand Down
4 changes: 2 additions & 2 deletions src/Legerity.IOS/Elements/Core/ProgressView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public ProgressView(IOSElement element)
/// <summary>
/// Gets the value of the progress bar.
/// </summary>
public double Percentage => double.Parse(this.Element.GetValue().TrimEnd('%'));
public virtual double Percentage => double.Parse(this.Element.GetValue().TrimEnd('%'));

/// <summary>
/// Allows conversion of a <see cref="IOSElement"/> to the <see cref="ProgressView"/> without direct casting.
/// </summary>
Expand Down
Loading

0 comments on commit 24ec861

Please sign in to comment.