using System;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Remote;
namespace CalcTest
{
class Program
{
private const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
private const string CalculatorAppId = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App";
protected static WindowsDriver<WindowsElement> session;
static void Main(string[] args)
{
string serverPath = System.IO.Path.Combine(
System.Environment.GetFolderPath(
System.Environment.SpecialFolder.ProgramFilesX86
), @"Windows Application Driver", "WinAppDriver.exe"
);
System.Diagnostics.Process.Start(serverPath);
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", CalculatorAppId);
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
session.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1.5));
// LeftClick on "One" at (50,48)
Console.WriteLine("LeftClick on \"One\" at (50,48)");
string xp1 = "//*[@ClassName=\"ApplicationFrameWindow\"]/Window[@Name=\"Calculator\"][@ClassName=\"Windows.UI.Core.CoreWindow\"]/Group[@ClassName=\"LandmarkTarget\"]/Group[@AutomationId=\"NumberPad\"][@Name=\"Number pad\"]/Button[@AutomationId=\"num1Button\"][@Name=\"One\"]";
var winElem1 = session.FindElementByXPath(xp1);
if (winElem1 != null)
{
winElem1.Click();
}
else
{
Console.WriteLine($"Failed to find element {xp1}");
return;
}
// LeftClick on "Two" at (43,35)
Console.WriteLine("LeftClick on \"Two\" at (43,35)");
string xp2 = "//*[@ClassName=\"ApplicationFrameWindow\"]/Window[@Name=\"Calculator\"][@ClassName=\"Windows.UI.Core.CoreWindow\"]/Group[@ClassName=\"LandmarkTarget\"]/Group[@AutomationId=\"NumberPad\"][@Name=\"Number pad\"]/Button[@AutomationId=\"num2Button\"][@Name=\"Two\"]";
var winElem2 = session.FindElementByXPath(xp2);
if (winElem2 != null)
{
winElem2.Click();
}
else
{
Console.WriteLine($"Failed to find element {xp2}");
return;
}
// LeftClick on "Three" at (37,43)
Console.WriteLine("LeftClick on \"Three\" at (37,43)");
string xp3 = "//*[@ClassName=\"ApplicationFrameWindow\"]/Window[@Name=\"Calculator\"][@ClassName=\"Windows.UI.Core.CoreWindow\"]/Group[@ClassName=\"LandmarkTarget\"]/Group[@AutomationId=\"NumberPad\"][@Name=\"Number pad\"]/Button[@AutomationId=\"num3Button\"][@Name=\"Three\"]";
var winElem3 = session.FindElementByXPath(xp3);
if (winElem3 != null)
{
winElem3.Click();
}
else
{
Console.WriteLine($"Failed to find element {xp3}");
return;
}
// LeftClick on "Plus" at (46,45)
Console.WriteLine("LeftClick on \"Plus\" at (46,45)");
string xp4 = "//*[@ClassName=\"ApplicationFrameWindow\"]/Window[@Name=\"Calculator\"][@ClassName=\"Windows.UI.Core.CoreWindow\"]/Group[@ClassName=\"LandmarkTarget\"]/Group[@AutomationId=\"StandardOperators\"][@Name=\"Standard operators\"]/Button[@AutomationId=\"plusButton\"][@Name=\"Plus\"]";
var winElem4 = session.FindElementByXPath(xp4);
if (winElem4 != null)
{
winElem4.Click();
}
else
{
Console.WriteLine($"Failed to find element {xp4}");
return;
}
// LeftClick on "Six" at (40,40)
Console.WriteLine("LeftClick on \"Six\" at (40,40)");
string xp5 = "//*[@ClassName=\"ApplicationFrameWindow\"]/Window[@Name=\"Calculator\"][@ClassName=\"Windows.UI.Core.CoreWindow\"]/Group[@ClassName=\"LandmarkTarget\"]/Group[@AutomationId=\"NumberPad\"][@Name=\"Number pad\"]/Button[@AutomationId=\"num6Button\"][@Name=\"Six\"]";
var winElem5 = session.FindElementByXPath(xp5);
if (winElem5 != null)
{
winElem5.Click();
}
else
{
Console.WriteLine($"Failed to find element {xp5}");
return;
}
// LeftClick on "Equals" at (39,17)
Console.WriteLine("LeftClick on \"Equals\" at (39,17)");
string xp6 = "//*[@ClassName=\"ApplicationFrameWindow\"]/Window[@Name=\"Calculator\"][@ClassName=\"Windows.UI.Core.CoreWindow\"]/Group[@ClassName=\"LandmarkTarget\"]/Group[@AutomationId=\"StandardOperators\"][@Name=\"Standard operators\"]/Button[@AutomationId=\"equalButton\"][@Name=\"Equals\"]";
var winElem6 = session.FindElementByXPath(xp6);
if (winElem6 != null)
{
winElem6.Click();
}
else
{
Console.WriteLine($"Failed to find element {xp6}");
return;
}
}
}
}