简体   繁体   English

在CodedUi测试期间使用元素ID代替其位置

[英]Use element id instead of his location during CodedUi Test

I'm trying to make some CodedUI Test of my client web using my webapp and wondering why the generate code use X/Y location instead of Id of element ? 我正在尝试使用我的web应用程序对客户端网络进行一些CodedUI测试,并且想知道为什么生成的代码使用X / Y位置而不是element的ID? In case i make a successfull test, if i move a button of his current location the test will fail. 万一我进行了一次成功的测试,如果我移动他当前位置的按钮,则测试将失败。 Is it possible to change that behavior ? 可以改变这种行为吗? Force the Test Builder to work with id instead of location ? 强制测试生成器使用id而不是location? (he did that for my winform application but not the website) (他是为我的winform应用程序这么做的,但不是为网站所做的)

Thanks. 谢谢。

The generated code does not use x,y coordinates of the control, they are the coordinates within (or relative to ) the control. 所生成的代码不使用X,所述控制 y坐标,它们是(或相对于 )的控制范围内的坐标。

Commonly the code includes statements such as: 通常,代码包含以下语句:

Mouse.Click(uIControl, new Point(25, 12));

One purpose of the x,y part is for buttons that also have a drop down menu. x,y部分的目的是用于还具有下拉菜单的按钮。 (For example, the SAVE-AS button in some programs has a little triangle that, when clicked, provides a choice of format for the saved file.) The x,y coordinate allows Coded UI to click on the main button or open the menu. (例如,某些程序中的SAVE-AS按钮带有一个小三角形,单击该三角形可为保存的文件提供格式选择。)x,y坐标允许编码用户界面单击主按钮或打开菜单。 Another use can be seen with programs such as Microsoft Paint where the coordinate refers to a place within the drawing area. 在诸如Microsoft Paint之类的程序中,可以看到另一种用法,其中坐标指向绘图区域内的位置。 (To understand this, try recording the actions of making a simple drawing with Microsoft Paint and looking at the generated code.) (要理解这一点,请尝试记录使用Microsoft Paint绘制简单图形并查看生成的代码的动作。)

In most cases the x,y coordinates can safely be removed, so the statement above can be simplified to: 在大多数情况下,可以安全地删除x,y坐标,因此上面的语句可以简化为:

Mouse.Click(uIControl);

See here for a fuller explanation. 请参阅此处以获取更完整的说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM