Skip to content

Commit 9cf9aa2

Browse files
committed
Update element attribute unit test to reflect the updated API that can retrieve arbitrary element attributes
1 parent f93ba7a commit 9cf9aa2

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

Tests/W3CWebDriver/ElementAttribute.cs

+35-7
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,46 @@ public void ErrorGetElementAttributeStaleElement()
6464
[TestMethod]
6565
public void GetValidElementAttribute()
6666
{
67-
// NOTE: HelpText is currently the only supported GetAttribute method. There are
68-
// no known examples of non-null HelpText, so this should be replaced with
69-
// a different attribute once more are supported.
70-
string helpText = alarmTabElement.GetAttribute("HelpText");
71-
Assert.AreEqual(helpText, null);
67+
// NOTE: The attributes below are only a subset of supported attributes.
68+
// Use inspect.exe to identify all available attributes of an element
69+
var element = alarmTabElement;
70+
71+
// Fixed value string attributes
72+
Assert.AreEqual(element.GetAttribute("Name"), "Alarm");
73+
Assert.AreEqual(element.GetAttribute("AutomationId"), "AlarmPivotItem");
74+
Assert.AreEqual(element.GetAttribute("FrameworkId"), "XAML");
75+
Assert.AreEqual(element.GetAttribute("ClassName"), "PivotItem");
76+
Assert.AreEqual(element.GetAttribute("LegacyName"), "Alarm"); // Shows as Legacy|Accessible.Name in inspect.exe
77+
78+
// Fixed value boolean attributes
79+
Assert.AreEqual(element.GetAttribute("IsEnabled"), "True");
80+
Assert.AreEqual(element.GetAttribute("IsKeyboardFocusable"), "True");
81+
Assert.AreEqual(element.GetAttribute("IsControlElement"), "True");
82+
83+
// Arbitrary value attributes
84+
Assert.IsTrue(System.Convert.ToInt32(element.GetAttribute("ProcessId")) > 0);
85+
Assert.IsFalse(string.IsNullOrEmpty(element.GetAttribute("RuntimeId")));
86+
87+
// Arbitrary value array attributes
88+
Assert.IsFalse(string.IsNullOrEmpty(element.GetAttribute("ClickablePoint")));
89+
var boundingRectangle = element.GetAttribute("BoundingRectangle");
90+
Assert.IsTrue(boundingRectangle.Contains("Top"));
91+
Assert.IsTrue(boundingRectangle.Contains("Left"));
92+
Assert.IsTrue(boundingRectangle.Contains("Width"));
93+
Assert.IsTrue(boundingRectangle.Contains("Height"));
94+
95+
// Pattern specific attribute that may be used along with element.Selected property etc.
96+
Assert.AreEqual(element.GetAttribute("SelectionItem.IsSelected"), element.Selected.ToString());
97+
Assert.AreEqual(element.GetAttribute("IsSelectionItemPatternAvailable"), "True");
98+
Assert.AreEqual(element.GetAttribute("IsSelectionPatternAvailable"), "False");
7299
}
73100

74101
[TestMethod]
75102
public void GetInvalidElementAttribute()
76103
{
77-
string helpText = alarmTabElement.GetAttribute("InvalidAttribute");
78-
Assert.AreEqual(helpText, null);
104+
// Getting the value of an invalid attribute should return null
105+
string invalidAttribute = alarmTabElement.GetAttribute("InvalidAttribute");
106+
Assert.AreEqual(invalidAttribute, null);
79107
}
80108
}
81109
}

0 commit comments

Comments
 (0)