Wicket
  1. Wicket
  2. WICKET-1830

Include Component Path in Generated Markup

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3.5, 1.4-RC1
    • Component/s: wicket
    • Labels:
      None

      Description

      For unit testing purposes, it would be nice to know the exact ids of the components on your wicket pages. Perhaps the generated markup could contain a wicket:path attribute?

      <div wicket:path="some:path:to:this:div">

        Issue Links

          Activity

          Hide
          James Carman added a comment -

          As I mentioned in the email thread, I'd like to try to take a stab at this one. I'll try to submit a patch soon.

          Show
          James Carman added a comment - As I mentioned in the email thread, I'd like to try to take a stab at this one. I'll try to submit a patch soon.
          Hide
          Igor Vaynberg added a comment -

          i waited a couple of days james, but didnt see a patch so i put this in myself as it is also useful to us for our selenium tests

          Show
          Igor Vaynberg added a comment - i waited a couple of days james, but didnt see a patch so i put this in myself as it is also useful to us for our selenium tests
          Hide
          Timo Rantalaiho added a comment -

          Hey Igor, did you try if this can really be used with Selenium?

          My colleague seemed to remember that colon ( would cause problems in values and attribute names when used in Selenium xpath expressions. So it might be good to make their format pluggable.

          Maybe something like

          if (getApplication().getDebugSettings().isOutputComponentPath())

          { IWicketPathPrinter printer = getApplication().getDebugSettings().getWicketPathPrinter(); tag.put(printer.getPathAttributeName(), printer.getWicketPathOf(this); }

          public class DefaultWicketPathPrinter implements IWicketPathPrinter
          {
          public String getPathAttributeName()

          { return "wicket:path"; }

          public String getWicketPathOf(Component component)

          { return component.getPageRelativePath(); }

          }

          Show
          Timo Rantalaiho added a comment - Hey Igor, did you try if this can really be used with Selenium? My colleague seemed to remember that colon ( would cause problems in values and attribute names when used in Selenium xpath expressions. So it might be good to make their format pluggable. Maybe something like if (getApplication().getDebugSettings().isOutputComponentPath()) { IWicketPathPrinter printer = getApplication().getDebugSettings().getWicketPathPrinter(); tag.put(printer.getPathAttributeName(), printer.getWicketPathOf(this); } public class DefaultWicketPathPrinter implements IWicketPathPrinter { public String getPathAttributeName() { return "wicket:path"; } public String getWicketPathOf(Component component) { return component.getPageRelativePath(); } }
          Hide
          Igor Vaynberg added a comment -

          i definately do not think we need to go this far, just find a character that works, perhaps escape : with _

          Show
          Igor Vaynberg added a comment - i definately do not think we need to go this far, just find a character that works, perhaps escape : with _
          Hide
          Igor Vaynberg added a comment -

          and its in

          Show
          Igor Vaynberg added a comment - and its in
          Hide
          Timo Rantalaiho added a comment -

          Looks good, cheers Igor!

          Show
          Timo Rantalaiho added a comment - Looks good, cheers Igor!
          Hide
          Frank van Lankvelt added a comment -

          As an example of how this functionality can be used, a small HOWTO for the Selenium IDE.

          Create a folder "wicketPathLocatorBuilder" with the file "user-extension.js.wicketPathLocatorBuilder". Paste the following snipped in this file.

          LocatorBuilders.add('wicketpath', function(e) {
          this.log.debug("wicketpath: e=" + e);
          if (e.attributes && e.hasAttribute("wicketpath"))

          { this.log.info("found attribute " + e.getAttribute("wicketpath")); return "//" + this.xpathHtmlElement(e.nodeName.toLowerCase()) + "[@wicketpath=" + this.attributeValue(e.getAttribute("wicketpath")) + "]"; }

          return null;
          });

          LocatorBuilders.order.unshift(LocatorBuilders.order.pop());

          Install the Selenium IDE plugin for Firefox from http://seleniumhq.org/download/ .

          Open the Selenium IDE, go to menu Options -> Options. In the Selenium Core extensions input field, paste the path to the earlier created folder "wicketPathLocatorBuilder". Restart firefox.

          You can now record tests by clicking and/or right-clicking to insert additional commands. By default, the wicketpath attribute is used to generate an element locator.

          Show
          Frank van Lankvelt added a comment - As an example of how this functionality can be used, a small HOWTO for the Selenium IDE. Create a folder "wicketPathLocatorBuilder" with the file "user-extension.js.wicketPathLocatorBuilder". Paste the following snipped in this file. LocatorBuilders.add('wicketpath', function(e) { this.log.debug("wicketpath: e=" + e); if (e.attributes && e.hasAttribute("wicketpath")) { this.log.info("found attribute " + e.getAttribute("wicketpath")); return "//" + this.xpathHtmlElement(e.nodeName.toLowerCase()) + "[@wicketpath=" + this.attributeValue(e.getAttribute("wicketpath")) + "]"; } return null; }); LocatorBuilders.order.unshift(LocatorBuilders.order.pop()); Install the Selenium IDE plugin for Firefox from http://seleniumhq.org/download/ . Open the Selenium IDE, go to menu Options -> Options. In the Selenium Core extensions input field, paste the path to the earlier created folder "wicketPathLocatorBuilder". Restart firefox. You can now record tests by clicking and/or right-clicking to insert additional commands. By default, the wicketpath attribute is used to generate an element locator.
          Show
          Igor Vaynberg added a comment - added to http://cwiki.apache.org/confluence/display/WICKET/Selenium+Tips cheers

            People

            • Assignee:
              Igor Vaynberg
              Reporter:
              James Carman
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development