Unit testing geofencing services in UWP - c#

I have an app that shows a notification when I arrive somewhere, and I would like to have unit testing for it. I searched around a bit, and couldn't find anything.
Can I do this?
Are there services out there for this?
If not, what is the best way to do this?

This is pretty easy, thanks to the awesome Windows Phone emulator and it’s tools.
Press the “Additional tools” button
Select the “Location” tab
Select the “Load” button(If you don't have file,please set a point on map and save it as Locations.xml file by clicking save a pointbutton)
Edit Locations.xml file with visual studio, setting latitude and longitude same as your application setting.
Create new points next to the previous one continually.
The press the “Play” button on the Location Tools
Now if you have done everything right, pretty soon you should see the first toast pop up, and they should appear in the notification center as well. Since the phone should move on walking speed (it’s a pedestrian area) you might need to wait for a while for them all to appear.

Related

Coded UI thinks control is in a different position

I haven't been able to find someone else who has this same issue and it is extremely frustrating. Basically, for whatever reason, Coded UI is seeing a control in a different area then where it actually is. Like this:
Bounding Rectangle for Label with "IDLE" in it is up and to the left of the control
As you can see in the picture for some reason the Bounding Rectangle is up and to the left of the selected Label with the word "IDLE" in it. This is the first time I have seen this issue and after doing like 50 googles searches I decided to come here.
First off I am using Coded UI with a Windows Forms Application (I don't know if that makes a difference), it seems to do the same thing with all Windows Forms Applications, it has worked fine for all my WPF applications.
Second, no matter how many times I record my click on a button in my application or something of the sort, running the recorded method will always click off the button (due to it thinking the button is positioned up and to the left of the control). Up and to the left seems to be the only consistent thing, how much up and to the left varies based off of where the application is on the screen.
If anyone has any ideas or something I can try please help, I have no idea what is going on. If you need anymore information feel free to ask.
Thanks
Edit for Code sample:
public class Controller : WinWindow
{
#region Constructors
public Controller()
{
SearchProperties[PropertyNames.Name] = "My Sample C#";
SearchProperties.Add(new PropertyExpression(PropertyNames.ClassName, "WindowsForms10.Window", PropertyExpressionOperator.Contains));
WindowTitles.Add("My Sample C#");
enableWindow = new EnableWindow(this);
}
#endregion
public WinEdit CommunicationSetup
{
get
{
if(communicationSetup == null)
{
communicationSetup = new WinEdit(this);
communicationSetup.SearchProperties[PropertyNames.ControlName] = "Communication";
communicationSetup.WindowTitles.Add("My Sample C#");
}
return communicationSetup;
}
}
private WinEdit communicationSetup;
}
Extra Edit:
To Click on the thing I've used this:
Mouse.Click(new Point(obj.BoundingRectangle.Location.X + 20, obj.BoundingRectangle.Location.Y + 10));
and This:
Mouse.Click(obj);
Both click up and to the left of the control, as expected since the BoundingRectangle show there as seen in the picture
Edit: To replace "right" with "left" because I'm clearly an idiot and don't know my directions lol
Edit: Here is some more pictures showing the DrawHighlight() for the button Enable on my application, sorry I have to take a ton of information out for company policy reasons which might make it a little difficult to see what everything is going on but I have to
I also moved the application around so you can see how much of a difference DrawHighlight() has when the application is moved
Application dragged further down and to the right
what is stored in the obj variable that you try to pass to Click() method?
The problem might occur because you have not enough unique properties, who may definitely describe the control. Try to add additional SearchProperties. The most valuable would be a Control ID or Automation ID. If you cannot obtain this property on the wanted control, ask your development team to add it.
Try also to debug the method. Investigate of is returned in BoundingRectangle property of the control. Try out DrawHighlight() method. It will mark the position of the control with a blue rectangle. Another option would be to use TryGetClickablePoint() method. Maybe your control's size is bigger than you can visually obtain. The last but not least: examine your control from UIMap Editor and its whole hierarchy. You might find that the control you are looking for was badly recorded.
If nothing helps, then provide some more information and results of your investigation.
Good luck with that one.
Alex
I figured a consistent way to solve my problem, thanks to #Loathing for his comments on my question. Here is how I solved it:
var ret=new Rectangle();
GetWindowRect(obj.WindowHandle, ref ret);
Mouse.Hover(new Point(ret.X, ret.Y));
I still am not sure why this works so if someone sees this and understands feel free to comment and explain, I'm a little fuzzy on what goes on with GetWindowRect.
I recently came across some interesting results when trying to debug cross browser tests between IE and chrome that similarly mimicked what you've reported. It turns out that CodedUI and IE seems to be sensitive to the display scaling. I was using a multi monitor setup with different resolutions and changing each's scaling, using mostly 125%. The control's top and left coordinates were always off in IE and I could never figure out why. After doing some math and dividing by 125%, sure enough the number matched the coordinates it was supposed to be reporting. If I tried to change the monitor scaling without restarting windows, the issue got worse and I would also miss clicks. I imagine your solution to GetWindowRect appears be DPI sensitive as well, and reporting the correct coordinates with scaling taken into account.
Link to microsoft page that loosely discusses this:
Understanding Screen Scaling Issues
I get this all the time and the only way I managed to resolve it is restarting windows (go figure yet another MS solutions with Restart of the entire OS). Anyhow, in my case, it could be working fine, but later I would RD into my desktop from a laptop and everything would go nuts with this issue. I had to restart when working directly with PC and restart again when working from RD session.
I have had this issue fairly frequently as well. In my case whenever my code tried to download a file, the browser would popup the little download bar at the bottom. From then on, all my location rectangles would be off by the height of that bar.
My guess is that it is a bug in Microsoft's CodedUI that is unable to reset itself when the window it is testing changes sizes in certain cases. I have found a lot of bugs in CodedUI, I really hope that some day they get it more stable.
The fix for my issues so far has been to close the Internet Explorer window I was using to run the tests and restart it. CodedUI can't even get this right though, so I go out and kill all iexplorer.exe processes then re-start the browser.

C# application to control another application

I have got a problem when I try to control another Windows application using my own C# application.
The requirement is like this. The "another application" is a business software which our company have bought. We want to develop an application to fill text boxes and simulate mouse clicking. All text input is from a certain XML file.
I have tried to approach such function with SendMessage and SendWait function call. Problem is in some cases or at some end user's laptop, the text filling is not correct. Meanwhile, the mouse clicking will be fail in some other cases.
My imagination of the reason cause is synchronisation problems with call SendMessage. But I have no idea how to fix it. Is there any suggestion or solutions?
Looking forward your reply.
SendMessage and SendWait will always have those sorts of issues (especially app-to-app), e.g. the user clicks someone on the screen at exactly the right/wrong time. Really the only way I know to reliably do this is by hooking onto the mouse/keyboard and take total control... its hard and painful.
Note: there are plenty of professional macro'ing software packages on the market (faking keyboard input, mouse movement, clicks etc). Some are very sophisticated with their own programming language and will possibly do what you want. Google "windows macroing software" and you will find heaps - I recommend you do you research, trial several packages til you find one you want and then purchase it.

How to delete delay on SendKeys.SendWait?

Hello I want to press a button with my app. So I use SendKeys class
SendKeys.SendWait("{RIGHT}");
Problem is that I need to wait 3-4 seconds after this line code for reaction from system. How can I speed it up or how can I delete this delay ?
// update 1
I've also tried
SendKeys.SendWait("{RIGHT}");
SendKeys.Flush();
BUt id didn't help
// update 2
I want my app that works in background to press a button programaticly in the actual active state of the user. So if he is in excel i want the right arrow to move the active cell, if he is in the game i want to turn right etc. SendWait does the thing I want but with some delay that I don't want.
Second important thing that this is not a virus or worm or anything like that. First of all as you can see I'm too stupid for that and secondly I'm playing with my KInect so this is some kind of interaction beetwen user and computer. Thats why it works in background and thats why I need to send it to the active app of the user
SendKeys is a nice little feature for Windows Form applications. Based on your tag it appears that you're using Windows Presentation Foundation, which will not support SendKeys.Send()
https://stackoverflow.com/a/1646568/340574
Take a look at the link above to use KeyEventArgs. I've read that you could also add a reference to System.Windows.Forms.dll through Visual Studio to use SendKeys, but I have not tried it myself.

Debug Secondary Tiles (attaching debugger)

How do you attach the debugger to the Windows Emulator (or Device) to debug runs from Secondary Tiles?
I'm created a secondary tile but it has some problems loading the data and I can quite figure out what is going wrong. How can i attach to the process so i can debug it?
Thanks for your help!
You can't. A click on a live-tile doesn't resume the previous instance, but creates a new one (or resets the navigation-stack, from a users perspective it's the same)
But considering that a Live Tile is nothing but a URI, I see no reason you need to click on the actual tile to test the functionality of such a URI. You could simply change the NavigationPage property of the DefaultTask in the WMAppManifest.xml, to be the URI your tile is meant to open with.
If you have a specialized functionality related to your tile, you should tell us, so we can give a more detailed answer.
This works for me...
Start app as normal
Tap Home
Tap second Live Tile
The debugger stays attached when the app closes (this allows testing of tombstoning etc) so it is still attached when you tap the second tile.

How to get a value of a RadioButton from a WinForm application that I don't have an API for?

I have a small calculation system that will be installed in multiple PCs. Those PCs have a program installed in them and this program is always open (but minimized).
I need to get the value of a 'RadioButton' in this program but I can't access it!
I've tried to get an API for this application but the company developed it refused to co-operate. I've got a crazy idea, you can refer to my question regarding this idea Click It and the last thing is to get the cache for the button but I think this is going to work with WebApplications only!
Any help would be Great! =) .. And btw I decided to build my application as web application but then I changed my mind to build it as a WinForms because of the screenshot. But if I got a better and a more clean solution I'd go back to WebApp
Screen grabbing is not a good option. You should be able to use FindWindow based methods to get hold of the radio button if the app uses windowed controls. If not then UI Automation may very well be able to get the value of the radio button. Whatever it's usually possible to read UI state out of another application with methods like this, and much easier than screen scraping.

Categories

Resources