Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Appium.Net/Appium/AppiumElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions test/integration/Android/ElementTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion only checks for non-null; GetProperty("className") could still return an empty string and this test would pass. Consider asserting Is.Not.Empty (or a known expected class name) to make the test meaningfully validate the command result.

Suggested change
Assert.That(className, Is.Not.Null);
Assert.That(className, Is.Not.Null.And.Not.Empty);

Copilot uses AI. Check for mistakes.
}

[OneTimeTearDown]
public void AfterAll()
{
Expand Down
48 changes: 48 additions & 0 deletions test/integration/Element/AppiumElementCacheTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
_element = new TestableAppiumElement();
}

[Test]
public void GetProperty_WithCacheEnabled_ReturnsCachedValue()
{
var propertyName = "className";
var expectedValue = "android.widget.TextView";

_element.SetCacheValues(new Dictionary<string, object>
{
{ "property/" + propertyName, expectedValue }
});

var propertyValue = _element.GetProperty(propertyName);

Assert.That(propertyValue, Is.EqualTo(expectedValue));
}
Comment on lines +21 to +35

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test verifies the returned value but doesn’t assert that the server was not called. Since the goal is caching behavior, consider also asserting ServerCallCount == 0 to ensure the value truly came from cache.

Copilot uses AI. Check for mistakes.

[Test]
public void SetCacheValues_WithValidDictionary_EnablesCache()
{
Expand Down Expand Up @@ -279,6 +295,38 @@
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]
Comment thread
Dor-bl marked this conversation as resolved.
public void GetProperty_WithEmptyCache_CallsServerOnceAndCaches()
{
var propertyName = "className";

// Enable cache with empty dictionary
_element.SetCacheValues(new Dictionary<string, object>());

// 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);

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / test (macos-latest)

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / android-tests (32, google_apis)

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / android-tests (32, google_apis)

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / android-tests (32, google_apis)

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / android-tests (32, google_apis)

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / ios-tests

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / ios-tests

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / ios-tests

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 322 in test/integration/Element/AppiumElementCacheTest.cs

View workflow job for this annotation

GitHub Actions / ios-tests

'TestableAppiumElement' does not contain a definition for 'CacheValues' and no accessible extension method 'CacheValues' accepting a first argument of type 'TestableAppiumElement' could be found (are you missing a using directive or an assembly reference?)

// Subsequent accesses should use cache
_ = _element.GetProperty(propertyName);
_ = _element.GetProperty(propertyName);
Comment on lines +320 to +326

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_element.CacheValues is referenced here, but TestableAppiumElement does not expose a CacheValues property (and IWebElementCached doesn’t define one either). This will fail to compile. Either add a read-only accessor on TestableAppiumElement (e.g., exposing the underlying cache dictionary) or remove this assertion and validate caching purely via ServerCallCount/returned values.

Suggested change
_ = _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);
var firstValue = _element.GetProperty(propertyName);
Assert.That(_element.ServerCallCount, Is.EqualTo(1));
// Subsequent accesses should use cache
var secondValue = _element.GetProperty(propertyName);
var thirdValue = _element.GetProperty(propertyName);
Assert.That(secondValue, Is.EqualTo(firstValue));
Assert.That(thirdValue, Is.EqualTo(firstValue));

Copilot uses AI. Check for mistakes.
Assert.That(_element.ServerCallCount, Is.EqualTo(1));
}

[Test]
public void TagName_WithEmptyCache_CallsServerOnceAndCaches()
{
Expand Down
6 changes: 5 additions & 1 deletion test/integration/helpers/TestableAppiumElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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");

Expand Down
Loading