-
Notifications
You must be signed in to change notification settings - Fork 184
Add integration and unit tests for GetProperty in AppiumElement #1038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| [Test] | ||||||||||||||||||||||||||||||||
| public void SetCacheValues_WithValidDictionary_EnablesCache() | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
|
|
@@ -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] | ||||||||||||||||||||||||||||||||
|
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
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Subsequent accesses should use cache | ||||||||||||||||||||||||||||||||
| _ = _element.GetProperty(propertyName); | ||||||||||||||||||||||||||||||||
| _ = _element.GetProperty(propertyName); | ||||||||||||||||||||||||||||||||
|
Comment on lines
+320
to
+326
|
||||||||||||||||||||||||||||||||
| _ = _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)); |
There was a problem hiding this comment.
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 assertingIs.Not.Empty(or a known expected class name) to make the test meaningfully validate the command result.