QTP recognising a JavaEdit object but not able to set a value when running the script - vbscript

I have written a simple script to log into a Java app where it fills in username and password, and then clicks on the "Connect" button".
Set UVC = JavaDialog("UVC")
wait(20)
If UVC.Exist Then
UVC.JavaEdit("JTextField").Set "admin"
wait(2)
UVC.JavaEdit("PSW").SetSecure "5256833195fsdqsdsqd447e4beefsdsdqd"
wait(5)
UVC.JavaButton("Connect").Click
Else
print "Console is not present"
End If
It's strange as QTP is identifying my password field properly. When running the following code I get a value back as expected:
MsgBox Main.JavaEdit("password").GetROProperty("attached_text")
I have also tried to set the password without encrypting it but it's also not working.
PS: the same script was working before and has since stopped working for an unknown reason!!!
Thanks in advance.

Replace
UVC.JavaEdit("PSW").SetSecure "5256833195fsdqsdsqd447e4beefsdsdqd"
with
UVC.JavaEdit("PSW").Click 1,1
UVC.JavaEdit("PSW").SetSecure "5256833195fsdqsdsqd447e4beefsdsdqd"
and it will work even with replay mode = "event". If you want to beautify this, you can use a click in the middle of the field, like in:
With UVC.JavaEdit("PSW")
.Click .GetROProperty ("width")\2, .GetROProperty ("height")\2
.SetSecure "5256833195fsdqsdsqd447e4beefsdsdqd"
End With
It seems that most Java password fields must first be focussed to be SetSecure-able.

Just to be sure.. check whether the field is enabled by testing .getroproperty("editable").
Use any of these methods to set text in Java Edit field.
You could use JavaEdit("PSW").Object.Settext method - this uses the JTextField in JavaSwing object properties
You could use setfocus method before entering the string in the field
Get the position of the test field
x = JavaEdit("PSW").Getroproperty("abs_x")
y = JavaEdit("PSW").Getroproperty("abs_y")
Set DRP = CreateObject("Mercury.DeviceReplay")
DRP.MouseClick x,y,"0"
DRP.SendString "the string"
You could also use JavaEdit's type object
Any of these methods should work for you. If not tough luck.. :)

Thanks for your answers but none of your suggestions worked, I have ended up using a basic turnaround :
UVC.JavaEdit("JTextField").Set"admin"
UVC.JavaEdit("PSW").Click 1,1
UVC.JavaEdit("PSW").SetSecure"52581237d889935df36ae78587773a641f40"
UVC.JavaButton("Connect").Click
wait (5)
While JavaDialog("Login Error").Exist
JavaDialog("Login Error").JavaButton("Ok").click
UVC.JavaEdit("PSW").RefreshObject
UVC.JavaEdit("PSW").SetSecure"52581237d889935df36ae78587773a641f40"
UVC.JavaButton("Connect").Click
Wend
I really don't get it how could the same function work sometimes and sometimes not!!

Related

Powershell and IBM/Lotus Domino

