Calling Coded UI Tests from Java using jni4net

580 views
Skip to first unread message

Tony Tonev

unread,
Jul 25, 2011, 12:17:32 PM7/25/11
to jni4net
Hi, I'm using this snapshot you posted in a different discussion post:
jni4net-0.8.5.0-snapshot20110711-bin and passing in a .NET 4.0 Coded
UI Test DLL into proxygen, and I get this:

e:\Dev\Java\jni4net\jni4net-0.8.5.0-snapshot20110711-bin\bin>proxygen
E:\Dev\Java\jni4net\codedUI-te
st\TestProject2\bin\Release\TestProject2.dll -wd E:\Dev\Java\jni4net
\codedUI-test\working
jni4net.proxygen - Copyright (C) 2009 Pavel Savara - licensed under
GPLv3
clr.version :v4.0.30319
clr.arch :64bit
java.home :C:\Program Files\Java\jdk1.6.0_21
java.version :1.6.0_21
sun.arch.data.model :64

Loaded E:\Dev\Java\jni4net\codedUI-test\TestProject2\bin\Release
\TestProject2.dll

System.Reflection.ReflectionTypeLoadException: Unable to load one or
more of the requested types. Re
trieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.Assembly.GetTypes()
at net.sf.jni4net.proxygen.model.Repository.RegisterAssemblies()
at net.sf.jni4net.proxygen.model.Repository.Register()
at net.sf.jni4net.proxygen.Program.Work(String[] args)
at net.sf.jni4net.proxygen.Program.Main(String[] args)

It looks like there are dependencies in the DLL that it can't find?
Maybe dependent Coded UI libraries. Do you know how I can find out
more about what the dependencies are, and how to resolve them?

I have been able to get a simple example .NET DLL to work in Java
through jni4net, so I know that works.

Tony Tonev

unread,
Jul 25, 2011, 3:23:05 PM7/25/11
to jni4net
I was able to get it working by adding dependencies in the proxygen
command using -dp. I found the dependencies under References in Visual
Studio (right click, properties, Path has the DLL location). The
command I used was:

