in QTP, how to check whether a dialog is already open? - vbscript

I have been using the following code to check whether a dialog is already open
If Window(window_name).Dialog(dialog_name).Exist = False
Then '' //here qtp waits..
Window(window_name).WinMenu("Menu").Select menu_name
End If
This code is to avoid reopening the same dialog during each run of the code. But the qtp run waits about 10 - 15 seconds & then goes to next step. in what way we can avoid this?
If the dialog is not open, then the menu will be clicked to open the dialog.

The Exist property accepts a value of how long to wait for the object to exist.
If Window(window_name).Dialog(dialog_name).Exist(60) = False

The method mentioned is good. You can also try this method.
If (Window(window_name).Dialog(dialog_name)
.winbutton(Btn_name).Getroproperty("abs_x"))
This returns true if the object exists if not it returns false.

Related

Blocking code in custom message box in VB6

In my vb6 project, I created my own msgbox using a form, due to difficulties in changing
the font/language of in-built msgbox. A search with google gave the idea of own msg-
box rather than trying msgbox of VB. Now the problem is : - when the user exits the
program, 3 options are given: to close, to restart and to cancel exit. The user need not
again go through the process of giving password etc in restart option. If I give cancel =
true in the QueryUnload event, then 2nd option does not work, 3rd option works. If
cancel = true is not given, 2nd option works, but 3rd option does not. It appears that
the main form does not get unloaded if cancel = true. Unless & until the main form
unloads, the program will not work with the fresh data to be given by the user in the
initial Form. Since the code after "msgbox.show" depends on options, it is not possible
to write that code in the same sub, not even in the same form code. Is there any way
to stop the subsequent code after "msgbox.show" and continue the same after getting
option? (like in the in-built msgbox of VB.) I am not an expert in VB, so please correct
if I made some mistake; also help with advice/suggestions.
EDIT:- [Extended explanation]
The 3 forms in my project:
Initial form for password, data etc. This is input Form for user.
Main Form. This Form shows the results after process of input.
frmMsgBox. This is a custom msgbox created using a form.
Main Form code portion. Code for closing the program:
Private Sub Form_QueryUnload(Cancel as.......)
cancel = True
frmMsgBox.Label1.caption = Do you wish to 1.Exit 2.Restart
3.Cancel the exit?
frmMsgBox.Show
End sub
(The above msgbox is almost like an in-built msgbox in VB with
vbYesNoCancel buttons) The message is in regional language,
which was the main reason forced me to use my own msgbox.
After MsgBox appears, the user selects one of the above options
using 3 commandButtons placed in that Form. The code after
clicking these buttons is written in the code portion of frmMsgBox:
Command1_Click 'This is for Exit from the Program.
All Forms.unload, All forms set to nothing, end.
Command2_click 'This is for restarting the Program.
Unload Main Form, set to nothing
Load Initial Form
Initial Fom.show
frmMsgBox.Hide
Command3_Click 'This is for cancelling the exit request.
Main Form.Show
frmMsgBox.Hide
With the above code, I have no problem with options 1 & 3,
i.e; to exit from the program or to start. The frmMsgBox hides,
the initial form shows - these are OK, but the main form does
not unload nor it is removed from memory. Because of this,
whatever new data is given by the user in the initial form now
is not being processed, the main form is struck with the old results.
If cancel = true is removed from the code above, Options 1 & 2
are OK, but option 3 does not work. Then the Main Form loses
all its results (all labels, texts etc in that Form turn blank.)

If statement in QF-test

I am learning QF-test and want to do a simple if statement. If I make a change on this one page it enabled an "Apply" button that I want to click if it becomes enabled.
When I check if the button is enabled this is what appears
Check boolean: enabled (true) [buttonApply=>($client)]
So I want to say something like
if 'buttonApply.enabled'=="true"
Mouse Click [buttonApply=>($client)]
but that doesn't seem to work
Well I emailed QF-test support and got this answer
Set the variable in the field 'Variable for Result'. Let's say 'CompPresence'
When you run the script , the variable 'CompPresence' will be filled with the value 'true' if the button "Apply" is enabled.
You can use the If loop like If '$(CompPresence)'==”true”

Error 3020 if I try to navigate to a new record or save a record after a cancelled delete macro