I have written 9 routines in the last few weeks in Powershell for Domino, they all appear to do what I need except 1!
This is the RegisterNewUser method, which does everything except the Email address. If I setup a user via Domino Administrator, I get everything including the email address ie internal address that is 'bob patz/smallhome'.
If I use my code this uses the registration process but all I end up with is the domain part of the internal email address '#smallhome'.
Does anyone know how to correct this? I don't think powershell uses the #formula language in any form, so I assume i somehow need to find the right column in a document or database and append the fullname in there somehow.
Is there anyone out there who can help in anyway?
regards
Mark
<#TOP TIP: THIS MUST RUN UNDER POWERSHELL (X86), ELSE IT WILL NOT WORK!!
This Powershell Function was created in March 2020 by (myself) Mark Baker as 'a' just to see if I can de-mystify
some of the Domino Database stucture, after running short bits of code and using Get-Member on some parts
of it and looking at online code snippets and reading some of the online info from IBM I have come up with
the function below to Create a New Lotus Notes User.
#
Original Code: 31/03/2020 by MBaker
A lot of work testing and diagnosing the different settings and values EVENTUALLY lead me to getting this working,
as at 08/04/2020 I just need to work out the settings for setting the correct email address per person.
#
This is how to use this function:
New-DominoUserRegistration "hazell" "C:\Program Files\IBM\Lotus\Notes\Data\ids\people\dhazell.id" "CN=Dom-01/O=Smallhome"
"Daniel" "" "swindon" "Work" "comment" "mail\dhazell" " " "password" 176
"dhazell"
Main use of this function is to connect to an IBM Domino Server and Create a New lotus notes user.
>
Function New-DominoUserRegistration {
[cmdletbinding()]
param (
[parameter(Position=0,Mandatory=$true,ValueFromPipeline=$True)][string]$lastname,
[parameter(Position=1,Mandatory=$true,ValueFromPipeline=$True)][string]$Useridfile,
[parameter(Position=2,Mandatory=$true,ValueFromPipeline=$True)][string]$mailserver,
[parameter(Position=3,Mandatory=$true,ValueFromPipeline=$True)][string]$firstname,
[parameter(Position=4,Mandatory=$false,ValueFromPipeline=$True)][string]$middle,
[parameter(Position=5,Mandatory=$true,ValueFromPipeline=$True)][string]$certpw,
[parameter(Position=6,Mandatory=$true,ValueFromPipeline=$True)][string]$location,
[parameter(Position=7,Mandatory=$true,ValueFromPipeline=$True)][string]$comment,
[parameter(Position=8,Mandatory=$true,ValueFromPipeline=$True)][string]$maildbpath,
[parameter(Position=9,Mandatory=$true,ValueFromPipeline=$True)][string]$fwddomain,
[parameter(Position=10,Mandatory=$true,ValueFromPipeline=$True)][string]$userpw,
[parameter(Position=11,Mandatory=$true,ValueFromPipeline=$True)][int]$usertype,
[parameter(Position=12,Mandatory=$true,ValueFromPipeline=$True)][string]$ShortName
)
cls
# Create Lotus Notes Object
$DomSession = New-Object -ComObject Lotus.NotesSession
# Initialize Lotus Notes Object
# "It'll use your open notes session and authentication Details"
$DomSession.Initialize()
# Use Method from Objects returned in variable $domsession one of which is CreateAdministrationProcess which
# takes a Server as input
$adminProcess = $Domsession.CreateRegistration()
$expiration = (Get-Date).adddays(1095)
$adminprocess.certifieridfile="C:\Program Files (x86)\IBM\Lotus\Notes\Data\ids\cert.id"
$adminprocess.Expiration =$expiration
#$adminprocess.RegistrationLog ="C:\program files (x86)\IBM\lotus\notes\data\reglog.nsf"
#[int]$adminProcess.MinPasswordLength=5
$adminprocess.RegistrationServer="Dom-01/smallhome"
$adminprocess.UpdateAddressBook=$true
$adminProcess.GroupList="Test4"
#$adminProcess.CreateMailDb=$true
#[int]$adminProcess.MailQuotaSizeLimit="100"
#[int]$adminProcess.MailQuotaWarningThreshold="90"
$adminProcess.PolicyName="/Registration_Settings"
$adminProcess.ShortName=$ShortName
[int]$adminProcess.MailOwnerAccess=2
$adminProcess.MailACLManager="LocalDomainAdmins"
$adminProcess.MailInternetAddress="$ShortName"+"#smallhome.local"
$adminProcess.MailTemplateName="Mail85.ntf"
$Notesid=$adminprocess.RegisterNewUser($lastname,$Useridfile,$mailserver,$firstname,$middle,$certpw,$location,$comment,$maildbpath,$fwddomain,$userpw,$usertype)
}
New-DominoUserRegistration "archer" "C:\Program Files (x86)\IBM\Lotus\Notes\Data\ids\people\barcher.id" "CN=Dom-01/O=Smallhome" "basil" "" "swindon" "Work" "comment" "mail\barcher" " " "password" 176 "barcher"
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/2Wamq.png
I now have an answer for this, this came from someone else on another board: the line [parameter(Position=9,Mandatory=$true,ValueFromPipeline=$True)][string]$fwddomain,
Needed to have [AllowEmptyString()] inserted before [string]$fwddomain, and the input field was " " and needed to be "". It appears the $fwddomain has an impact on the internal email address name ie: 'bob patz/smallhome'.
I have tested this and it shows up in the people view and also I can now send emails to other users and ones self!
Problem solved.
Regards
Mark

