Skip to content

Commit

Permalink
Merged PR 2192439: Update WebDriverAPI test for better coverage, comp…
Browse files Browse the repository at this point in the history
…atibility with older application, and higher success rate

Add W3C Actions API endpoint as a supported endpoint in the README.md
Add a test scenario for pen barrel button click operation using W3C Actions API
Create FindAppTitleBar in AlarmsClockBase WebDriverAPI tests to support older apps
Update Window WebDriverAPI tests to use Edge private windows
Refactor add alarm page dismissal and create a helper function
Strategically add delay to prevent false negatives
  • Loading branch information
timotiusmargo committed Aug 9, 2018
2 parents dd641e5 + 65529e9 commit 35a6592
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 35 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ Below are the capabilities that can be used to create Windows Application Driver
| POST | /session |
| GET | /sessions |
| DELETE | /session/:sessionId |
| POST | /session/:sessionId/actions (v1.1 RC) |
| POST | /session/:sessionId/appium/app/launch |
| POST | /session/:sessionId/appium/app/close |
| POST | /session/:sessionId/back |
Expand Down
35 changes: 32 additions & 3 deletions Tests/WebDriverAPI/ActionsPen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,36 @@ public static void ClassCleanup()
TearDown();
}

[TestMethod]
public void Pen_Click_BarrelButton()
{
// Create a new test alarm
string alarmName = "PenBarrelButtonTest";
DeletePreviouslyCreatedAlarmEntry(alarmName);
AddAlarmEntry(alarmName);
Thread.Sleep(TimeSpan.FromSeconds(3));

var alarmEntries = session.FindElementsByXPath($"//ListItem[starts-with(@Name, \"{alarmName}\")]");
Assert.IsNotNull(alarmEntries);
Assert.AreEqual(1, alarmEntries.Count);

// Open a the context menu on the alarm entry using long tap (press and hold) action and click delete
PointerInputDevice penDevice = new PointerInputDevice(PointerKind.Pen);
ActionSequence sequence = new ActionSequence(penDevice, 0);
sequence.AddAction(penDevice.CreatePointerMove(alarmEntries[0], 0, 0, TimeSpan.Zero));
sequence.AddAction(penDevice.CreatePointerDown(PointerButton.PenBarrel));
sequence.AddAction(penDevice.CreatePointerUp(PointerButton.PenBarrel));
session.PerformActions(new List<ActionSequence> { sequence });

Thread.Sleep(TimeSpan.FromSeconds(1));
session.FindElementByName("Delete").Click();
Thread.Sleep(TimeSpan.FromSeconds(1));

alarmEntries = session.FindElementsByXPath($"//ListItem[starts-with(@Name, \"{alarmName}\")]");
Assert.IsNotNull(alarmEntries);
Assert.AreEqual(0, alarmEntries.Count);
}

