Can Not find static text control when the test is executed on virtual machine - testing

I am using Microsoft Automation UI framework to develop my automation test cases. The problem I faced with is related to interaction with static text control. I am just trying to get the control's text. The test work perfect when I run the test on my local machine. The problem is when I run the test via Test Controler on the (no matter which) Test Agent. The error which appear is that the static control text can not be found.
Theis is the part of my code where I am trying to initialize the control I want to interact with:
private void Init(TreeScope treeScope, params Condition[] properties)
{
try
{
List<Condition> propertiesList = properties.ToList();
propertiesList.Add(Condition.TrueCondition);
bool controlFound = Wait.ForCondition(
() =>
{
try
{
TestControl = Parent.FindFirst(treeScope,
new System.Windows.Automation.AndCondition(propertiesList.ToArray()));
return !TestControl.Current.IsOffscreen;
}
catch
{
return false;
}
});
if (!controlFound)
{
throw new ElementNotAvailableException(DescriptiveName + "Control is NOT found");
}
this.GetItAsUITestControl().WaitForControlReady(Playback.PlaybackSettings.WaitForReadyTimeout);
if (TestControl.Current.IsKeyboardFocusable)
{
TestControl.SetFocus();
}
string controlFullName = this.TestControl.Current.ControlType.ProgrammaticName;
DescriptiveName = "< " + DescriptiveName + " " + controlFullName.Substring(controlFullName.LastIndexOf(".")) + " >";
}
catch (ElementNotAvailableException ex)
{
Report.Error(ex.Message);
}
catch (Exception ex)
{
Report.Error(ex.Message);
}
}
Any ideas?
I am using Microsoft System Center Virtual Machine Manager 2008 R2 for managing my virtual machines (I think all machines are vmware). But from my prespective the problem is not in the virtual machine because all of the tests are executed without any problems on the VM except the one which verify the Static Text Control content. I am 100% sure that the desctop of the VM where the tests are executed is active because I am able to look at it using VMWare Remote Console.
In terms of execution of the tests on the remote machine I am using Test Controlers and Test Agents which comes with Visual Studio.

Related

Getting contents of system clipboard on headless linux server for automated testing

I am trying to run some selenium cases on a headless linux system through docker in which the "user" clicks a button that copys text to the system clipboard. When I run this code, I get an error that says "No X11 DISPLAY variable was set, but this program performed an operation which requires it."
I am now running the case using xvfb to account for the lack of X11 Display variable, but the code still does not work. Now, I am getting a nullpointer when trying to access the contents of the system clipboard.
Here is the code that I am running to get the copied text.
String copied = null;
try {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transferable = clipboard.getContents(null);
DataFlavor[] availableFlavors = clipboard.getAvailableDataFlavors();
if ( transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor) ) {
copied = (String)transferable.getTransferData(DataFlavor.stringFlavor);
} else {
System.out.println("Could not find a suitable flavor.");
if ( transferable.getTransferDataFlavors().length == 0 ) {
System.out.println("no supported flavors");
}
for ( DataFlavor availableFlav : availableFlavors ) {
System.out.println("availableFlav = " + availableFlav);
}
for ( DataFlavor flavaflav : transferable.getTransferDataFlavors() ) {
System.out.println("transferDataFlavor = " + flavaflav);
}
}
// I am not sure what could cause the below exceptions to happen, but we should just fail the case if they occur.
} catch (IOException e) {
e.printStackTrace();
fail("IOException while fetching copied text.");
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
fail("UnsupportedFlavorException while fetching copied text.");
}
return copied;
Running this code with xvfb is resulting in the following output:
Could not find a suitable flavor.
no supported flavors
And then throws the NullPointerException.
Is there a way to fake a system clipboard that actually works in this headless linux server?
What might be causing the system clipboard running in xvfb to have nothing copied?

I need a conditional statement or Error handling that can exit the open browser