How can we get the value of textbox in QTP?

I am executing the automated test scripts in UFT 12.5 I am new to UFT. Not very familiar with codes.There is an edit box wherein i have to type the value "S05292". Example:
Browser(Browsername").Page("Pagename").WebEdit("ctl00$ConBody$txtPDNumber").Set "S05292"
The problem is my script fails at this step and does not type the value. Can somebody provide me with a solution which is easy to understand. I tried the below two methods
Method (1)
a=Browser().page().webedit(ctl00$ConBody$txtPDNumber).getroproperty("value")
if a=="S05292" then
msgbox ("displayed message is S05292")
else
msgbox ("msg is not S05292")
end if
Method (2)
x = Browser("Browsername").Page("Pagename").Webedit("ctl00$ConBody$txtPDNumber").GetROProperty("value")
msgbox x
The error message that displays is
Cannot identify the object "ctl00$ConBody$txtPDNumber" (of class WebEdit).
Verify that this object's properties match an object currently displayed in your application.
Use the Object Spy to get the properties of that text box at run time and then make sure they match up to the properties of that text box in your object repository that you defined. Perhaps that don't match up or you didn't uniquely identify that text box.
If you don't want to use an object repository then you have to pass it a property at run time to uniquely identify it. Some thing like:
Browser().page().webedit("developer name:=PDNumber").
Instead of a .set you can do a .type to set/type the value into the text box

Selenium with Ruby : Handling JS Prompt with 2 fields

I want Selenium to connect to my Staging site, which is hosted on WPEngine. Therefore each time I connect, it asks me for a user name and password, in a Javascript prompt.
I can easily send text to the first (user name) field in the prompt :
def connectToStaging()
alert = #browser.switch_to.alert
if /username and password/.match(alert.text)
alert.send_keys("username")
end
end
But then I don't know how to switch to the password field to do the same.
I've tried sending a tab character right after sending the string "username" :
alert.send_keys(:tab)
But it returns an error : NoMethodError: undefined method `split' for :tab:Symbol
Otherwise I don't know if there's a way to target the field using find_element ? Or is there a function to switch to the next field in whatever window or form the pointer is in at the moment ?
Thanks so much !
Thanks to #max-pleaner, a solution has been found.
Documentation here
I chose the first solution proposed : you can authenticate by putting your credentials directly in the url : https://username:password#www.yoursite.com
Thank you so much for your help !
Write this one
alert.send_keys("username",:tab,"password")

using WebEdit .Type property cannot be used

I have a piece of code in using QTP for a webpage
Browser("Sarit_2").Page("Sarit").WebEdit("frm_vendor_address1").Set dtVAdd1
You will observe, I used a 'Set' property. In reality, I wanted to use a 'Type' property because soon I will write script to check field limit and .Set property throws an error when I try to set a value larger than the field length. But Type property(I used it in win32 app), it types as much as the field length but at least doesn't throw an error I can't handle.
QTP in WebEdit or this particular WebEdit does not allow me to choose .Type. How come it allowed me in the case of SWFfield?
Any suggestions?
"Type" is a method used for Windows application, Delphi, Java, swf etc... But it is not used for Web application.
For web application we have to use "Set" method. Therefore above piece of code accepts 'Set' method. This also tells why you can not use 'Type' method with web based object.
If you want to count the field limit, you can object spy on the webedit-> save its max length value to any variable-> at run time store max length of that web edit field to variable2 using 'Browser("...").Page("..."). .... .GetROProperty("max length"). Now compare the two variable with if statement.
The WebEdit test object is helpfully trying to prevent you from setting an invalid value into the edit field.
You obviously don't want this help the question I'm not clear on is what you're trying to accomplish. If you want to set the first part of the string up to maxlength you can do something like this:
Public Function SetLimit(ByRef test_object, ByRef Value)
max = test_object.GetROProperty("max length")
If Len(Value) > max Then
test_object.Set Left(Value, max)
Else
test_object.Set Value
End If
End Function
RegisterUserFunc "WebEdit", "Set", "SetLimit"
You could use the WScript shell object to send keystrokes to the WebEdit after focussing it (by clicking into it). Like shown in http://h30499.www3.hp.com/t5/Quality-Center-Support-and-News/QTP-cannot-input-value-to-Webedit-field/td-p/4206627#.UkRMyIbIYyg:
Set WshShell = CreateObject("WScript.Shell")
Browser("Sarit_2").Page("Sarit").WebEdit("frm_vendor_address1").Click
WshShell.SendKeys(dtVAdd1)
Set WshShell = Nothing
Note that dtVAdd1's value must then conform to the format SendKeys expects -- as documented in (for example) http://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx.
Alternatively, you could use the undocumented Mercury.DeviceReplay interface to send the keystrokes. This is easily googleable.
As we know WebEdit does not supports Type method, we can use alternate approach like
1.SendKeys
Set objClick = CreateObject("WScript.Shell")
Browser("Sarit_2").Page("Sarit").WebEdit("frm_vendor_address1").Click
objClick.SendKeys "dtVAdd1"
Set objClick = Nothing
http://www.ufthelp.com/2013/02/sending-keyboard-strokes-in-uft-115.html
2.Using Native Object properties
Browser("Sarit_2").Page("Sarit").WebEdit("frm_vendor_address1").object.value ="dtVAdd1"
but this is almost similar to Set method
3.Using Advance Run settings in UFT
Tools->options->GUI Testing ->Web->Advance->Run Settings->Replay Type ->Mouse

PageObject with Ruby - set text in a text field only works in the main file

I'm automating a site that has a page with a list of options selected by a radio button. When selecting one of the radios, a text field and a select list are presented.
I created a file (test_contracting.rb) that is the one through which I execute the test (ruby test_contracting.rb) and some other classes to represent my page.
On my class ContractPage, I have the following element declaration:
checkbox(:option_sub_domain, :id => "option_sub_domain")
text_field(:domain, :id => "domain_text")
select_list(:tld, :id => "domain_tld")
I've created in the ContractPage a method that sets the configuration of the domain like this:
def configure_domain(config={})
check_option_sub_domain
domain = config[:domain]
tld = config[:tld]
end
When I call the method configure_domain from the test_contracting.rb, it selects the radio button, but it doesn't fill the field with the values. The params are getting into the method correctly. I've checked it using "puts". Even if I change the params to a general string like "bla" it doesnt work. The annoying point is that if on test_contracting.rb I call the exact same components, it works.
my_page_instance = ContractPage.new(browser)
my_page_instance.domain = "bla"
my_page_instance.tld = ".com"
What I found to work was to in the configure_domain method, implement the following:
domain_element.value = config[:domain]
tld_element.send_keys config[:locaweb_domain]
Then it worked.
The documentation for the PageObjects module that I'm using as reference can be found here: http://rubydoc.info/github/cheezy/page-object/master/PageObject/Accessors#select_list-instance_method
Do you guys have any explation on why the method auto generated by the pageobject to set the value of the object didnt work in this scope/context ?
By the way, a friend tried the same thing with Java and it failed as well.
In ruby all equals methods (methods that end with the = sign) need to have a receiver. Let me show you some code that will demonstrate why. Here is the code that sets a local variable to a value:
domain = "blah"
and here is the code that calls the domain= method:
domain = "blah"
In order for ruby to know that you are calling a method instead of setting a local variable you need to add a receiver. Simply change your method above to this and it will work:
def configure_domain(config={})
check_option_sub_domain
self.domain = config[:domain]
self.tld = config[:tld]
end
I'm pretty new to this world of Selenium and page objects but maybe one of my very recent discoveries might help you.
I found that that assignment methods for the select_list fields only worked for me once I started using "self" in front. This is what I have used to access it within my page object code. e.g., self.my_select_list="my select list value"
Another note - The send_keys workaround you mention is clever and might do the trick for a number of uses, but in my case the select list values are variable and may have several options starting with the same letter.
I hope something in here is useful to you.
UPDATE (Jan 3/12)
On diving further into the actual Ruby code for the page object I discovered that the select_list set is also using send_keys, so in actuality I still have the same limitation here as the one I noted using the send_keys workaround directly. sigh So much to learn, so little time!

Resources