From 51d259e27a478a111510eaac2eefe680c531b653 Mon Sep 17 00:00:00 2001 From: Troy Walsh Date: Wed, 20 Oct 2021 08:28:07 -0500 Subject: [PATCH 1/3] Add and test missing mobile Bys --- src/Appium.Net/Appium/MobileBy.cs | 30 ++++++++++++++++++++ test/integration/Windows/ClickElementTest.cs | 10 +++++++ 2 files changed, 40 insertions(+) diff --git a/src/Appium.Net/Appium/MobileBy.cs b/src/Appium.Net/Appium/MobileBy.cs index bc0e7a2f0..d93b23ecf 100644 --- a/src/Appium.Net/Appium/MobileBy.cs +++ b/src/Appium.Net/Appium/MobileBy.cs @@ -133,6 +133,10 @@ public static By AndroidUIAutomator(IUiAutomatorStatementBuilder selector) => public static new By Name(string selector) => new ByName(selector); public static new By Id(string selector) => new ById(selector); + + public static new By ClassName(string selector) => new ByClassName(selector); + + public static new By TagName(string selector) => new ByTagName(selector); } /// @@ -472,4 +476,30 @@ public ById(string selector) : base(selector, MobileSelector.Id) public override string ToString() => $"ById({selector})"; } + + public class ByTagName : MobileBy + { + /// + /// Initializes a new instance of the class. + /// + /// Id selector. + public ByTagName(string selector) : base(selector, MobileSelector.TagName) + { + } + public override string ToString() => + $"ByTagName({selector})"; + } + + public class ByClassName : MobileBy + { + /// + /// Initializes a new instance of the class. + /// + /// Id selector. + public ByClassName(string selector) : base(selector, MobileSelector.ClassName) + { + } + public override string ToString() => + $"ByClassName({selector})"; + } } \ No newline at end of file diff --git a/test/integration/Windows/ClickElementTest.cs b/test/integration/Windows/ClickElementTest.cs index a25354af6..a87675f5d 100644 --- a/test/integration/Windows/ClickElementTest.cs +++ b/test/integration/Windows/ClickElementTest.cs @@ -70,6 +70,16 @@ public void Addition() Assert.AreEqual("Display is 8", CalculatorResult.Text); } + [Test] + public void AdditionWithCompoundBys() + { + _calculatorSession.FindElement(MobileBy.ClassName("ApplicationFrameWindow")).FindElement(MobileBy.Name("One")).Click(); + _calculatorSession.FindElement(MobileBy.AccessibilityId("plusButton")).Click(); + _calculatorSession.FindElement(MobileBy.Name("Calculator")).FindElement(MobileBy.Name("Five")).Click(); + _calculatorSession.FindElement(MobileBy.Name("Equals")).Click(); + Assert.AreEqual("Display is 6", CalculatorResult.Text); + } + [Test] public void Combination() { From f3f2f3472cc1ca6d82511b123cd90640b820d3d3 Mon Sep 17 00:00:00 2001 From: Troy Walsh Date: Wed, 20 Oct 2021 08:50:30 -0500 Subject: [PATCH 2/3] Fix docs --- src/Appium.Net/Appium/MobileBy.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Appium.Net/Appium/MobileBy.cs b/src/Appium.Net/Appium/MobileBy.cs index d93b23ecf..a6220f506 100644 --- a/src/Appium.Net/Appium/MobileBy.cs +++ b/src/Appium.Net/Appium/MobileBy.cs @@ -480,9 +480,9 @@ public override string ToString() => public class ByTagName : MobileBy { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// Id selector. + /// Tag name selector. public ByTagName(string selector) : base(selector, MobileSelector.TagName) { } @@ -493,9 +493,9 @@ public override string ToString() => public class ByClassName : MobileBy { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// Id selector. + /// Class name selector. public ByClassName(string selector) : base(selector, MobileSelector.ClassName) { } From 28c8e00062b06266994cc44d067349fd7fecb516 Mon Sep 17 00:00:00 2001 From: Troy Walsh Date: Wed, 20 Oct 2021 16:23:56 -0500 Subject: [PATCH 3/3] Add abiltity to connect to Mobile web browsers --- src/Appium.Net/Appium/AppiumOptions.cs | 9 +++++ .../Android/Device/BrowserTests.cs | 39 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/integration/Android/Device/BrowserTests.cs diff --git a/src/Appium.Net/Appium/AppiumOptions.cs b/src/Appium.Net/Appium/AppiumOptions.cs index bc9def95b..240f28f6f 100644 --- a/src/Appium.Net/Appium/AppiumOptions.cs +++ b/src/Appium.Net/Appium/AppiumOptions.cs @@ -51,6 +51,15 @@ public AppiumOptions() : base() /// public string PlatformVersion { get; set; } + /// + /// Gets or sets the Browser name of the Appium browser's (e.g. Chrome, Safari and so on) setting. + /// + public new string BrowserName + { + get { return base.BrowserName; } + set { base.BrowserName = value; } + } + /// /// Provides a means to add additional capabilities not yet added as type safe options /// for the Appium driver. diff --git a/test/integration/Android/Device/BrowserTests.cs b/test/integration/Android/Device/BrowserTests.cs new file mode 100644 index 000000000..f421762c5 --- /dev/null +++ b/test/integration/Android/Device/BrowserTests.cs @@ -0,0 +1,39 @@ +using Appium.Net.Integration.Tests.helpers; +using NUnit.Framework; +using OpenQA.Selenium.Appium; +using OpenQA.Selenium.Appium.Android; +using System; + +namespace Appium.Net.Integration.Tests.Android.Device.App +{ + internal class BrowserTests + { + private AppiumDriver _driver; + private AppiumOptions _androidOptions; + + [OneTimeSetUp] + public void SetUp() + { + _androidOptions = new AppiumOptions(); + _androidOptions.BrowserName = "Chrome"; + + _driver = new AndroidDriver( + Env.ServerIsLocal() ? AppiumServers.LocalServiceUri : AppiumServers.RemoteServerUri, + _androidOptions); + _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); + } + + [OneTimeTearDown] + public void TearDown() + { + _driver.Dispose(); + } + + [Test] + public void Browser() + { + _driver.Navigate().GoToUrl("https://github.com/appium"); + Assert.IsNotEmpty(_driver.PageSource); + } + } +} \ No newline at end of file