wpf-402173-common-concepts-ui-test-automation-support-how-to-test-with-appium.md
DevExpress WPF Controls support the Appium framework with WinAppDriver UI test automation. This topic shows how to prepare the environment and create a test.
Follow the steps below to use Appium with DevExpress WPF Controls:
To use the Appium API, create a WindowsDriver instance. The following code sample runs the tested application and creates a WindowsDriver session:
var options = new AppiumOptions();
options.AddAdditionalCapability(capabilityName: "app", capabilityValue: PathToTheApp);
options.AddAdditionalCapability(capabilityName: "deviceName", capabilityValue: "WindowsPC");
options.AddAdditionalCapability(capabilityName: "platformName", capabilityValue: "Windows");
options.AddAdditionalCapability(capabilityName: "ms:experimental-webdriver", capabilityValue: true);
var driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), options);
Dim options = New AppiumOptions()
options.AddAdditionalCapability(capabilityName:="app", capabilityValue:=PathToTheApp)
options.AddAdditionalCapability(capabilityName:="deviceName", capabilityValue:="WindowsPC")
options.AddAdditionalCapability(capabilityName:="platformName", capabilityValue:="Windows")
options.AddAdditionalCapability(capabilityName:="ms:experimental-webdriver", capabilityValue:=True)
Dim driver = New WindowsDriver(Of WindowsElement)(New Uri("http://127.0.0.1:4723"), options)
To test a running application, change the line with the “app” capabilityName from the code sample above to the following:
options.AddAdditionalCapability(capabilityName: "appTopLevelWindow", capabilityValue: $"0x{WindowHandle.ToInt64():X8}");
options.AddAdditionalCapability(capabilityName:="appTopLevelWindow", capabilityValue:=$"0x{WindowHandle.ToInt64()}")
Note
If you host tests in the same process as the tested application, tests should be in a separate thread. In this case, the UI thread can process windows messages synchronously.
You can use the WinAppDriver UI Recorder tool to generate tests. In this case, your test application requires the DesktopSession class. This approach has the following cons:
Use the WinAppDriver’s FindElementByName , FindElementByClassName , and FindElementByAccessibilityId methods to find application elements. These methods work faster than the FindElementByXPath method. Tests based on these methods do not fail when you modify the application layout.
You can use the Inspect tool to find element names, class names, and automation ids.
Tip
You can specify the AutomationProperties.AutomationId attached property of the application elements to enhance test readability. Refer to the Use the AutomationID Property topic for more information.
The following code opens the “New Employee” window, finds the “First Name” element with the TextEdit class in this window, inputs “John”, and clicks the “Save & Close” element:
[Test]
public void CreateEmployee()
{
var bNewEmployee = driver.FindElementByName("New Employee");
bNewEmployee.Click();
WindowsElement newEmployeeWindow = null;
while (newEmployeeWindow == null)
newEmployeeWindow = driver.FindElementByName("Employee (New)");
newEmployeeWindow.FindElementByName("First Name").FindElementByClassName("TextEdit").SendKeys("John");
newEmployeeWindow.FindElementByName("Save & Close").Click();
}
Public Sub CreateEmployee()
Dim driver = desktopSession.DesktopSessionElement
Dim bNewEmployee = driver.FindElementByName("New Employee")
bNewEmployee.Click()
Dim newEmployeeWindow As WindowsElement = Nothing
While newEmployeeWindow Is Nothing
newEmployeeWindow = driver.FindElementByName("Employee (New)")
End While
newEmployeeWindow.FindElementByName("First Name").FindElementByClassName("TextEdit").SendKeys("John")
newEmployeeWindow.FindElementByName("Save & Close").Click()
End Sub
See Also