diff --git a/src/Appium.Net/Appium/AppiumElement.cs b/src/Appium.Net/Appium/AppiumElement.cs index 1a11590a..827e7d8f 100644 --- a/src/Appium.Net/Appium/AppiumElement.cs +++ b/src/Appium.Net/Appium/AppiumElement.cs @@ -155,7 +155,6 @@ public override string GetCssValue(string propertyName) => CacheValue( () => base.GetCssValue(propertyName) )?.ToString(); - //TODO: Add Integrations tests public string GetProperty(string propertyName) => CacheValue( "property/" + propertyName, () => base.GetDomProperty(propertyName) diff --git a/test/integration/Android/ElementTest.cs b/test/integration/Android/ElementTest.cs index 46ffd79f..f3bc0aeb 100644 --- a/test/integration/Android/ElementTest.cs +++ b/test/integration/Android/ElementTest.cs @@ -202,6 +202,18 @@ public void FindAppiumElementsListUsingNestedElement() Assert.That(myDerivedElements, Is.Not.Empty); } + [Test] + public void GetPropertyTest() + { + if (Env.IsCiEnvironment()) + { + Assert.Ignore("Skipping GetPropertyTest test in CI environment"); + } + var myElement = WaitForElement(_driver, MobileBy.Id("android:id/content")); + string className = myElement.GetProperty("className"); + Assert.That(className, Is.Not.Null); + } + [OneTimeTearDown] public void AfterAll() { diff --git a/test/integration/Element/AppiumElementCacheTest.cs b/test/integration/Element/AppiumElementCacheTest.cs index 5acda8ed..8ad0af01 100644 --- a/test/integration/Element/AppiumElementCacheTest.cs +++ b/test/integration/Element/AppiumElementCacheTest.cs @@ -18,6 +18,22 @@ public void SetUp() _element = new TestableAppiumElement(); } + [Test] + public void GetProperty_WithCacheEnabled_ReturnsCachedValue() + { + var propertyName = "className"; + var expectedValue = "android.widget.TextView"; + + _element.SetCacheValues(new Dictionary + { + { "property/" + propertyName, expectedValue } + }); + + var propertyValue = _element.GetProperty(propertyName); + + Assert.That(propertyValue, Is.EqualTo(expectedValue)); + } + [Test] public void SetCacheValues_WithValidDictionary_EnablesCache() { @@ -279,6 +295,38 @@ public void TagName_WithCacheDisabled_CallsServerEveryTime() Assert.That(_element.ServerCallCount, Is.EqualTo(3)); } + [Test] + public void GetProperty_WithCacheDisabled_CallsServer() + { + var propertyName = "className"; + + // Access multiple times without cache + _ = _element.GetProperty(propertyName); + _ = _element.GetProperty(propertyName); + + // Should have made 2 server calls + Assert.That(_element.ServerCallCount, Is.EqualTo(2)); + } + + [Test] + public void GetProperty_WithEmptyCache_CallsServerOnceAndCaches() + { + var propertyName = "className"; + + // Enable cache with empty dictionary + _element.SetCacheValues(new Dictionary()); + + // First access should call server and populate cache + _ = _element.GetProperty(propertyName); + Assert.That(_element.ServerCallCount, Is.EqualTo(1)); + Assert.That(_element.CacheValues.ContainsKey($"property/{propertyName}"), Is.True); + + // Subsequent accesses should use cache + _ = _element.GetProperty(propertyName); + _ = _element.GetProperty(propertyName); + Assert.That(_element.ServerCallCount, Is.EqualTo(1)); + } + [Test] public void TagName_WithEmptyCache_CallsServerOnceAndCaches() { diff --git a/test/integration/helpers/TestableAppiumElement.cs b/test/integration/helpers/TestableAppiumElement.cs index b5a40862..dc12c42a 100644 --- a/test/integration/helpers/TestableAppiumElement.cs +++ b/test/integration/helpers/TestableAppiumElement.cs @@ -100,6 +100,10 @@ public string GetAttribute(string attributeName) => CacheValue( "attribute/" + attributeName, () => SimulateServerCall("server-attribute-value"))?.ToString(); + public string GetProperty(string propertyName) => CacheValue( + "property/" + propertyName, + () => GetDomProperty(propertyName))?.ToString(); + #endregion #region IWebElement Implementation (not used for cache testing) @@ -120,7 +124,7 @@ public string GetAttribute(string attributeName) => CacheValue( public string GetDomAttribute(string attributeName) => throw new NotImplementedException("Not needed for cache testing"); - public string GetDomProperty(string propertyName) => throw new NotImplementedException("Not needed for cache testing"); + public string GetDomProperty(string propertyName) => SimulateServerCall("server-property-value")?.ToString(); public OpenQA.Selenium.ISearchContext GetShadowRoot() => throw new NotImplementedException("Not needed for cache testing");