[TestMethod]
public void Pen_Click_OriginElement()
{
Expand Down Expand Up @@ -161,7 +191,7 @@ public void Pen_Click_OriginViewport()
[TestMethod]
public void Pen_DoubleClick()
{
WindowsElement appNameTitle = session.FindElementByAccessibilityId("AppName");
WindowsElement appNameTitle = FindAppTitleBar();
WindowsElement maximizeButton = session.FindElementByAccessibilityId("Maximize");

// Set focus on the application by switching window to itself
Expand Down Expand Up @@ -203,7 +233,7 @@ public void Pen_DoubleClick()
[TestMethod]
public void Pen_DragAndDrop()
{
WindowsElement appNameTitle = session.FindElementByAccessibilityId("AppName");
WindowsElement appNameTitle = FindAppTitleBar();
const int offset = 100;

// Save application window original position
Expand Down Expand Up @@ -287,7 +317,6 @@ public void Pen_LongClick()
Assert.AreEqual(0, alarmEntries.Count);
}


[TestMethod]
public void Pen_Scroll_Horizontal()
{
Expand Down
5 changes: 2 additions & 3 deletions Tests/WebDriverAPI/ActionsTouch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void Touch_Click_OriginViewport()
[TestMethod]
public void Touch_DoubleClick()
{
WindowsElement appNameTitle = session.FindElementByAccessibilityId("AppName");
WindowsElement appNameTitle = FindAppTitleBar();
WindowsElement maximizeButton = session.FindElementByAccessibilityId("Maximize");

// Set focus on the application by switching window to itself
Expand Down Expand Up @@ -203,7 +203,7 @@ public void Touch_DoubleClick()
[TestMethod]
public void Touch_DragAndDrop()
{
WindowsElement appNameTitle = session.FindElementByAccessibilityId("AppName");
WindowsElement appNameTitle = FindAppTitleBar();
const int offset = 100;

// Save application window original position
Expand Down Expand Up @@ -287,7 +287,6 @@ public void Touch_LongClick()
Assert.AreEqual(0, alarmEntries.Count);
}


[TestMethod]
public void Touch_Scroll_Horizontal()
{
Expand Down
47 changes: 31 additions & 16 deletions Tests/WebDriverAPI/AppSessionBase/AlarmClockBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,8 @@ public virtual void TestInit()
}
catch
{
session.Navigate().Back();
Thread.Sleep(TimeSpan.FromSeconds(1));
session.DismissAlarmDialogIfThere();

try
{
alarmTabElement = session.FindElementByAccessibilityId("AlarmPivotItem");
}
catch
{
session.FindElementByAccessibilityId("Back").Click(); // Press back button if navigating back somehow failed
session.DismissAlarmDialogIfThere();
alarmTabElement = session.FindElementByAccessibilityId("AlarmPivotItem");
}
DismissAddAlarmPage();
alarmTabElement = session.FindElementByAccessibilityId("AlarmPivotItem");
}

Assert.IsNotNull(alarmTabElement);
Expand Down Expand Up @@ -146,10 +134,37 @@ protected static WindowsElement GetStaleElement()
session.FindElementByAccessibilityId("AddAlarmButton").Click();
Thread.Sleep(TimeSpan.FromSeconds(0.5));
WindowsElement staleElement = session.FindElementByAccessibilityId("AlarmSaveButton");
session.Navigate().Back(); // Dismiss add alarm page
session.DismissAlarmDialogIfThere();
DismissAddAlarmPage();
Thread.Sleep(TimeSpan.FromSeconds(2));
return staleElement;
}

protected static void DismissAddAlarmPage()
{
try
{
session.FindElementByAccessibilityId("CancelButton").Click(); // Press cancel button to dismiss any non-main page
}
catch
{
session.FindElementByAccessibilityId("Back").Click(); // Press back button if cancel button above somehow failed
Thread.Sleep(TimeSpan.FromSeconds(1));
session.DismissAlarmDialogIfThere();
}
}

protected static WindowsElement FindAppTitleBar()
{
WindowsElement element;
try
{
element = session.FindElementByAccessibilityId("AppName");
}
catch (InvalidOperationException)
{
element = session.FindElementByAccessibilityId("TitleBar");
}
return element;
}
}
}
4 changes: 2 additions & 2 deletions Tests/WebDriverAPI/AppSessionBase/EdgeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ protected static RemoteWebElement GetStaleElement()

// Navigate to Edge about:flags page
session.FindElementByAccessibilityId("addressEditBox").SendKeys(Keys.Alt + 'd' + Keys.Alt + CommonTestSettings.EdgeAboutFlagsURL + Keys.Enter);
Thread.Sleep(TimeSpan.FromSeconds(2));
Thread.Sleep(TimeSpan.FromSeconds(3));
Assert.AreNotEqual(originalTitle, session.Title);

// Save a reference to Reset all flags button on the page and navigate back to home
staleElement = session.FindElementByAccessibilityId("ResetAllFlags");
Assert.IsNotNull(staleElement);
session.Navigate().Back();
Thread.Sleep(TimeSpan.FromSeconds(1));
Thread.Sleep(TimeSpan.FromSeconds(3));
Assert.AreEqual(originalTitle, session.Title);

return staleElement;
Expand Down
4 changes: 2 additions & 2 deletions Tests/WebDriverAPI/AppSessionBase/WebDriverApiExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ internal static WindowsElement FindCalculatorTitleByAccessibilityId(this Windows
WindowsElement element;
try
{
element = session.FindElementByAccessibilityId("AppNameTitle");
element = session.FindElementByAccessibilityId("AppName");
}
catch (InvalidOperationException)
{
element = session.FindElementByAccessibilityId("AppName");
element = session.FindElementByAccessibilityId("AppNameTitle");
}
return element;
}
Expand Down
3 changes: 1 addition & 2 deletions Tests/WebDriverAPI/ElementClick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public void ClickElement()
Assert.AreEqual("30", minuteSelector.Text);

// Return to main page and click on pivot items to switch between tabs
session.FindElementByAccessibilityId("CancelButton").Click();

DismissAddAlarmPage();
WindowsElement worldPivot = session.FindElementByAccessibilityId("WorldClockPivotItem");
WindowsElement alarmPivot = session.FindElementByAccessibilityId("AlarmPivotItem");

Expand Down
2 changes: 1 addition & 1 deletion Tests/WebDriverAPI/ElementSendKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void SendKeysToElementError_StaleElement()
{
try
{
session.FindElementByAccessibilityId("CancelButton").Click();
DismissAddAlarmPage();
Thread.Sleep(TimeSpan.FromSeconds(1));
alarmNameTextBox.SendKeys("keys");
Assert.Fail("Exception should have been thrown");
Expand Down
2 changes: 2 additions & 0 deletions Tests/WebDriverAPI/Forward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ public void NavigateForward_SystemApp()

// Navigate back to the original folder
session.Navigate().Back();
Thread.Sleep(TimeSpan.FromSeconds(1));
Assert.AreEqual(originalTitle, session.Title);

// Navigate forward to the target folder
session.Navigate().Forward();
Thread.Sleep(TimeSpan.FromSeconds(1));
Assert.AreEqual(newTitle, session.Title);
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/WebDriverAPI/TouchScroll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public void TouchScrollOnElement_Vertical()
Thread.Sleep(TimeSpan.FromSeconds(1));
Assert.IsTrue(minute00.Displayed);

// Navigate back to the original view
session.Navigate().Back();
// Dismiss add alarm page
DismissAddAlarmPage();
}

[TestMethod]
Expand Down
14 changes: 10 additions & 4 deletions Tests/WebDriverAPI/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ public void GetWindowHandles_ModernApp()
List<string> previouslyOpenedEdgeWindows = new List<string>(windowHandlesBefore);
previouslyOpenedEdgeWindows.Remove(session.CurrentWindowHandle);

// Open a new window
session.Keyboard.SendKeys(Keys.Control + "n" + Keys.Control);
// Set focus on itself
session.SwitchTo().Window(session.CurrentWindowHandle);

// Open a new window in private mode
session.Keyboard.SendKeys(Keys.Control + Keys.Shift + "p" + Keys.Shift + Keys.Control);
Thread.Sleep(TimeSpan.FromSeconds(3));
var windowHandlesAfter = session.WindowHandles;
Assert.IsNotNull(windowHandlesAfter);
Expand Down Expand Up @@ -161,8 +164,11 @@ public void SwitchWindows()
List<string> previouslyOpenedEdgeWindows = new List<string>(session.WindowHandles);
previouslyOpenedEdgeWindows.Remove(session.CurrentWindowHandle);

// Open a new window
session.Keyboard.SendKeys(Keys.Control + "n" + Keys.Control);
// Set focus on itself
session.SwitchTo().Window(session.CurrentWindowHandle);

// Open a new window in private mode
session.Keyboard.SendKeys(Keys.Control + Keys.Shift + "p" + Keys.Shift + Keys.Control);
Thread.Sleep(TimeSpan.FromSeconds(3));
var multipleWindowHandles = session.WindowHandles;
Assert.IsTrue(multipleWindowHandles.Count > 1);
Expand Down

0 comments on commit 35a6592

Please sign in to comment.