I am running tests with IBM RFT, when a test fails, the browser does not close. On a Windows machine this is a huge problem because I then have several instances of the browser still running in the background.
You can create a super helper class in which you override the onTerminate-method. This method is always called after the termination of the testMain-method. To ensure that there are no browser instances running, I personally like to kill the respecting processes altogether. Maybe there are more subtile ways... Example of a super helper class killing IE on termination (Java):
public abstract class SuperScript extends RationalTestScript
{
#Override
public void onTerminate()
{
try
{
Process p = Runtime.getRuntime().exec("taskkill /IM iexplore.exe /F");
if (p != null)
{
p.waitFor();
}
}
catch (Exception e)
{
}
super.onTerminate();
}
}

Message Dialog not displaying on Windows 8 tablet - Caliburn.Micro/C#

Has anyone heard of any issues with MessageDialog's not displaying on Windows 8 tablets? Or more specifically Samsung 700t? It uses a regular intel process and not ARM. I built the app on a laptop and the messagedialog shows when debugging from the laptop, shows on the tablet simulator but doesn't show on the actual tablet.
I'm using the Caliburn.Micro IResult interface to display the messagedialog in the view.
Heres snippits of code that I'm using:
public IEnumerable<IResult> NavExecute(String method)
{
Windows.UI.ViewManagement.ApplicationView.TryUnsnap();
var conn = NetworkInformation.GetInternetConnectionProfile();
if (conn.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess)
{
yield return new MessageDialogResult("Internet Connection Not Detected", "Connection Error");
netOn = false;
}
}
the above is in my view model base class, and heres the implementation of the IResult class itself:
public class MessageDialogResult : ResultBase
{
private readonly string _content;
private readonly string _title;
public MessageDialogResult(string content, string title)
{
_content = content;
_title = title;
}
public async override void Execute(ActionExecutionContext context)
{
var dialog = new MessageDialog(_content, _title);
await dialog.ShowAsync();
OnCompleted();
}
}
I doub't it's an issue with the code since I'm debugging in x86 mode on both devices (before anyone asks why I'm not debugging for all devices it's because I'm using SQLite which requires a seperate package for each arhitecture.)
I'm not sure if theres a setting somewhere in Windows 8 that disables in app popups, but I couldn't find one.
Any ideas?
Are you handling the callback of Coroutine.Execute?
The callback on Execute might be calling back with an exception thrown by the coroutine - this would silently fail if you weren't explicitly looking for it in the callback
Coroutine.Execute(YourEnumerator(), new ActionExecutionContext { Blah }, (o, e) => {
if(e.Error != null) // Something went wrong
});
Maybe the async await is throwing or something like that (can't think why!)
Edit:
Ah additionally stuff in your enumerator could also throw:
Windows.UI.ViewManagement.ApplicationView.TryUnsnap();
var conn = NetworkInformation.GetInternetConnectionProfile();
Either one could throw making the outer enumerator swallow an exception if not handled in the callback - or could be a nullref on conn?
The reason why GetInternetConnectionProfile() was returning a null ref was due to the fact that when on a laptop, if you disconnect from a wireless connection the laptop's internet connection profile defaults to ethernet, whereas the tablet (at least the Samsung 700T) doesn't have an ethernet port so it's connection profile doesn't exist if a wireless connection isn't established.
Thanks to Charleh for pointing me in the right direction.

Why JDK's JConsole seek virtual machines using both jvmstat and attach api?

I'm writing some JVM instance related application and looking at open source to see how it's solve some problems. The JConsole from JDK7 collects running VMs in two ways (look at source licensed by GPL2 in jdk/src/share/classes/sun/tools/jconsole/LocalVirtualMachine.java). The first is jvmstat way, code like this:
private static void getMonitoredVMs(Map<Integer, LocalVirtualMachine> map) {
MonitoredHost host;
Set vms;
try {
host = MonitoredHost.getMonitoredHost(new HostIdentifier((String)null));
vms = host.activeVms();
} catch (java.net.URISyntaxException sx) {
throw new InternalError(sx.getMessage());
} catch (MonitorException mx) {
throw new InternalError(mx.getMessage());
}
for (Object vmid: vms) {
if (vmid instanceof Integer) {
int pid = ((Integer) vmid).intValue();
String name = vmid.toString(); // default to pid if name not available
boolean attachable = false;
String address = null;
try {
MonitoredVm mvm = host.getMonitoredVm(new VmIdentifier(name));
// use the command line as the display name
name = MonitoredVmUtil.commandLine(mvm);
attachable = MonitoredVmUtil.isAttachable(mvm);
address = ConnectorAddressLink.importFrom(pid);
mvm.detach();
} catch (Exception x) {
// ignore
}
map.put((Integer) vmid,
new LocalVirtualMachine(pid, name, attachable, address));
}
}
}
Second is attach way, and looks like this:
private static void getAttachableVMs(Map<Integer, LocalVirtualMachine> map) {
List<VirtualMachineDescriptor> vms = VirtualMachine.list();
for (VirtualMachineDescriptor vmd : vms) {
try {
Integer vmid = Integer.valueOf(vmd.id());
if (!map.containsKey(vmid)) {
boolean attachable = false;
String address = null;
try {
VirtualMachine vm = VirtualMachine.attach(vmd);
attachable = true;
Properties agentProps = vm.getAgentProperties();
address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
vm.detach();
} catch (AttachNotSupportedException x) {
// not attachable
} catch (IOException x) {
// ignore
}
map.put(vmid, new LocalVirtualMachine(vmid.intValue(),
vmd.displayName(),
attachable,
address));
}
} catch (NumberFormatException e) {
// do not support vmid different than pid
}
}
}
My question: why it uses two different tools for retrieving virtual machines list? I know that through attach api you can list VMs running by this same JRE only, but jvmstat can give you list of all VMs running with any JRE versions. I have tested JRE/JDK 7 32 and 64-bit only because theys and newer are my target, sadly on windows only. Is not suffiecient to use jvmstat only? Is there any case when some VM is visible by attach api, but jvmstat can't see it?
Usually, for finding all jvm process, attach api is equal to jvmstat. But in some customized circumstances, it's diffrent. And the diffrent is com.sun.tools.attach.spi.AttachProvider.
e.g. in Windows platform, jvmstat finds java process by listing all files in the directory %TEMP%/hsperfdata_caoxudong(In linux, it is /tmp/hsperfdata_caoxudong). And attach api finds java processes by AttachProvider instance. jdk provides a default an AttachProvider implementation, which depends on your OS platform. In Windows Platform, the implementation is sun.tools.attach.WindowsAttachProvider. In its listVirtualMachines method, if isTempPathSecure method return false, it will iterate all processes, and find all processes, which loaded library "jvm.dll". You can install your own AttachProvider implementation to find java processes with your own ways, and the result may be diffrent with jvmstat.
The installation of AttachProvider is here.

How to start a windows service in Visual Studio 2008?

IN Visual Studio when I try to start a windows service project it tells me I cant because I have to use "NET Start" and so forth.
I remember in VS 2003 that when I pressed play it started the service and stop stopped it. Is there any way that when I press play or start for that windows service project I can have this same functionality.
What I currently do is install them using installutil and I put a pre-processor command with System.Diagnostics.Debug.Launch() when I have a compilation variable defined and when I use the service manager it shows me the window to select the debugger. Still this method is somewhat cumbersome.
For anyone else reading this, remember to try to debug ONE thread at a time.
I usually allow for a command line switch that I can pass to my service using the command line argument settings in the IDE. When this switch is on I can run my service as a regular app. The only issue here is that you need to remember that services usually run under accounts with restricted permissions, so debugging as an app in your user context may behave differently when accessing secured resources. Here is example code:
static void Main()
{
if (IsDebugMode())
{
MyService svc = new MyService();
svc.DebugStart();
bool bContinue = true;
MSG msg = new MSG();
// process the message loop so that any Windows messages related to
// COM or hidden windows get processed.
while (bContinue && GetMessage(out msg, IntPtr.Zero, 0, 0) > 0)
{
if (msg.message != WM_QUIT)
DispatchMessage(ref msg);
else
bContinue = false;
}
}
else
{
ServiceBase.Run(new MyService());
}
}
public void DebugStart()
{
this.OnStart(null);
}
static bool IsDebugMode()
{
return (System.Environment.CommandLine.IndexOf("debug") > -1);
}