proxygen E:\Dev\Java\jni4net\codedUI-test\TestProject2\bin\Release
\TestProject2.dll -wd E:\Dev\Java\jni4net\codedUI-test\working -dp "C:
\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
\PublicAssemblies
\Microsoft.VisualStudio.QualityTools.CodedUITestFramework.dll";"C:
\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
\PublicAssemblies
\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll";"C:
\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
\PublicAssemblies
\Microsoft.VisualStudio.TestTools.UITest.Common.dll";"C:\Program Files
(x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies
\Microsoft.VisualStudio.TestTools.UITest.Extension.dll";"C:\Program
Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies
\Microsoft.VisualStudio.TestTools.UITesting.dll";"C:\Program Files
(x86)\Reference Assemblies\Microsoft\Framework\.NETFramework
\v4.0\System.dll";"C:\Program Files (x86)\Reference Assemblies
\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll";"C:\Program
Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework
\v4.0\System.Data.dll";"C:\Program Files (x86)\Reference Assemblies
\Microsoft\Framework\.NETFramework\v4.0\System.Drawing.dll";"C:
\Program Files (x86)\Reference Assemblies\Microsoft\Framework
\.NETFramework\v4.0\System.Windows.Forms.dll";"C:\Program Files
(x86)\Reference Assemblies\Microsoft\Framework\.NETFramework
\v4.0\UIAutomationTypes.dll";"C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework\.NETFramework\v4.0\WindowsBase.dll"

I probably added more than was needed (just to be safe). When I ran
the build.cmd, it said some of them were duplicate, so I removed those
from the command in the build.cmd, and it worked.

Now to try calling it from Java.

On Jul 25, 11:17 am, Tony Tonev <tony.to...@perceptivesoftware.com>
wrote:

Tony Tonev

unread,
Jul 26, 2011, 12:57:11 PM7/26/11
to jni4net
When I tried calling the method from Java, I had to load dependent
libraries like this:

try
{
Bridge.init();
Bridge.LoadAndRegisterAssemblyFrom(new File("C:\\Program
Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\
\PublicAssemblies\
\Microsoft.VisualStudio.QualityTools.CodedUITestFramework.dll"));
Bridge.LoadAndRegisterAssemblyFrom(new File("C:\\Program
Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\
\PublicAssemblies\
\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll"));
Bridge.LoadAndRegisterAssemblyFrom(new File("C:\\Program
Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\
\PublicAssemblies\
\Microsoft.VisualStudio.TestTools.UITest.Common.dll"));
Bridge.LoadAndRegisterAssemblyFrom(new File("C:\\Program
Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\
\PublicAssemblies\
\Microsoft.VisualStudio.TestTools.UITest.Extension.dll"));
Bridge.LoadAndRegisterAssemblyFrom(new File("C:\\Program
Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\
\PublicAssemblies\\Microsoft.VisualStudio.TestTools.UITesting.dll"));
Bridge.LoadAndRegisterAssemblyFrom(new File("C:\\Program
Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\
\PrivateAssemblies\
\Microsoft.VisualStudio.TestTools.UITest.Playback.dll"));
Bridge.LoadAndRegisterAssemblyFrom(new File("C:\\Program
Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\
\PrivateAssemblies\
\Microsoft.VisualStudio.TestTools.UITest.Framework.dll"));
Bridge.LoadAndRegisterAssemblyFrom(new File(".\\lib\
\TestProject2.j4n.dll"));

CodedUITest1 codedUITest = new CodedUITest1();

System.out.println(codedUITest.hello());

codedUITest.CodedUITestMethod1();
}
catch (Exception e)
{
e.printStackTrace();
}

It does print out the hello() string, so I know it's able to call into
the Coded UI DLL. When it gets to "codedUITest.CodedUITestMethod1();"
it launches my application (which is the first step of my Coded UI
test), but then fails with:

Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToLaunchApplicationException:
The following error occurred when this process was started: Object
reference not set to an instance of an object. File:
%ProgramFiles(x86)%\ImageNow6\bin\imagenow.exe. --->
System.NullReferenceException: Object reference not set to an instance
of an object.
at
Microsoft.VisualStudio.TestTools.UITesting.UITestControl..ctor(IntPtr
windowHandle)
at
Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.set_Process(Process
value)
at
Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.Start(ProcessStartInfo
startInfo)
--- End of inner exception stack trace ---
at
Microsoft.VisualStudio.TestTools.UITesting.ApplicationUnderTest.Start(ProcessStartInfo
startInfo)
at TestProject2.UIMap.LoginImageNow()
at TestProject2.__CodedUITest1.CodedUITestMethod10(IntPtr __envp,
JniLocalHandle __obj)
at testproject2.CodedUITest1.CodedUITestMethod1(Native Method)
at tmp.TempTest.main(TempTest.java:34)

So, it launches the app and then says it failed to launch. I keep
getting "Object reference not set to an instance of an object." Any
idea why this could be? It works fine when run from Visual Studio or
from mstest.exe.

Thanks,
Tony

On Jul 25, 2:23 pm, Tony Tonev <tony.to...@perceptivesoftware.com>
wrote:

Pavel Šavara

unread,
Jul 26, 2011, 4:06:27 PM7/26/11
to jni...@googlegroups.com
Hi Tony,

it seems to me you are passing invalid handle. The code which fails is
below (dotPeek).

private UITestControl(IntPtr windowHandle)
: this()
{
if (windowHandle == IntPtr.Zero)
{
throw new ArgumentNullException("windowHandle");
}
else
{
EqtTrace.Verbose("AL : Constructing UITestControl from
windowHandle: {0}", new object[1]
{
(object) windowHandle
});
try
{
this.ScreenElement = ScreenElement.FindFromWindowHandle(windowHandle);
}
catch (SystemException ex)
{
Playback.MapAndThrowException(ex, false);
throw;
}
this.CacheQueryId();

Tony Tonev

unread,
Jul 26, 2011, 4:26:47 PM7/26/11
to jni...@googlegroups.com
Hey Pavel,

Thanks for your response. I think you're right, but I'm not sure what's causing it, since I'm not the one calling UITestControl and passing in a null handle. Coded UI does that, and it seems to do it correctly when run from Visual Studio, but from Java through jni4net, it fails. I'm not sure what is different. Any ideas?

Tony

--

Tony Tonev

Software Engineer - Test
Perceptive Software

tony....@perceptivesoftware.com
www.perceptivesoftware.com

+1 913 422 7525 corporate
+1 913 667 8334 direct
+1 913 422 3820 fax
+1 800 941 7460 toll-free

NOTICE: If received in error, please destroy the message and notify sender. Sender does not waive confidentiality or privilege, and use is prohibited.




Pavel Šavara

unread,
Jul 26, 2011, 5:11:24 PM7/26/11
to jni...@googlegroups.com
At the second look it seems it starts another process ?
Such process would not contain jni4net of JVM ?
I'm just guessing.

Tony Tonev

unread,
Jul 26, 2011, 5:25:05 PM7/26/11
to jni...@googlegroups.com
Yes, it is starting another process to run UI tests on, but that process shouldn't need a JVM since we're only interacting with it through mouse clicks and keystrokes (Coded UI does this).

Thanks again for your response.

Tony


--

Tony Tonev

Software Engineer - Test
Perceptive Software

tony....@perceptivesoftware.com
www.perceptivesoftware.com

+1 913 422 7525 corporate
+1 913 667 8334 direct
+1 913 422 3820 fax
+1 800 941 7460 toll-free

NOTICE: If received in error, please destroy the message and notify sender. Sender does not waive confidentiality or privilege, and use is prohibited.




Reply all
Reply to author
Forward
0 new messages