appium-dotnet-driver是否支持.net core 2.x?

时间:2019-05-09 07:29:07

标签: .net-core appium

我正在尝试在.net核心框架中使用Appium donet webdriver,并警告我有关Appium.WebDriver,Castle.Core和Selenium.Support。 .net核心有支持吗?

1 个答案:

答案 0 :(得分:2)

我为WinDriver做过类似的事情。我能够从“自动化地球”转换“ GettingStartedWinDriver”解决方案。参见their GitHub

下面的屏幕快照显示了所使用的项目属性和依赖项: This screenshot 如您所见,正在引用Appium.WebDriver(4.0.05-beta)来完成这项工作。这是使其在.net Core 2.1上运行的关键。因此,请务必对此进行调查,以使其适用于WebDriver。

这是实现:

using NUnit.Framework;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using System;

namespace GettingStartedWinDriverDotNetCore2Dot1
{
    [TestFixture]
    public class CalculatorTests
    {
        private WindowsDriver<WindowsElement> _driver;

        [SetUp]
        public void TestInit()
        {
            AppiumOptions appOptions = new AppiumOptions();

            appOptions.AddAdditionalCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
            appOptions.AddAdditionalCapability("deviceName", "WindowsPC");
            _driver = 
                new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appOptions);
            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
        }

        [TearDown]
        public void TestCleanup()
        {
            if (_driver != null)
            {
                _driver.Quit();
                _driver = null;
            }
        }

        [Test]
        public void Addition()
        {
            _driver.FindElementByName("Five").Click();
            _driver.FindElementByName("Plus").Click();
            _driver.FindElementByName("Seven").Click();
            _driver.FindElementByName("Equals").Click();

            var calculatorResult = GetCalculatorResultText();
            Assert.AreEqual("12", calculatorResult);
        }

        [Test]
        public void Division()
        {
            _driver.FindElementByAccessibilityId("num8Button").Click();
            _driver.FindElementByAccessibilityId("num8Button").Click();
            _driver.FindElementByAccessibilityId("divideButton").Click();
            _driver.FindElementByAccessibilityId("num1Button").Click();
            _driver.FindElementByAccessibilityId("num1Button").Click();
            _driver.FindElementByAccessibilityId("equalButton").Click();

            Assert.AreEqual("8", GetCalculatorResultText());
        }

        [Test]
        public void Multiplication()
        {
            _driver.FindElementByXPath("//Button[@Name='Nine']").Click();
            _driver.FindElementByXPath("//Button[@Name='Multiply by']").Click();
            _driver.FindElementByXPath("//Button[@Name='Nine']").Click();
            _driver.FindElementByXPath("//Button[@Name='Equals']").Click();

            Assert.AreEqual("81", GetCalculatorResultText());
        }

        [Test]
        public void Subtraction()
        {
            _driver.FindElementByXPath("//Button[@AutomationId=\"num9Button\"]").Click();
            _driver.FindElementByXPath("//Button[@AutomationId=\"minusButton\"]").Click();
            _driver.FindElementByXPath("//Button[@AutomationId=\"num1Button\"]").Click();
            _driver.FindElementByXPath("//Button[@AutomationId=\"equalButton\"]").Click();

            Assert.AreEqual("8", GetCalculatorResultText());
        }

        [Test]
        [TestCase("One", "Plus", "Seven", "8")]
        [TestCase("Nine", "Minus", "One", "8")]
        [TestCase("Eight", "Divide by", "Eight", "1")]
        public void Templatized(string input1, string operation, string input2, string expectedResult)
        {
            _driver.FindElementByName(input1).Click();
            _driver.FindElementByName(operation).Click();
            _driver.FindElementByName(input2).Click();
            _driver.FindElementByName("Equals").Click();

            Assert.AreEqual(expectedResult, GetCalculatorResultText());
        }

        private string GetCalculatorResultText()
        {
            return _driver.FindElementByAccessibilityId("CalculatorResults").Text.Replace("Display is", string.Empty).Trim();
        }
    }
}