In trying to simulate a JavaScript alert dialog earlier, I ran into an issue with recording a "Tab" press from an input box.
Here is the scenario:
1) Type date into input1
2) Tab to next field
a) if input1 date is older than 6 months old, javascript alert notifying user (scenario I am testing, and going to take a screenshot of in the test).
b) if input1 date is within range, no javascript alert
When I played back the test, which had a "Handle 'Alert' Dialog", to my surprise, the test was hanging as that Alert never came up.
After some fiddling, I converted the step to code which is below:
This is all being tested against a third party product, which I have no control over the javascript functions that result from the input box. The input is below:
As you can see it appears there is a lot going on here.
The issue comes with the "ActiveBrowser.ContentWindow.SetFocus();" line. If I remove this line, the Alert will show up like normal.
What I think is occuring is, the "ActiveBrowser.ContentWindow.SetFocus();" line is not allowing the "onchange
My question is, is the "ActiveBrowser.ContentWindow.SetFocus();" necessary as part of the default "Tab" record key action?
P.S. I know I can take care of all JavaScript Alert dialogs by using the following:
..and I plan on it. But I also want to work in taking a screenshot of the JavaScript alert and I haven't got into custom dialog handlers yet.
Here is the scenario:
1) Type date into input1
2) Tab to next field
a) if input1 date is older than 6 months old, javascript alert notifying user (scenario I am testing, and going to take a screenshot of in the test).
b) if input1 date is within range, no javascript alert
When I played back the test, which had a "Handle 'Alert' Dialog", to my surprise, the test was hanging as that Alert never came up.
After some fiddling, I converted the step to code which is below:
[CodedStep(@"Keyboard (KeyPress) - Tab (1 times) on 'NewCensusEffectiveDateTextBox'")] public void NavToPatient_CodedStep() { ActiveBrowser.ContentWindow.SetFocus(); Pages.AdminCensus.NewCensusEffectiveDateTextBox.ScrollToVisible(); Pages.AdminCensus.NewCensusEffectiveDateTextBox.Focus(); ActiveBrowser.Manager.Desktop.KeyBoard.KeyPress(ArtOfTest.WebAii.Win32.KeyBoard.KeysFromString("Tab"), 100, 1); ActiveBrowser.WaitUntilReady(); }This is all being tested against a third party product, which I have no control over the javascript functions that result from the input box. The input is below:
<input type=text size=10 maxlength=10 name=effective_date value="1/1/2001" onkeypress="return filterKeys(event)" onfocus='setDateItem(this, "P")' onblur="reformatDate(this)" onchange='reformatDate(this); javascript:ESOLValidateDateString(frmData.effective_date);checkUpdateCareLevel();' >As you can see it appears there is a lot going on here.
The issue comes with the "ActiveBrowser.ContentWindow.SetFocus();" line. If I remove this line, the Alert will show up like normal.
What I think is occuring is, the "ActiveBrowser.ContentWindow.SetFocus();" line is not allowing the "onchange
='reformatDate(this);" to run.My question is, is the "ActiveBrowser.ContentWindow.SetFocus();" necessary as part of the default "Tab" record key action?
P.S. I know I can take care of all JavaScript Alert dialogs by using the following:
public override void OnBeforeTestStarted() { Manager.DialogMonitor.AddDialog(new AlertDialog(ActiveBrowser, DialogButton.OK)); Manager.DialogMonitor.Start(); }..and I plan on it. But I also want to work in taking a screenshot of the JavaScript alert and I haven't got into custom dialog handlers yet.