Object null reference error on a button click in a windows client app

Asked by Sid

I am testing a windows application Login screen. My sikuli script enters usrid, password and click the log in button.

In my script i have App.Open() to open aut. In this case after click log in button i get a "Object reference not set to an instance of the object"

But if open the app manully (without app.open()) i dont see this issue and my test passes (My script log in successfully).

Can you please let me know, how to fix the object reference error while using app.open()

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

show the snippet how you use App.open().

which system?

Revision history for this message
Sid (scindiad) said :
#2

My code:

App.open("C:\Program Files (x86)\AUT\Client\AUT.exe")

imgUserId =("LWe_.png")
try:
    assert exists (imgUserId)
except AssertionError:
    print "Could not find the Userid field"

click(getLastMatch())
type("a",KEY_CTRL)
type("<email address hidden>")

imgPassword =("1340666502867.png")
try:
    assert exists (imgPassword)
except AssertionError:
    print "Could not find the password field"

click(getLastMatch())
type("a",KEY_CTRL)
type("mypassword")

imgSignin =("Sgnn.png")

try:
    assert exists (imgSignin)
except AssertionError:
    print "Could not find the Signin button"
click(getLastMatch())

This would give me object null ref error. But if i comment the first line (app.open()) and open my aut.exe and run the scripts i have no issue.

Revision history for this message
Sid (scindiad) said :
#3

I am using Windows 7

Revision history for this message
Sid (scindiad) said :
#4

and sikuli version is X-1.0rc3

Revision history for this message
RaiMan (raimund-hocke) said :
#5

might be a timing problem:

    assert exists (imgUserId)
waits 3 seconds for the imgUserId image to appear.

Since you catch the assert exception and let the script continue, getLastMatch() is None, which leads to the Java null pointer exception.
Your approach does not make much sense, since when the password field is not found, continuing the script is useless.

If you start the app forefront, the image is already visible.

This could be my code:

App.open("C:\Program Files (x86)\AUT\Client\AUT.exe")

imgUserId =("LWe_.png")
click(wait(imgUserId, 10)) # give max 10 seconds
type("a",KEY_CTRL)
type("<email address hidden>")

imgPassword =("1340666502867.png")
click(imgUserId) # no additional wait necessary, should be there
type("a",KEY_CTRL)
type("mypassword")

imgSignin =("Sgnn.png")
click(imgSignin) # no additional wait necessary, should be there

In any case, if one of the image searches fail, the script will abort with a FindFailed exception.

if you want your own message:
e.g.
if not exists(imgUserId, 10): print "imgUserId not found"; exit(1)
click(getLastMatch()

Revision history for this message
Sid (scindiad) said :
#6

Thanks RaiMan!

But my issue is not withe password field. Sikuli is able to find the userid and password field and its able to enter the values that i provide in my scripts into the respective fields.

My issue is after i click the signin button, then i see the object null reference in my aut.exe

Expected result:
Script log in without any issue and application should open

Actual Result:
Log in didnt happen and i am seeing a object null reference error. This doesnt happen when i open the aut.exe manually

I hope this clarifies my question

Revision history for this message
Sid (scindiad) said :
#7

Thanks RaiMan!

But my issue is not withe password field. Sikuli is able to find the userid and password field and its able to enter the values that i provide in my scripts into the respective fields.

My issue is after i click the signin button, then i see the object null reference in my aut.exe

Expected result:
Script log in without any issue and application should open

Actual Result:
Log in didnt happen and i am seeing a object null reference error. This doesnt happen when i open the aut.exe manually

I hope this clarifies my question

Revision history for this message
Best RaiMan (raimund-hocke) said :
#8

--- I hope this clarifies my question
not really.

I understand:
In all cases (manually opened and using App.open()) works in that the fields are found and filled.

--- My issue is after i click the signin button, then i see the object null reference in my aut.exe
So you are saying, that the click() on the sign in button also works in both cases.

If this is right, than this means, that the script totally works in both cases.

Supposing this is true: Does this mean, that the "object null reference" problem happens in your application aut.exe?

If this is true, then the environment for your app in case App.open() differs from that when invoking it manually.

App.open() internally uses WinAPI createprocess
(http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx)

with this call in C++:
int result = CreateProcess( NULL, appName, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);

So you can see nothing special is provided, only the given app name/file path.

So this might mean, that your app cannot be invoked this way.

you might try to use the Windows start command from inside the script instead of using App.open():

import os
os.popen("start aut.exe")

Revision history for this message
Sid (scindiad) said :
#9

Thanks RaiMan, that solved my question.