Thread: [NUnitAsp-devl] Re: [Nunitasp-users] HtmlTag (and HtmlControlTester)
Brought to you by:
jlittle82
From: Cory F. <Cor...@mo...> - 2005-05-23 21:02:13
|
Jim Shore wrote: > In order to enable NUnitAsp to test legacy code, I'm putting in a lot of > new features. Multiple forms are now supported, as is the ability to > emulate Javascript without writing a custom tester. Next on the list is > testers for HTML controls and testing HTML tags that don't have an ID. > XPath will probably be part of that, although I haven't decided for sure. > > The current "no guarantees" release date for the next version is August > or September. XPath would be extremely helpful for testing Mobile Controls. Even using "ASP.NET to it's fullest" still the only way to use it to test Mobile Controls is by using XPath (and it isn't pretty XPath either). My first stab at working on the extension for mobile controls I stopped because I also couldn't figure out how to get it to use XPath. I was able to get all the way up to that point, but not quite. In my situation it's a little different in that, for mobile controls, you know the ID, and can relate it to a tag, but only by going through the value of another tag. Because some phones treat tags named the same as being the same (even if they are on different cards), ASP.NET uses a unique naming scheme which does something like: <wml> <card> <onevent type="onenterforward"> <refresh><setvar name="mcsv0" value="" /></refresh> </onevent> <do type="accept" label="GO"> <go href="mobileindex.aspx"> <postfield name="__EVENTTARGET" value="_ctl2:cmdMasterPermitCollectorSubmit" /> <postfield name="_ctl2:MasterPermitText" value="$(mcsv0)" /> </go> </do> <p>Master Permit Number<input name="mcsv0" format="*N" /></p> </card> </wml> So you basically have to iterate through the postfield nodes looking for the value in the variable notation (in the above case $(mcsv0) and match that to the the server-side name. In addition, you have to iterate though the setvar nodes to see what the default value was coming into the page, and iterate though the input tags to match the assigned name to set the value. Sorry, that was the long answer. The short answer, I would *love* to see XPath support. :) Even if I had to do a lot of overriding to extend the classes, it would be helpful. I'd be willing to throw my hat in closer to the second week of July (maybe some time in June if I can get this current project finished up). Cory |
From: Dave P. <n0n...@gm...> - 2005-05-23 22:35:44
|
I've got a solution for this, though I may be using a class inappropriately= . Using the Strategy pattern (GOF), I factored out the strategy for finding the tag for a tester. I call this strategy a "locator" and I created an interface IHtmlTagLocator, with one method: Locate( ), which returns an HtmlTag. I have a base class that derives from HtmlControlTester and has a constructor that takes an IHtmlTagLocator (among other things). Then, I overloaded the Tag property, and use the locator to get the HtmlTag. Then I have two classes that implement IHtmlTagLocator -- one for aspId, and one for XPath. The benefit of doing it this way is that I can create all my custom testers that are specialized for images, or whatever, and I don't have to implement one using ID and the other using XPath. One small problem is that I lied two paragraphs back. Turns out b/c of the current design, you can't create a locator using AspId because it's done by the tester base class. Some refactoring of the base classes is required for this to work, I think, and that may not be deemed appropriate. For now, I just call base.Tag if no locator was specified. But I think factoring the location out of the tester would be a good thing, since testing the tag (mapping properties and such) should not be affected by the method used to find it. Anyway, just my $.02. Dave P.S. I think there's also a problem regarding detecting page updates.=20 It probably means more objects need to be sent to the XPathLocator constructor (e.g. the HttpClient object) On 5/23/05, Cory Foy <Cor...@mo...> wrote: > Jim Shore wrote: > > In order to enable NUnitAsp to test legacy code, I'm putting in a lot o= f > > new features. Multiple forms are now supported, as is the ability to > > emulate Javascript without writing a custom tester. Next on the list i= s > > testers for HTML controls and testing HTML tags that don't have an ID. > > XPath will probably be part of that, although I haven't decided for sur= e. > > > > The current "no guarantees" release date for the next version is August > > or September. >=20 > XPath would be extremely helpful for testing Mobile Controls. Even using > "ASP.NET to it's fullest" still the only way to use it to test Mobile > Controls is by using XPath (and it isn't pretty XPath either). >=20 > My first stab at working on the extension for mobile controls I stopped > because I also couldn't figure out how to get it to use XPath. I was > able to get all the way up to that point, but not quite. >=20 > In my situation it's a little different in that, for mobile controls, > you know the ID, and can relate it to a tag, but only by going through > the value of another tag. Because some phones treat tags named the same > as being the same (even if they are on different cards), ASP.NET uses a > unique naming scheme which does something like: >=20 > <wml> > <card> > <onevent type=3D"onenterforward"> > <refresh><setvar name=3D"mcsv0" value=3D"" /></refresh> > </onevent> > <do type=3D"accept" label=3D"GO"> > <go href=3D"mobileindex.aspx"> > <postfield name=3D"__EVENTTARGET" > value=3D"_ctl2:cmdMasterPermitCollectorSubmit" /> > <postfield name=3D"_ctl2:MasterPermitText" > value=3D"$(mcsv0)" /> > </go> > </do> > <p>Master Permit Number<input name=3D"mcsv0" format=3D"*N" /></p> > </card> > </wml> >=20 > So you basically have to iterate through the postfield nodes looking for > the value in the variable notation (in the above case $(mcsv0) and match > that to the the server-side name. In addition, you have to iterate > though the setvar nodes to see what the default value was coming into > the page, and iterate though the input tags to match the assigned name > to set the value. >=20 > Sorry, that was the long answer. The short answer, I would *love* to see > XPath support. :) Even if I had to do a lot of overriding to extend the > classes, it would be helpful. I'd be willing to throw my hat in closer > to the second week of July (maybe some time in June if I can get this > current project finished up). >=20 > Cory >=20 >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by Oracle Space Sweepstakes > Want to be the first software developer in space? > Enter now for the Oracle Space Sweepstakes! > http://ads.osdn.com/?ad_id=3D7412&alloc_id=3D16344&op=3Dclick > _______________________________________________ > Nunitasp-users mailing list > Nun...@li... > https://lists.sourceforge.net/lists/listinfo/nunitasp-users > |