Waiting until Image no longer exists to continue test
-
- Posts: 14
- Joined: Thu Aug 12, 2010 10:37 pm
Waiting until Image no longer exists to continue test
I'm trying to test a Flash game where there is loading sessions between areas but the load times vary dependent on machine several other factors. There is a loading screen between areas, I'm wondering if there is some sort of command that i can put it that tells Ranorex to wait until the preloader images no longer exist then proceed with its test?
Re: Waiting until Image no longer exists to continue test
Do you have a link to the image object? If so you can do something like this...
Code: Select all
bool ImageVisible = ImageObject.Visible;
while (ImageVisible == true)
{
Thread.Sleep(500);
ImageVisible = ImageObject.Visible;
}
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
-
- Posts: 14
- Joined: Thu Aug 12, 2010 10:37 pm
Re: Waiting until Image no longer exists to continue test
I do have a url link for each loading image. Where would this go (I'm learning C# as time goes so please bear with me), would it replace the ImageObject.Visible?
Re: Waiting until Image no longer exists to continue test
I'm sorry, I meant an xPath link to the object. In other words have you created a variable that references your object? That is what ImageObject represents in my example code.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
-
- Posts: 14
- Joined: Thu Aug 12, 2010 10:37 pm
Re: Waiting until Image no longer exists to continue test
Oh ok. Now am i creating method solely for this or am i adding it as part of another method? Please do not that I will be creating at least 25 unique checks.
Re: Waiting until Image no longer exists to continue test
What I would do is create a new method cal WaitUntilExists or something similar that takes an object as a variable. You call that method with the object passed in and it will wait until that object exists.
So, create the method once and use it however many times you want.
Just to be clear, when done you will have created a framework method that can be used with any project you want.
So, create the method once and use it however many times you want.
Just to be clear, when done you will have created a framework method that can be used with any project you want.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
-
- Posts: 14
- Joined: Thu Aug 12, 2010 10:37 pm
Re: Waiting until Image no longer exists to continue test
I cannot pull an Xpath with Spy since the everything on the screen is being shown as one flat image, Spy isn't picking up every individual piece of art.
Is there any way that i can put the image into the repository and reference the image from there? So far when i substitute the image file name from the repository for ImageObject, I had Ranorex simplify the file path and then put that in place of the ImageObject Variable (assuming that was the correct step). But the method keeps coming back as invalid. Below is the method I'm trying to use.
Is there any way that i can put the image into the repository and reference the image from there? So far when i substitute the image file name from the repository for ImageObject, I had Ranorex simplify the file path and then put that in place of the ImageObject Variable (assuming that was the correct step). But the method keeps coming back as invalid. Below is the method I'm trying to use.
Code: Select all
public static void ValidateHud()
{
bool ImageVisible = .//img[@alt=.Visible;
while (ImageVisible == True)
{
Thread.Sleep(500);
ImageVisible = .//img[@alt=.Visible:
}
}
-
- Posts: 14
- Joined: Thu Aug 12, 2010 10:37 pm
Re: Waiting until Image no longer exists to continue test
It is also an option for me to put a check in that instead of waiting for the loading screen to turn off is to put a wait until exists, So that Ranorex is waiting until the HUD shows up, which is one of the last things to load for our flash applet.
Re: Waiting until Image no longer exists to continue test
Something like this may be what you are after?
Public Sub waitUntilImageNotExists(strRanorexPath as String, strBmpFilePath as String, intTimeout as Integer)
Dim containingItem as Ranorex.Unknown = strRanorexPath
Dim bmp As System.Drawing.Bitmap = Ranorex.Imaging.Load(strBmpFilePath)
Dim iterations as Integer = 0
While imaging.Contains(containingItem.Element, bmp)
delay.Seconds(1)
iterations += 1
If iterations > intTimeout - 1 Then
report.Failure("Image", strBmpFilePath & " has not dissapered within " & intTimeout.ToString)
Throw New Exception
End If
End While
Report.Info("Image", strBmpFilePath & " no longer exists within " & strRanorexPath)
End Sub
Public Sub waitUntilImageNotExists(strRanorexPath as String, strBmpFilePath as String, intTimeout as Integer)
Dim containingItem as Ranorex.Unknown = strRanorexPath
Dim bmp As System.Drawing.Bitmap = Ranorex.Imaging.Load(strBmpFilePath)
Dim iterations as Integer = 0
While imaging.Contains(containingItem.Element, bmp)
delay.Seconds(1)
iterations += 1
If iterations > intTimeout - 1 Then
report.Failure("Image", strBmpFilePath & " has not dissapered within " & intTimeout.ToString)
Throw New Exception
End If
End While
Report.Info("Image", strBmpFilePath & " no longer exists within " & strRanorexPath)
End Sub
-
- Posts: 14
- Joined: Thu Aug 12, 2010 10:37 pm
Re: Waiting until Image no longer exists to continue test
Thanks for all the help guys, I think I'll forgo this step until I finish all my test cases and add this back in as a nice to have, for now I'll just put a large delay time.
Re: Waiting until Image no longer exists to continue test
Sorry to resurrect an old thread, but I was surprised that no-one posted a solution for the OP. We have a couple of projects starting up that require similar items to this so what we use is something similar to the following:
Helper method:
Then invoking it when needed is:
To ensure that you test case is truly portable, make sure that your reference images are all added to the project and set "Copy to output directory" as Always/PreserveNewest.
That way, when you load the image, you can use a relative path, and know that the relative path will always be true in relation to the executable.
Helper method:
Code: Select all
private void WaitForImageNotExists(Bitmap img, TimeSpan waitTime)
{
var start = System.DateTime.Now;
do
{
if (!Imaging.Contains(MyRepository.Instance.MyAppWindow.Self, img))
return;
} while(System.DateTime.Now.Subtract(start).TotalMilliseconds < waitTime.TotalMilliseconds);
throw new Exception("Time out looking for image");
}
Code: Select all
Bitmap img = Imaging.Load(@"path\imageOfInterest.bmp");
Imaging.FindOptions.Default.Similarity = 0.95;
try
{
WaitForImageNotExists(img, TimeSpan.FromSeconds(10));
}
catch
{
// Do handling here. Abort or whatever.
}
That way, when you load the image, you can use a relative path, and know that the relative path will always be true in relation to the executable.