Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the advantages of the interface control DevExpress WPF

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "what are the advantages of the interface control DevExpress WPF". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

DevExpress WPF has 120 + controls and libraries that will help you deliver high-performance business applications that meet or exceed the needs of your enterprise. Through DevExpress WPF, you can create powerful interactive XAML basic applications that focus on the needs of contemporary customers and build a new generation of touch-enabled solutions in the future.

In v20.2, the technical team enhanced support for UI test automation in the WPF product line, and UI automation now includes more comprehensive automated testing capabilities:

The DevExpress WPF control forms a theme-independent AutomationPeer hierarchy.

You can search for the AutomationPeer attribute in the automation tree, and the generated and assigned XAML/ code AutomationPeer attribute can be used for search.

AutomationPeers includes various automation modes, such as Invoke, ExpandCollapse, Selection, Scroll and so on.

You can create automated tests using the UIAutomationClient library API, or you can use any UI test library based on UI automation technology.

The DevExpress WPF control contains the UI test mode option, and the following changes are made to the application when used:

Animation is disabled.

The context menu is activated only when the mouse is clicked and does not open when the mouse pointer hovers over the menu item.

The UI automation tree was modified to produce more stable and reliable tests.

Note: we tested the control using Appium WinAppDriver API.

Prepare the environment

Enable Windows Developer Mode.

Install WinAppDriver.

Download WinAppDriver UI Recorder.

Create a test

Follow these steps to create a new test project:

1. Open a Windows command prompt, create a project folder or navigate to an existing folder, and use the following command:

Dotnet new nunit-- framework netcoreapp3.1-create an empty nunit test project.

Dotnet add package Appium.WebDriver-reference the Appium.WebDriver package in your project.

two。 Open the nunit test project in Visual Studio.

3. Create a DesktopSession class that allows you to use the code that the WinAppDriver UI logger will generate.

You can see how it is implemented below:

