|
| 1 | +//****************************************************************************** |
| 2 | +// |
| 3 | +// Copyright (c) 2017 Microsoft Corporation. All rights reserved. |
| 4 | +// |
| 5 | +// This code is licensed under the MIT License (MIT). |
| 6 | +// |
| 7 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 8 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 9 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 10 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 11 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 12 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 13 | +// THE SOFTWARE. |
| 14 | +// |
| 15 | +//****************************************************************************** |
| 16 | + |
| 17 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 18 | +using OpenQA.Selenium.Appium.Windows; |
| 19 | + |
| 20 | +namespace W3CWebDriver |
| 21 | +{ |
| 22 | + [TestClass] |
| 23 | + public class ElementClick : AlarmClockBase |
| 24 | + { |
| 25 | + [ClassInitialize] |
| 26 | + public static void ClassInitialize(TestContext context) |
| 27 | + { |
| 28 | + Setup(context); |
| 29 | + } |
| 30 | + |
| 31 | + [ClassCleanup] |
| 32 | + public static void ClassCleanup() |
| 33 | + { |
| 34 | + TearDown(); |
| 35 | + } |
| 36 | + |
| 37 | + [TestMethod] |
| 38 | + public void ErrorClickElementNoSuchWindow() |
| 39 | + { |
| 40 | + try |
| 41 | + { |
| 42 | + Utility.GetOrphanedElement().Click(); |
| 43 | + Assert.Fail("Exception should have been thrown"); |
| 44 | + } |
| 45 | + catch (System.InvalidOperationException exception) |
| 46 | + { |
| 47 | + Assert.AreEqual(ErrorStrings.NoSuchWindow, exception.Message); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + [TestMethod] |
| 52 | + public void ErrorClickElementStaleElement() |
| 53 | + { |
| 54 | + try |
| 55 | + { |
| 56 | + GetStaleElement().Click(); |
| 57 | + Assert.Fail("Exception should have been thrown"); |
| 58 | + } |
| 59 | + catch (System.InvalidOperationException exception) |
| 60 | + { |
| 61 | + Assert.AreEqual(ErrorStrings.StaleElementReference, exception.Message); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + [TestMethod] |
| 66 | + public void ClickElement() |
| 67 | + { |
| 68 | + // Open a new alarm page and try clicking on visible and non-visible element in the time picker |
| 69 | + session.FindElementByAccessibilityId("AddAlarmButton").Click(); |
| 70 | + |
| 71 | + // initially visible element |
| 72 | + WindowsElement hourSelector = session.FindElementByAccessibilityId("HourLoopingSelector"); |
| 73 | + hourSelector.FindElementByName("8").Click(); |
| 74 | + Assert.AreEqual("8", hourSelector.Text); |
| 75 | + |
| 76 | + // initially non-visible element that is implicitly scrolled into view once clicked |
| 77 | + WindowsElement minuteSelector = session.FindElementByAccessibilityId("MinuteLoopingSelector"); |
| 78 | + minuteSelector.FindElementByName("30").Click(); |
| 79 | + Assert.AreEqual("30", minuteSelector.Text); |
| 80 | + |
| 81 | + // Return to main page and click on pivot items to switch between tabs |
| 82 | + session.FindElementByAccessibilityId("CancelButton").Click(); |
| 83 | + |
| 84 | + WindowsElement worldPivot = session.FindElementByAccessibilityId("WorldClockPivotItem"); |
| 85 | + WindowsElement alarmPivot = session.FindElementByAccessibilityId("AlarmPivotItem"); |
| 86 | + |
| 87 | + worldPivot.Click(); |
| 88 | + Assert.IsTrue(worldPivot.Selected); |
| 89 | + Assert.IsFalse(alarmPivot.Selected); |
| 90 | + |
| 91 | + alarmPivot.Click(); |
| 92 | + Assert.IsFalse(worldPivot.Selected); |
| 93 | + Assert.IsTrue(alarmPivot.Selected); |
| 94 | + } |
| 95 | + } |
| 96 | +} |
0 commit comments