WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

How to debug test project when testing using WinAppDriver

Open Arulpriya opened this issue 2 years ago • 5 comments

Hi Team,

We have our custom control that acts like MS DataGrid. We used the Windows driver to retrieve the framework elements and perform some actions on the control (like click). But the elements are not retrieved properly and we need to debug through the methods of our custom control from Windows driver methods. Can you suggest a way to debug the testing project? Below are the method that we use from Windows driver to get elements.

var options = new AppiumOptions(); options.AddAdditionalCapability("app", @"\....\bin\Debug\GridControlDemo.exe"); options.AddAdditionalCapability("deviceName", "LAPN-23996"); _driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723/"), options); _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); Actions actions = new Actions(_driver); var grid1 = _driver.FindElementByAccessibilityId("Grid1"); var firstCellValue = grid1.FindElementByName("GridCell_R1_C1"); actions.MoveToElement(firstCellValue).ContextClick().Build().Perform();

Thanks in Advance, Arulpriya R

Arulpriya avatar Aug 19 '22 06:08 Arulpriya

Arulpriya What do you mean to Debug? Why you cannot use standart methods of your IDE?

Shakevg avatar Aug 19 '22 08:08 Shakevg

Hi @Shakevg,

Our use case is, When we have two custom controls in the same form and trying to retrieve the element by passing the FindElementByAccessibilityId, we get same instance for both grids. So, we could not perform click actions in the 2nd grid. Can you please suggest a solution to get each elements to perform actions?

Thanks in Advance, Arulpriya R

Arulpriya avatar Aug 24 '22 05:08 Arulpriya

Arulpriya Did you try to access to each grid by index:

var grids = _driver.FindElementsByAccessibilityId("Grid1");
var grid1 = grids[0];
var firstCellValue = grid1.FindElementByName("GridCell_R1_C1");
actions.MoveToElement(firstCellValue).ContextClick().Build().Perform();
var grid2 = grids[1];
firstCellValue = grid2.FindElementByName("GridCell_R1_C1");
actions.MoveToElement(firstCellValue).ContextClick().Build().Perform();

Shakevg avatar Aug 24 '22 20:08 Shakevg

Hi @Shakevg, Yes, we tried but we only get the single grid using FindElementByAccessibilityId method and we could get another grid by indexing. Thanks, Arulpriya R

Arulpriya avatar Aug 29 '22 12:08 Arulpriya

Arulpriya Could you post Session.PageSource here or screen with 2 grids

Shakevg avatar Aug 29 '22 18:08 Shakevg

Hi @Shakevg,

Please find the screen with 2 grids, image

vijayarasan avatar Oct 18 '22 14:10 vijayarasan

@vijayarasan I mean need to see how it looks like in inspector.exe (screen from inspector)

Shakevg avatar Oct 19 '22 06:10 Shakevg

Hi @Shakevg,

Please find the screen from inspector,

image

vijayarasan avatar Oct 22 '22 11:10 vijayarasan

@vijayarasan Grids looks different. Can you try to save PageSource: session.PageSource And check grids are available there with expected properties because real available XML can be different with Inspector

Shakevg avatar Oct 29 '22 18:10 Shakevg

@Shakevg Find the saved session.PageSource is in the attachment. Both grids are available in the attached document.

PageSource Saved File: PageSource.txt

vijayarasan avatar Nov 03 '22 14:11 vijayarasan

@vijayarasan Your grids have different AutomationId The next code should work:

var grid1 = _driver.FindElementByAccessibilityId("gridControl2");
var firstCellValue = grid1.FindElementByName("GridCell_R1_C1");
actions.MoveToElement(firstCellValue).ContextClick().Build().Perform();
var grid2 = _driver.FindElementByAccessibilityId("gridControl1");
firstCellValue = grid2.FindElementByName("GridCell_R1_C1");
actions.MoveToElement(firstCellValue).ContextClick().Build().Perform();

Shakevg avatar Nov 07 '22 16:11 Shakevg

@Shakevg We tried as you suggested, but it didn't work. We are getting the same Grid when accessing the grids by using FindElementByAccessibilityId. Look at the screenshot taken when debugging the test,

image

(Note: We used the cell value text to indicate that both grids have the same value)

The element ID in both grids is the same. So, we could not perform click actions in the second grid. Please suggest a solution to get each element to perform actions.

vijayarasan avatar Nov 11 '22 14:11 vijayarasan