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

          James Carman created issue -
          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.
          Igor Vaynberg made changes -
          Field Original Value New Value
          Assignee Igor Vaynberg [ ivaynberg ]
          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
          Igor Vaynberg made changes -
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 1.4-M4 [ 12313295 ]
          Fix Version/s 1.3.5 [ 12313175 ]
          James Carman made changes -
          Comment [ Ok, cool. I did look through the source to try to figure out where this would go. I didn't find a nice quick and easy place to make this change. So, I didn't get around to it yet. Out of curiosity, do you have the SVN version number of your checkin? I'd love to see the code changes (I don't get SVN commit messages). ]
          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
          Igor Vaynberg made changes -
          Link This issue relates to WICKET-2832 [ WICKET-2832 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Resolved Resolved
          2d 21h 10m 1 Igor Vaynberg 15/Sep/08 21:13

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development