Public class DesktopSession {const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723/";WindowsDriver"

< WindowsElement >

DesktopSession;public DesktopSession (WindowsDriver

< WindowsElement >

Source) {desktopSession = source;} public WindowsDriver

< WindowsElement >

DesktopSessionElement {get {return desktopSession;}} public WindowsElement FindElementByAbsoluteXPath (string xPath, int nTryCount = 10) {WindowsElement uiTarget = null;var index = xPath.IndexOf (value:'/', startIndex: 1); xPath = xPath.Substring (startIndex: index); while (nTryCount-- > 0) {try {uiTarget = desktopSession.FindElementByXPath (xpath: $"/ {xPath}");} catch {Console.WriteLine ($@ "Find failed:"{xPath}");} if (uiTarget! = null) break;Thread.Sleep (millisecondsTimeout: 100) Return uiTarget;} public IOptions Manage () {return this.desktopSession.Manage ();} public void CloseApp () {this.desktopSession.CloseApp ();}}

4. Copy and paste the following test fixture into the UnitTest1.cs file:

Public class Tests {Process pWad;const string PathToTheDemo = @ "C:\ Users\ Public\ Documents\ DevExpress Demos 20.2\ Components\ WPF\ DevExpress.OutlookInspiredApp.Wpf\ bin\ DevExpress.OutlookInspiredApp.Wpf.exe"; protected DesktopSession desktopSession {get;private set;} [OneTimeSetUp] public void FixtureSetup () {StartWAD (); var options = new AppiumOptions (); options.AddAdditionalCapability (capabilityName: "app", capabilityValue: PathToTheDemo); options.AddAdditionalCapability (capabilityName: "deviceName", capabilityValue: "WindowsPC") Options.AddAdditionalCapability (capabilityName: "platformName", capabilityValue: "Windows"); var driver = new WindowsDriver

< WindowsElement >

(new Uri ("http://127.0.0.1:4723"), options); desktopSession = new DesktopSession (driver); WaitSplashScreen (driver);} static void WaitSplashScreen (WindowsDriver)

< WindowsElement >

Driver) {var cwh = driver.CurrentWindowHandle;while (driver.WindowHandles.Contains (cwh)) Thread.Sleep (1000); driver.SwitchTo (). Window (driver.WindowHandles [0]);} private void StartWAD () {var psi = new ProcessStartInfo (@ "C:\ Program Files (x86)\ Windows Application Driver\ WinAppDriver.exe"); psi.EnvironmentVariables.Add ("DX.UITESTINGENABLED", "1"); pWad = Process.Start (psi);} [OneTimeTearDown] public void FixtureTearDown () {desktopSession.CloseApp (); pWad.Kill () } [SetUp] public void Setup () {} [Test] public void Test1 () {Assert.Pass ();}}

The FixtureSetup method does the following:

Call the StartWAD method, which starts WinAppDriver.exe and enables UI test mode.

Create a new Appium test session.

Call the WaitSplashScreen method and suspend the test during the application load operation.

UI test mode

Switch the DevExpress WPF control to UI test mode by setting the DX.UITESTINGENABLED environment variable to 1 or the ClearAutomationEventsHelper.UITestingEnabled property to true for the application under test (when the application starts). This mode results in the following changes:

Animation is disabled.

The context menu is activated only when the mouse is clicked and does not open when the mouse pointer is over the menu.

The UI automation tree has been modified to produce more stable and reliable UI tests.

Recording test

Follow these steps to record the test:

1. Run the WinAppDriver UI logger as an administrator.

two。 Set a breakpoint in the Test1 method.

3. Debug the Test1 test, which runs the OutlookInspired demo application and enables the UI test mode.

4. Click the Record button in the WinAppDriver UI logger window.

Hover over the New Employee button and wait until the recorder displays a blue border around the button. This means that the logger is ready to capture input, click the button.

Hover over the First Name text field and wait until the logger is ready to capture the input and enter a value.

Repeat the previous step for the Last Name, Title, Mobile Phone, and Email text fields.

Record the clicks on the Save & Close button.

5. In the Recorder window, click the Pause and copy button to copy the generated code to the clipboard.

Shortcoming

The approach outlined above has some disadvantages:

These tests use the FindElementByXPath method to find elements, which is slow because it parses the entire visual tree. On our test machine, the test took 1 minute and 32 seconds.

These tests are difficult to maintain because they use absolute XPath to locate elements, and changes to the application layout can break the tests.

These tests are difficult to read.

Rewrite test

We can rewrite the test to solve the above problem (and speed up the test). You can analyze the recorded xpath or use inspection tools to get element attributes, such as Names, ClassNames, and AccessibilityIds.

Use WinAppDriver's FindElementByName, FindElementByClassName, and FindElementByAccessibilityId methods to find application elements, which are faster than the FindElementByAbsoluteXPath method. Tests based on these methods do not fail when you modify the layout of your application.

[Test] [Order (0)] public void CreateEmployee () {var desktopElement = desktopSession.DesktopSessionElement;var bNewEmployee = desktopElement.FindElementByName ("NewEmployee"); bNewEmployee.Click (); WindowsElement newEmployeeWindow = null;while (newEmployeeWindow = = null) newEmployeeWindow = desktopElement.FindElementByName ("Employee (New)"); newEmployeeWindow.FindElementByName ("First Name"). FindElementByClassName ("TextEdit"). SendKeys ("John"); newEmployeeWindow.FindElementByName ("Last Name"). FindElementByClassName ("TextEdit"). SendKeys ("Doe") NewEmployeeWindow.FindElementByName ("Title"). FindElementByClassName ("TextEdit"). SendKeys ("CTO"); newEmployeeWindow.FindElementByName ("Mobile Phone"). FindElementByClassName ("ButtonEdit"). SendKeys ("1111111111"); newEmployeeWindow.FindElementByName ("Email"). FindElementByClassName ("ButtonEdit"). SendKeys ("john.doe@dx-email.com"); newEmployeeWindow.FindElementByName ("Save & Close"). Click ();}

The rewritten test takes only 25 seconds.

This is the end of the content of "what are the advantages of the interface control DevExpress WPF". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report