JScript, compile time, and FindChild: Using objects to organize namemappings, doin' it wrong?
I asked a question recently about the usage of regex & wildcards in the FindChild method, and this is where that question came from. My workplace has a test project that hasn't been maintained and was quite a mess, so I went in and updated it, hoping to make the test not only more robust but more legible. My master plan was to create four classes that would represent the four different chunks of the UI that would be tested. Of course, JScript doesn't have "classes" like those who have programmed in langauges like C#, Python, Java, etc. are used to, but one can do something like
function UIElement() {
// Properties this.Property1 = "hello"; this.Property2 = 3; }
var element = UIElement();
Now this seemed great at first glance, because I could represent some GUI element like an element with a grid inside of it like this
var parentElement = Aliases.Program.InformationDisplay.InfoDisplayWindow; function InformationGrid() { this.Grid = parentElement.FindChild("className", "info_container", 3); this.GridRows = this.Grid.FindAllChildren("className", "info-details", 5); this.GetDogName = function(rowIndex) { var name = this.GridRows[rowIndex].FindChild("className", "name-panel", 3).contentText; Log.Message(name); } }
which would reduce method size despite introducing more methods, introduce code clarity, and provide some level of abstraction for future usage; all pending code review. I wrote the four JScript classes I wanted in another script unit within the project. I had hoped I could go through the following chain of steps for the tests in question:
- Ensure that our software is running - if it isn't, open it (we have a method for this)
- Open the window in our software that we want to test (also have a method for this)
- Call an initializer method from the script unit I just wrote which uses a mix of aliases and FindChild to point out where the UI elements are in the object hierarchy
- Run the test, which would then call the various classes and perform the tests
- Finish the test and close the window
However, when I run the test, I get a JScript runtime error that the very first property of the very first class in the script unit that I've written to house my GUI representing classes is "null or not an object"
function WorkSearchBar() { this.SearchTypeDropdown = schedDisplaySearchBar.FindChild("className", "dropdown", 6); // Errors out here this.DropdownButton = this.SearchTypeDropdown.FindChild("className", "btn btn-default dropdown-toggle ng-binding", 2); this.SubmitButton = schedDisplaySearchBar.FindChild(new Array("className", "idStr"), new Array("btn btn-default", "submitSearch"), 8); this.SetDropdown = function(item) { this.DropdownButton.DropDown(); this.SearchTypeDropdown.FindChild("contentText", item, 4).Click(); } }
The error makes sense because the software isn't open yet (would more than likely be a null reference exception in C#/Java/etc), but this script unit shouldn't be hit yet. In the workflow above, I have the software set to open before anything else in the test method. Shouldn't this only come into play when its needed because of JIT compilation? Is JScript not JIT compiled? Is this "representing GUI elements as objects using a mix of aliases and FindChild" plan an unsupported approach?