Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Automated testing, and div naming
Mon, Jun 26 2017 7:26 AMPermanent Link

Matthew Jones

Has anyone done any automation of WebBuilder apps? I'd like to have a basic regression test suite for my application, as I keep breaking some minor thing while building new stuff. The one I'm looking at at the moment is GhostInspector. However, it uses named div's to work out if things are working, and looking at my application in the browser, all the divs have no classname and no id. Is it possible for my code to add these? Or ideally, for them to be added automatically?

I realise that it might reveal information, but perhaps it could be optional. I also have multiple instances of the same form, so "Edit1" will occur more than once, so a way to intercept or make the id relate to the parent name too might be good.

Anyway, if anyone has done this sort of thing before, please say...

--

Matthew Jones
Mon, Jun 26 2017 9:35 AMPermanent Link

Matthew Jones

Quick test shows how it behaves:


Click on input[name="editEmail"]

Assign mj into input[name="editEmail"]

Click on div:nth-of-type(3) > div:nth-of-type(2) > div:nth-of-type(1) > div:nth-of-type(4) > div:nth-of-type(3) > div:nth-of-type(3) > div:nth-of-type(1) > div:nth-of-type(1) > div:nth-of-type(2) > div > div > div:nth-of-type(1) > div:nth-of-type(1) > div:nth-of-type(1) > div:nth-of-type(2) > div:nth-of-type(1) > div:nth-of-type(4)
ELEMENT NOT FOUND



--

Matthew Jones
Mon, Jun 26 2017 10:14 AMPermanent Link

Matthew Jones

This appears to work:

   Button1.ClientElement.Id := 'HelloMum';

It is only affecting the top level of the button, and I'm not sure how this would affect the clicks, as the other elements of the button also have the OnClick active.
I guess I'd have to traverse all the child elements and name them too.

I think I'd be happy to traverse the whole DOM to fill this in. One risk of course is that I break framework code that uses the names/id's of elements. I guess just leaving anything that has a name would be the ideal anyway.

Got to stop for the day, so will pick up later.

--

Matthew Jones
Mon, Jun 26 2017 1:46 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< This appears to work: >>

Yes, that is the correct way to handle this.

<< It is only affecting the top level of the button, and I'm not sure how this would affect the clicks, as the other elements of the button also have the OnClick active. >>

Yes, but they all end up getting dispatched to the top-level element, the interface controller (TInterfaceController) anyway, so they don't really matter.  IOW, as long as you assign an ID to the interface controller elements, then you will be able to trigger/test clicks on a particular control.

<< I guess I'd have to traverse all the child elements and name them too. >>

No, that won't be necessary. Smile

<< I think I'd be happy to traverse the whole DOM to fill this in. One risk of course is that I break framework code that uses the names/id's of elements. I guess just leaving anything that has a name would be the ideal anyway. >>

EWB only uses the element names for HTML forms. Apart from that, it does not care about element IDs/names.

Tim Young
Elevate Software
www.elevatesoft.com
Tue, Jun 27 2017 10:17 AMPermanent Link

Matthew Jones

Matthew Jones wrote:

> Has anyone done any automation of WebBuilder apps?

Okay, a basic working version. In the FormCreate, call:

   AddItemIDs(Self, 'jo');

And that does enough to make app.ghostinspector.com work well enough. The 'jo' is the form identifier prefix, to keep things unique.

In the code below, g_xAppendValues is a TStringList global that can be used to make all items uniquely numbered, but I wanted forms of the same type to get the same number order for each one, so an intermediate list is used if it encounters a form. You can make one call for your parent form and everything is plastered, or do it individually.

I expect people will want to customise, but this is good starter code. The Copy calls are snipping the T or Tfrm from names.


function GetNextItemName(szSuffix : String; szComponentType : String; xList : TStringList = nil) : String;
var
   szCurrent : String;
   nValue : Integer;
begin
   if not assigned(g_xAppendValues) then
      g_xAppendValues := TStringList.Create;

   if not assigned(xList) then
       xList := g_xAppendValues;

   szCurrent := xList.Values[szComponentType];
   nValue := StrToIntDef(szCurrent, 1);
   xList.Values[szComponentType] := IntToStr(nValue + 1);
   if szSuffix <> '' then
       szSuffix := '-' + szSuffix;
   Result := 'XA' + szComponentType + szSuffix + IntToStr(nValue);
end;


procedure AddItemIDsInternal(xControl : TControl; szParentName : String; xNameList : TStringList);
var
   nLoop : integer;
   xComp : TControl;
   szCompType : String;
begin
   for nLoop := xControl.ControlCount - 1 downto 0 do
   begin
       xComp := xControl.Controls[nLoop];
       if TControlAccessor(xComp).ClientElement.id = '' then
       begin
           szCompType := Copy(xComp.classname, 2, 99);
           TControlAccessor(xComp).ClientElement.id := GetNextItemName('', szParentName + '-' + szCompType, xNameList);
       end;                          
       if xComp is TFormControl then
       begin
           szParentName := szParentName + '=' + Copy(xComp.ClassName, 5, 99);
           AddItemIDs(xComp, szParentName);
       end
       else
       begin
           AddItemIDsInternal(xComp, szParentName, xNameList);
       end;
   end;
end;

procedure AddItemIDs(xControl : TControl; szParentName : String);
var
   nLoop : integer;
   xComp : TControl;
   xNameList : TStringList;
begin
   if not g_bEnableItemIDs then
       exit;
            
   if szParentName = '' then
       szParentName := Copy(xControl.classname, 2, 99);

   xNameList := TStringList.Create();
   try
       AddItemIDsInternal(xControl, szParentName, xNameList);
   finally
       xNameList.Free;
   end;
end;


--

Matthew Jones
Image