Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Component IDs(How to set component IDs for automated testing)
Component IDs [message #1403177] Tue, 22 July 2014 07:34 Go to next message
Rok Štembergar is currently offline Rok ŠtembergarFriend
Messages: 4
Registered: July 2014
Junior Member
I want to perform tests on our Scout Web and Swing application with Robot Framework using Selenium and Swing library. These require components to have some form of identification on individual components.

I've noticed that this problem should be solved with Luna, at least for the Swing part in this post: http://www.eclipse.org/forums/index.php/t/636879/
Could anyone shed some light oh how this can be achieved, maybe also for the Web part of the app?

Thank you
Re: Component IDs [message #1403230 is a reply to message #1403177] Tue, 22 July 2014 14:26 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1250
Registered: October 2011
Senior Member
Can you tell what the requirements are for "Robot Framework using Selenium and Swing library"? I assume they define how they need to access to the GUI component.

For example: a common practice in the web, is to work with the "id" attribute of the elements (I am not sure to know if this is possible with Eclipse RAP).

What has been achive with Luna to provide a mechanism to have unique id for each element in the Scout Model. Depending on your use case (this is precisely why I ask) you need to propagate this id to the component in the UI layer.

.
Re: Component IDs [message #1403347 is a reply to message #1403230] Wed, 23 July 2014 07:05 Go to previous messageGo to next message
Rok Štembergar is currently offline Rok ŠtembergarFriend
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 #1404209 is a reply to message #1403347] Wed, 30 July 2014 13:17 Go to previous messageGo to next message
Rok Štembergar is currently offline Rok ŠtembergarFriend
Messages: 4
Registered: July 2014
Junior Member
I have here a part of the SwingLibrary's output which listed components from the swing application:

   Level: 11 Component: org.eclipse.scout.rt.ui.swing.ext.JPanelEx Index: 13 Name: null
                                     Level: 12 Component: org.eclipse.scout.rt.ui.swing.ext.JPanelEx Index: 14 Name: Synth.GroupBoxBody
                                        Level: 13 Component: org.eclipse.scout.rt.ui.swing.ext.JPanelEx Index: 15 Name: null
                                           Level: 14 Component: org.eclipse.scout.rt.ui.swing.ext.JStatusLabelEx Index: null Name: null
                                              Level: 15 Component: org.eclipse.scout.rt.ui.swing.ext.JPanelEx Index: 16 Name: null


SwingLibrary can successfully locate components by Name ( tested with the name Synth.GroupBoxBody from the above code ).

Taken from SwingLibrary's page:

If the identifier matches to internal name of a component (set using setName method in Java code), that component is chosen.

We need a way to set names for components/inputs etc. @ClassId as the name would be ok. Class names directly could probably also work.
Re: Component IDs [message #1404233 is a reply to message #1404209] Wed, 30 July 2014 15:09 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1250
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 #1404305 is a reply to message #1404233] Thu, 31 July 2014 07:08 Go to previous messageGo to next message
Rok Štembergar is currently offline Rok ŠtembergarFriend
Messages: 4
Registered: July 2014
Junior Member
@Order(20.0)
    @ClassId("7be3874c-9323-44be-833b-cd354ca0c1ce")
    public class NameInputField extends AbstractTextField {


And the SwingLibrary's output:

 Level: 14 Component: org.eclipse.scout.rt.ui.swing.ext.decoration.JTextFieldWithDecorationIcons Index: 1 Name: 7be3874c-9323-44be-833b-cd354ca0c1ce


Works like a charm!

If 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.).

Again thank you for your reply and time!
Re: Component IDs [message #1404321 is a reply to message #1404305] Thu, 31 July 2014 08:55 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1250
Registered: October 2011
Senior Member
Rok Štembergar wrote on Thu, 31 July 2014 09:08
If 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 #1779891 is a reply to message #1404321] Mon, 15 January 2018 12:28 Go to previous messageGo to next message
Andreas Christ is currently offline Andreas ChristFriend
Messages: 32
Registered: April 2016
Member
Hi all,

I wonder if you (BSI) have come to a conclusion on that issue yet.

Our problem: we like to test the scout application with selenium, and want to select not only form items but also menu items. A good idea is to have that good old HTML "id" attribute - but I haven't found a proper way to create it, there is no Scout method to create this in HTML.

Well, @ClassId doesn't work for menu items, and it is far away from form items, e.g.
<div class="form-field string-field value-field basic-field evbcontractno" style="left: 0px; top: 54px; width: 570px; height: 30px;">
  <label style="left: 0px; top: 0px; width: 140px; height: 30px;">Vertragsnummer</label>
  <span class="mandatory-indicator" style="top: 0px; left: 140px; width: 8px;"></span>
  <input autocomplete="false" spellcheck="false" class="field has-inner-alignment halign-left valign-top" wrap="off" maxlength="4000" style="left: 148px; top: 0px; width: 392px; height: 30px;" type="text">
  <span class="clear-icon needsclick unfocusable"></span>
  <span class="status" style="width: 20px; top: 0px; right: 0px; height: 30px; line-height: 30px;"></span>
</div>


You see, "evbcontractno" is not the INPUT tag itself, but the surrounding DIV tag.
            @Order(1000)
            @ClassId("evbcontractnoXXX")
            public class EVBContractNoField extends AbstractStringField {

                @Override
                protected String getConfiguredLabel() {
                    return TEXTS.get("EVBContractNo");
                }

                @Override
                protected String getConfiguredCssClass() {
                    return "evbcontractno";
                }
            }


BTW: @ClassId has no effect at all...

My question: how can I add "ID" attribute to any HTML element?
Re: Component IDs [message #1779950 is a reply to message #1779891] Tue, 16 January 2018 06:44 Go to previous messageGo to next message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 104
Registered: November 2010
Senior Member
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 Go to previous message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 104
Registered: November 2010
Senior Member
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
Previous Topic:Custom login on scout
Next Topic:[6.1.0.M5] Missing RunContext when calling Service from CredentialVerifier
Goto Forum:
  


Current Time: Mon Nov 19 06:49:07 GMT 2018

Powered by FUDForum. Page generated in 0.03199 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top