Skip to content

Commit

Permalink
Merge pull request #132 from MADE-Apps/feature/partial-matching
Browse files Browse the repository at this point in the history
Partial name matching for element selection methods
  • Loading branch information
jamesmcroft authored Apr 28, 2022
2 parents b56b946 + 24ec861 commit 8ed8c73
Show file tree
Hide file tree
Showing 103 changed files with 1,397 additions and 522 deletions.
4 changes: 2 additions & 2 deletions samples/AndroidCoreSamples/AndroidCoreSamples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="4.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Shouldly" Version="4.0.3" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions samples/MADESampleApp/MADESampleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="4.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Shouldly" Version="4.0.3" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions samples/TelerikUwpSdkSample/TelerikUwpSdkSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="4.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Shouldly" Version="4.0.3" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions samples/W3SchoolsWebTests/W3SchoolsWebTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="100.0.4896.6000" />
<PackageReference Include="Selenium.WebDriver.MSEdgeDriver" Version="99.0.1150.46" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="101.0.4951.4100" />
<PackageReference Include="Selenium.WebDriver.MSEdgeDriver" Version="100.0.1185.50" />
<PackageReference Include="Shouldly" Version="4.0.3" />
</ItemGroup>

Expand Down
6 changes: 3 additions & 3 deletions samples/WebTests/WebTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="4.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="Selenium.WebDriver.MSEdgeDriver" Version="99.0.1150.46" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Selenium.WebDriver.MSEdgeDriver" Version="100.0.1185.50" />
<PackageReference Include="Shouldly" Version="4.0.3" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions samples/WindowsAlarmsAndClock/WindowsAlarmsAndClock.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="4.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Shouldly" Version="4.0.3" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="4.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Shouldly" Version="4.0.3" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions samples/XamlControlsGallery/XamlControlsGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<ItemGroup>
<PackageReference Include="Appium.WebDriver" Version="4.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Shouldly" Version="4.0.3" />
</ItemGroup>

Expand Down
5 changes: 0 additions & 5 deletions src/Legerity.Android/Elements/AndroidElementWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ protected AndroidElementWrapper(AndroidElement element)
/// </summary>
public AndroidDriver<AndroidElement> Driver => AppManager.AndroidApp;

/// <summary>
/// Gets a value indicating whether the element is enabled.
/// </summary>
public bool IsEnabled => this.Element.Enabled;

/// <summary>
/// Determines whether the specified element is shown with the specified timeout.
/// </summary>
Expand Down
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
Loading

0 comments on commit 8ed8c73

Please sign in to comment.