Home » Eclipse Projects » Eclipse Scout » Component IDs(How to set component IDs for automated testing)
| |
Re: Component IDs [message #1403347 is a reply to message #1403230] |
Wed, 23 July 2014 07:05 |
Rok Štembergar Messages: 4 Registered: July 2014 |
Junior Member |
|
|
First of i would like to thank you for your reply.
For the Selenium Library, it can locate elements in html code by looking their tags, text, links, css.. 'It is also possible to give an arbitrary XPath or DOM expression as locator.'
So basically, as far as i can see, anything that makes a component unique in html code would do. Testing this in Luna i saw no noticable identification of a component in the Web application, aside from text, but this is not a good way to locate components.
For the Swing Library, the identifier can be:
- The logical name of the component given by the developer. This is the recommended approach as such internal names are likely to be stable.
- The index of the component in its own context, such as the 3rd button in the context. Indexes change when components are added, removed or reordered so this is a relatively fragile approach.
- Title, label or other visible text of the component. Visible texts can change, especially if the application is translated, so this is also a fragile approach.
I made it work with labels and indexes, but the first option is probably best to aim for. I hope i clarified things a bit and again, thank you.
|
|
| |
Re: Component IDs [message #1404233 is a reply to message #1404209] |
Wed, 30 July 2014 15:09 |
Jeremie Bresson Messages: 1252 Registered: October 2011 |
Senior Member |
|
|
I did not forget you. I did not have enough time to test and to describe the new mechanim introduced with luna.
I think the AbstractSwingEnvironment.assignWidgetId(ITypeWithClassId, ISwingScoutComposite) is the method you are looking for.
It seems to me, that there is a new parameter "org.eclipse.scout.rt.widgetIdsEnabled" that you can set to true to active the mechanism. The Problem is, the current "assign id mechanism" implementation is not doing what you decribe here:
Quote: If the identifier matches to internal name of a component (set using setName method in Java code), that component is chosen.
By the way, using setName() is also what Jubula needs. So you need to override assignWidgetId().
Here a dirty hack (without checking the "org.eclipse.scout.rt.widgetIdsEnabled" parameter) that you can use to test:
public class SwingEnvironment extends DefaultSwingEnvironment {
@Override
protected void assignWidgetId(ITypeWithClassId model, ISwingScoutComposite uiField) {
JComponent swingField = uiField.getSwingField();
swingField.setName(model.classId());
}
}
I did not try it. I did not discuss it with the developpers. It is only what I found out from some code analysis.
It would be great to test and document this new feature in detail.
For the moment the only input I found is here:
https://wiki.eclipse.org/Scout/NewAndNoteworthy/4.0#Using_Id_in_test_tools
[Updated on: Wed, 30 July 2014 15:11] Report message to a moderator
|
|
| |
Re: Component IDs [message #1404321 is a reply to message #1404305] |
Thu, 31 July 2014 08:55 |
Jeremie Bresson Messages: 1252 Registered: October 2011 |
Senior Member |
|
|
Rok Štembergar wrote on Thu, 31 July 2014 09:08If i understand correctly, org.eclipse.scout.rt.widgetIdsEnabled enables SWT and SWING only. Is there a way to propagate these IDs for the web app?
As i mentioned above, the SeleniumLibrary offers a plethora of ways to find components, almost anything would do (id tag, name tag, class names, etc.).
You are correct. It would really be nice to have the Web-UI too. I think nobody took time to understand how it can be implemented with Eclipse-RAP.
.
[Updated on: Thu, 31 July 2014 13:11] Report message to a moderator
|
|
| |
Re: Component IDs [message #1779950 is a reply to message #1779891] |
Tue, 16 January 2018 06:44 |
|
Andreas,
If you pass the URL parameter ?inspector=true to your application, Scout will automatically add two HTML5 attributes to the DOM elements for all fields:
- data-classid: contains the value of the @ClassId annotation of the field
- data-modelclass: contains the java class name of the field
Note that the URL parameter is disabled by default on production systems for security reasons. In development mode, the parameter is enabled by default. Otherwise it can explicitly be allowed by setting scout.urlHints.enabled=true in your config.properties.
These IDs are intended to be used in automated tests. In fact, we use Selenium ourselves. There is an AbstractSeleniumTest in the module org.eclipse.scout.rt.ui.html.selenium that you can inherit your test classes from. It is available from the 6.1.x branch and provides some nice utility functions, e.g. to select the input field of a scout form field. (As you have noted, form fields consist of a wrapped DOM structure. The container represents the model field and consists of the label, the mandatory indicator, a status icon, and the actual input field it self. Some fields, such as the date field, can contain more than one <input> field. The correct element can be selected using XPath expressions in selenium. The provided utility functions automatically convert Java class references to XPath expressions.)
Here is an example selenium test for the "Widgets" demo application:
https://github.com/BSI-Business-Systems-Integration-AG/org.eclipse.scout.docs/tree/releases/6.1.x/code/widgets/org.eclipse.scout.widgets.ui.html.app.selenium
Regards,
Beat
|
|
|
Re: Component IDs [message #1780005 is a reply to message #1779950] |
Tue, 16 January 2018 13:17 |
|
Just to make it clear (since this thread is actually quite old and originally discusses Swing, SWT and RAP UIs of Scout <= 4): What I descriped only applies to the new HTML 5 UI (since Scout version 5.2). The code snippets Andreas provided seem to imply that he indeed uses the new UI (e.g. getConfiguredCssClass did not exist in previous versions). My appologies if I should have guessed wrongly, though.
In case you are still using Swing/SWT/RAP UI: I'm not aware of a simple built-in method to generate IDs in the output. It should be possible somehow (after all, it's just software), but I would not put too much effort in this, since the old UIs are not maintained anymore. My recommendation would be to upgrade to a newer version of Scout and switch to the HTML UI. There are migration guides at http://eclipsescout.github.io/.
Regars,
Beat
|
|
|
Goto Forum:
Current Time: Wed Feb 05 05:50:23 GMT 2025
Powered by FUDForum. Page generated in 0.06036 seconds
|