I have a form that has two buttons. One for save and new the other delete. I used the macor wizard to create both of these. Everything works fine if I use the delete and press Yes but if I press No to cancel the delete and then try to navigate to a new record or save the existing one I get the error message "You tried to call Update or CancelUpdate or attempted to update a Field in a recordset without first calling AddNew or Edit. (Error 3020)". Once I get this error the form hangs. I can not do anything else on the form. When I try to close the form I get the same message and it refuses to save the record before closing.
I figured it out. There was a sub that ran when the form tried to delete that bombed. What I did was in the form's before del confirm I ran a sub that set a global variable to true that I used in the sub that was causing the problem to exit early. In the form's after del confirm I used a sub to reset the global variable to false. Works great now.

selenium.chooseOkOnNextConfirmation() is not working

I'm stuck in one of the confirmation message. Below is the code.
boolean bFlag = selenium.isConfirmationPresent(); // which gives bFlag= false
selenium.chooseOkOnNextConfirmation();
selenium.click("//input[#value='Approve']");
// On clicking Approve button confirmation messasge is displayed.
boolean Flag = selenium.isConfirmationPresent(); // Which gives flag= true
Selenium is unable to click OK in the confirmation. I'm unable to continue with further coding. Nun of the selenium commands is working after clicking on approve button.
Can any one help me on this
Regards
I only have a reference to a rather old piece of documentation, but I guess what is said there is still true
http://release.seleniumhq.org/selenium-core/1.0.1/reference.html#chooseOkOnNextConfirmation
every time a confirmation comes up, you must consume it with a corresponding getConfirmation, or else the next selenium operation will fail.
So your code should look like this:
selenium.chooseOkOnNextConfirmation();
selenium.click("//input[#value='Approve']");
String confirmation = selenium.getConfirmation();
assertEquals("expected text of confirmation", confirmation); // check content of confirmation, optional
// now continue with more selenium commands

Selenium Webdriver - How do I skip the wait for page load after a click and continue

I have an rspec test using webdriver that clicks on a button... after clicking the button, the page never fully loads (which is expected and correct behaviour). After clicking the button, I want to wait 2 seconds and then navigate to a different URL... despite the fact that the page has not loaded. I don't want to throw an error because the page hasn't loaded, I want to just ignore that, and continue on as if everything is good. The page should never load, that is the expected and correct behaviour.
How can I avoid waiting until the timeout, and secondly, how can I have that not throw an error which casuses the test to fail.
Thank you!
WebDriver has a blocking API and it will always wait for page to be loaded. What you can do instead, is to press the button via JavaScript, i.e. trigger its onclick event. I am not familiar with Ruby, but in Java it would be:
WebDriver driver = ....; // Init WebDriver
WebElement button = ....; // Find your element for clicking
String script = "if (document.createEventObject){"+
"return arguments[0].fireEvent('onclick');"+
"}else{"+
"var evt = arguments[0].ownerDocument.createEvent('MouseEvents');"+
"evt.initMouseEvent('click',true,true,"+
"element.ownerDocument.defaultView,1,0,0,0,0,false,"+
"false,false,false,1,null);"+
"return !element.dispatchEvent(evt);}" ;
((JavascriptExecutor)driver).executeScript(script, button);
After this you can wait for 2 seconds and continue
I had this similar problem, I tried this solution which #Sergii mentioned but was getting below error:
org.openqa.selenium.JavascriptException: javascript error: element is not defined (Session info: chrome=84.0.4147.89)
As a workaround had to initialize element within java script code.
String script = "var element = document.querySelector('button[type=submit]');" +
"if (document.createEventObject){"+
"return element.fireEvent('onclick');"+
"}else{"+
"var evt = element.ownerDocument.createEvent('MouseEvents');"+
"evt.initMouseEvent('click',true,true,"+
"element.ownerDocument.defaultView,1,0,0,0,0,false,"+
"false,false,false,1,null);"+
"return !element.dispatchEvent(evt);}" ;
Thank you #Sergii for your answer, I was not able to add this as a comment due to limited characters, so added it as a separate answer.
why don't you try a simple trick of using "waiting()" after waitForPageToLoad() which makes it to neglect the previous command in Selenium and never fails that step
What if you used RSpec's expect method:
expect {
Thread.new() {
sleep(2)
raise RuntimeError
}
theButton.click()
}.to raise_error
Send the 'Enter' key to the link or button in question instead of a click, webdriver won't wait for the page to load and will return instantly (this is in C#, just translate to Ruby):
element.SendKeys(Key,Return);

Resources