No caching for repository items

Class library usage, coding and language questions.
stefanb
Posts: 18
Joined: Fri Feb 01, 2013 2:30 pm

No caching for repository items

Post by stefanb » Thu Apr 18, 2013 12:14 pm

Hi

I have a problem with the caching of attributes in the elements. I have the following method to wait for the "visible" attribute to become true.
public static bool EnsureVisible(Ranorex.Adapter element, int timeout = 30)
        {
            sw.Restart();
                while (sw.Elapsed.Seconds < timeout)
                {
                    if (element.Visible)
                    {
                        return true;
                    }
                    Delay.Seconds(1);
                }
            return false;
        }
However it seems like if the element has visible=false the first time the element is accessed, it will stay this way even though it becomes visible=true in the GUI. I´m using the repository and have also tried to set all folders in the path to "Use Cash"=false but this didn’t make any difference. Is there some way that I can clear the cache or refresh the attributes in the element?


I use a Ranorex .Net Runtime Version 4.0.30319.18034 trial.
I have Windows 7 Proffesional with ServicePack 1 and .Net 4.5
BR Stefan

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: No caching for repository items

Post by Support Team » Fri Apr 19, 2013 5:17 pm

Hello,

Your method should work to find out if an element is visible.
How do you create the Ranorex.Adapter that you pass to the method?

Could you please verify in Spy if this element is visible during test execution?
Could you please make it visible before you call this method and verify if you get true?

Thank you in advance.

Regards,
Markus (T)
.
Image

stefanb
Posts: 18
Joined: Fri Feb 01, 2013 2:30 pm

Re: No caching for repository items

Post by stefanb » Tue Apr 30, 2013 9:47 am

Hi!

Not sure about this but it has been working fine since I changed my code to make a new instance of the repo every time I call for a new element, i.e.
private static Repository repo
        {
            get
            {
                return Repository.Instance;
            }
        }

public static bool EnsureVisible(int timeout = 30)  
        {  
            sw.Restart();
                while (sw.Elapsed.Seconds < timeout)  
                {  
                    if (repo.foo.bar.Visible)  
                    {  
                        return true;
                    }  
                    Delay.Seconds(1);  
                }  
            return false;  
        }
So I guess it is not possible to just look at the attribute of an element because it is static.

BR Stefan

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: No caching for repository items

Post by Support Team » Thu May 02, 2013 3:38 pm

Hello,

Your second code snippet works since you access the repository item directly.

Could you please describe how did you call your method before?
Do you create a new element and try to access its attributes?
Please provide us details about your repository elements.

Could be please describe what do you mean with the following sentence?
So I guess it is not possible to just look at the attribute of an element because it is static.
Thank you in advance.

Regards,
Markus (T)
.
Image

stefanb
Posts: 18
Joined: Fri Feb 01, 2013 2:30 pm

Re: No caching for repository items

Post by stefanb » Tue May 07, 2013 12:56 pm

Hi!

This is the way I called the method before:
public static class Foo
{
	private static readonly Repository repo = Repository.Instance;
        private static readonly Stopwatch sw = new Stopwatch();

        public static Ranorex.Form Bar
        {
            get
            {
                try
                {
                    return reop.Bar
                }
                catch (ElementNotFoundException e)
                {
                    Report.Screenshot();
                    Report.Failure(e.Message);
                    throw;
                }
            }
        }

	public static void Press(Ranorex.Adapter element)
        {
            try
            {
                if (!Service.EnsureVisible(element))
                {
                    throw new ValidationFailedException(Service.stepName() + ": \r\nElement is not visible");
                }
                if (!Service.EnsureEnabled(element))
                {
                    throw new ValidationFailedException(Service.stepName() + ": \r\nElement is not enabeld");
                }
                element.Click();
            }
            catch (ValidationFailedException e)
            {
                Report.Screenshot();
                Report.Failure(e.Message);
                throw;
            }
        }

	public static bool EnsureVisible(Ranorex.Adapter element, int timeout = 30)  
        {  
            sw.Restart();  
                while (sw.Elapsed.Seconds < timeout)  
                {  
                    if (element.Visible)  
                    {  
                        return true;  
                    }  
                    Delay.Seconds(1);  
                }  
            return false;  
        } 

        [TestMethod]
        public static void TestCase()
        {
            Press(Bar);
	}
}
What I mean is that the element attributes stays the same as long as I don´t make a new instance of the repository.

BR Stefan

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: No caching for repository items

Post by Support Team » Wed May 08, 2013 1:53 pm

Hello,

Thank you for your code.

It seems there is a mistake in the expression:
return reop.Bar
Could you please replace it with the following code:
return repo.Bar;
In your example you try to pass 'repo.Bar' to your method.
Could it be that 'repo.foo.bar' is the correct element which should be passed to your method?

Please let me know if it works.
Thank you.

Regards,
Markus (T)
.
Image