|
| 1 | +//****************************************************************************** |
| 2 | +// |
| 3 | +// Copyright (c) 2019 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 System; |
| 18 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 19 | +using OpenQA.Selenium; |
| 20 | + |
| 21 | +namespace AbsoluteXPath |
| 22 | +{ |
| 23 | + [TestClass] |
| 24 | + public class Alarms |
| 25 | + { |
| 26 | + [TestMethod] |
| 27 | + public void TestMethod1() |
| 28 | + { |
| 29 | + DesktopSession desktopSession = new DesktopSession(); |
| 30 | + TimeSpan.FromSeconds(2); |
| 31 | + |
| 32 | + bool bSuccess = false; |
| 33 | + |
| 34 | + try |
| 35 | + { |
| 36 | + // LeftClick on Button "Type here to search" at (59,39) |
| 37 | + Console.WriteLine("LeftClick on Button \"Type here to search\" at (59,39)"); |
| 38 | + string xpath_LeftClickButtonTypehereto_59_39 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Pane[@ClassName=\"Shell_TrayWnd\"][@Name=\"Taskbar\"]/Pane[@ClassName=\"TrayDummySearchControl\"]/Button[@ClassName=\"Button\"][@Name=\"Type here to search\"]"; |
| 39 | + var winElem_LeftClickButtonTypehereto_59_39 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickButtonTypehereto_59_39); |
| 40 | + if (winElem_LeftClickButtonTypehereto_59_39 != null) |
| 41 | + { |
| 42 | + winElem_LeftClickButtonTypehereto_59_39.Click(); |
| 43 | + } |
| 44 | + else |
| 45 | + { |
| 46 | + Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickButtonTypehereto_59_39}"); |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + |
| 51 | + // KeyboardInput VirtualKeys=""alarms"Keys.Space + Keys.SpaceKeys.Shift + "7" + Keys.ShiftKeys.Space + Keys.Space"clock"" CapsLock=False NumLock=False ScrollLock=False |
| 52 | + Console.WriteLine("KeyboardInput VirtualKeys=\"\"alarms\"Keys.Space + Keys.SpaceKeys.Shift + \"7\" + Keys.ShiftKeys.Space + Keys.Space\"clock\"\" CapsLock=False NumLock=False ScrollLock=False"); |
| 53 | + System.Threading.Thread.Sleep(1000); |
| 54 | + winElem_LeftClickButtonTypehereto_59_39.SendKeys("alarms"); |
| 55 | + winElem_LeftClickButtonTypehereto_59_39.SendKeys(Keys.Space + Keys.Space); |
| 56 | + winElem_LeftClickButtonTypehereto_59_39.SendKeys(Keys.Shift + "7" + Keys.Shift); |
| 57 | + winElem_LeftClickButtonTypehereto_59_39.SendKeys(Keys.Space + Keys.Space); |
| 58 | + winElem_LeftClickButtonTypehereto_59_39.SendKeys("clock"); |
| 59 | + |
| 60 | + |
| 61 | + // LeftClick on ListItem "Alarms & Clock, Trusted Microsoft Store app, Press right to swit" at (126,13) |
| 62 | + Console.WriteLine("LeftClick on ListItem \"Alarms & Clock, Trusted Microsoft Store app, Press right to swit\" at (126,13)"); |
| 63 | + string xpath_LeftClickListItemAlarmsCloc_126_13 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Cortana\"]/Pane[@ClassName=\"WebView\"][@Name=\"Bing\"]/Pane[@Name=\"Bing\"]/List[@Name=\"Results\"][@AutomationId=\"suggestionsList\"]/ListItem[starts-with(@Name,\"Alarms & Clock, Trusted Microsoft Store app, Press right to swit\")][starts-with(@AutomationId,\"id_\")]"; |
| 64 | + var winElem_LeftClickListItemAlarmsCloc_126_13 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickListItemAlarmsCloc_126_13); |
| 65 | + if (winElem_LeftClickListItemAlarmsCloc_126_13 != null) |
| 66 | + { |
| 67 | + winElem_LeftClickListItemAlarmsCloc_126_13.Click(); |
| 68 | + } |
| 69 | + else |
| 70 | + { |
| 71 | + Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickListItemAlarmsCloc_126_13}"); |
| 72 | + return; |
| 73 | + } |
| 74 | + |
| 75 | + |
| 76 | + // LeftClick on ListItem "Alarm" at (56,17) |
| 77 | + Console.WriteLine("LeftClick on ListItem \"Alarm\" at (56,17)"); |
| 78 | + string xpath_LeftClickListItemAlarm_56_17 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Alarms & Clock\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Alarms & Clock\"]/List[@AutomationId=\"TopNavMenuItemsHost\"]/ListItem[@Name=\"Alarm\"][@AutomationId=\"AlarmButton\"]"; |
| 79 | + var winElem_LeftClickListItemAlarm_56_17 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickListItemAlarm_56_17); |
| 80 | + if (winElem_LeftClickListItemAlarm_56_17 != null) |
| 81 | + { |
| 82 | + winElem_LeftClickListItemAlarm_56_17.Click(); |
| 83 | + } |
| 84 | + else |
| 85 | + { |
| 86 | + Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickListItemAlarm_56_17}"); |
| 87 | + return; |
| 88 | + } |
| 89 | + |
| 90 | + |
| 91 | + // LeftClick on ListItem "Clock" at (54,10) |
| 92 | + Console.WriteLine("LeftClick on ListItem \"Clock\" at (54,10)"); |
| 93 | + string xpath_LeftClickListItemClock_54_10 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Alarms & Clock\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Alarms & Clock\"]/List[@AutomationId=\"TopNavMenuItemsHost\"]/ListItem[@Name=\"Clock\"][@AutomationId=\"ClockButton\"]"; |
| 94 | + var winElem_LeftClickListItemClock_54_10 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickListItemClock_54_10); |
| 95 | + if (winElem_LeftClickListItemClock_54_10 != null) |
| 96 | + { |
| 97 | + winElem_LeftClickListItemClock_54_10.Click(); |
| 98 | + } |
| 99 | + else |
| 100 | + { |
| 101 | + Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickListItemClock_54_10}"); |
| 102 | + return; |
| 103 | + } |
| 104 | + |
| 105 | + |
| 106 | + // LeftClick on ListItem "Timer" at (56,21) |
| 107 | + Console.WriteLine("LeftClick on ListItem \"Timer\" at (56,21)"); |
| 108 | + string xpath_LeftClickListItemTimer_56_21 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Alarms & Clock\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Alarms & Clock\"]/List[@AutomationId=\"TopNavMenuItemsHost\"]/ListItem[@Name=\"Timer\"][@AutomationId=\"TimerButton\"]"; |
| 109 | + var winElem_LeftClickListItemTimer_56_21 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickListItemTimer_56_21); |
| 110 | + if (winElem_LeftClickListItemTimer_56_21 != null) |
| 111 | + { |
| 112 | + winElem_LeftClickListItemTimer_56_21.Click(); |
| 113 | + } |
| 114 | + else |
| 115 | + { |
| 116 | + Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickListItemTimer_56_21}"); |
| 117 | + return; |
| 118 | + } |
| 119 | + |
| 120 | + |
| 121 | + // LeftClick on ListItem "Stopwatch" at (71,24) |
| 122 | + Console.WriteLine("LeftClick on ListItem \"Stopwatch\" at (71,24)"); |
| 123 | + string xpath_LeftClickListItemStopwatch_71_24 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Alarms & Clock\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Alarms & Clock\"]/List[@AutomationId=\"TopNavMenuItemsHost\"]/ListItem[@Name=\"Stopwatch\"][@AutomationId=\"StopwatchButton\"]"; |
| 124 | + var winElem_LeftClickListItemStopwatch_71_24 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickListItemStopwatch_71_24); |
| 125 | + if (winElem_LeftClickListItemStopwatch_71_24 != null) |
| 126 | + { |
| 127 | + winElem_LeftClickListItemStopwatch_71_24.Click(); |
| 128 | + } |
| 129 | + else |
| 130 | + { |
| 131 | + Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickListItemStopwatch_71_24}"); |
| 132 | + return; |
| 133 | + } |
| 134 | + |
| 135 | + |
| 136 | + // LeftClick on Button "Reset" at (16,23) |
| 137 | + Console.WriteLine("LeftClick on Button \"Reset\" at (16,23)"); |
| 138 | + string xpath_LeftClickButtonReset_16_23 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Alarms & Clock\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Alarms & Clock\"]/Button[@Name=\"Reset\"][@AutomationId=\"StopWatchResetButton\"]"; |
| 139 | + var winElem_LeftClickButtonReset_16_23 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickButtonReset_16_23); |
| 140 | + if (winElem_LeftClickButtonReset_16_23 != null) |
| 141 | + { |
| 142 | + winElem_LeftClickButtonReset_16_23.Click(); |
| 143 | + } |
| 144 | + else |
| 145 | + { |
| 146 | + Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickButtonReset_16_23}"); |
| 147 | + return; |
| 148 | + } |
| 149 | + |
| 150 | + |
| 151 | + // LeftClick on Button "Start" at (40,25) |
| 152 | + Console.WriteLine("LeftClick on Button \"Start\" at (40,25)"); |
| 153 | + string xpath_LeftClickButtonStart_40_25 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Alarms & Clock\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Alarms & Clock\"]/Button[@Name=\"Start\"][@AutomationId=\"StopwatchPlayPauseButton\"]"; |
| 154 | + var winElem_LeftClickButtonStart_40_25 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickButtonStart_40_25); |
| 155 | + if (winElem_LeftClickButtonStart_40_25 != null) |
| 156 | + { |
| 157 | + winElem_LeftClickButtonStart_40_25.Click(); |
| 158 | + } |
| 159 | + else |
| 160 | + { |
| 161 | + Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickButtonStart_40_25}"); |
| 162 | + return; |
| 163 | + } |
| 164 | + |
| 165 | + |
| 166 | + // LeftClick on Button "Pause" at (34,28) |
| 167 | + Console.WriteLine("LeftClick on Button \"Pause\" at (34,28)"); |
| 168 | + string xpath_LeftClickButtonPause_34_28 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Alarms & Clock\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Alarms & Clock\"]/Button[@Name=\"Pause\"][@AutomationId=\"StopwatchPlayPauseButton\"]"; |
| 169 | + var winElem_LeftClickButtonPause_34_28 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickButtonPause_34_28); |
| 170 | + if (winElem_LeftClickButtonPause_34_28 != null) |
| 171 | + { |
| 172 | + winElem_LeftClickButtonPause_34_28.Click(); |
| 173 | + } |
| 174 | + else |
| 175 | + { |
| 176 | + Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickButtonPause_34_28}"); |
| 177 | + return; |
| 178 | + } |
| 179 | + |
| 180 | + |
| 181 | + // LeftClick on Button "Reset" at (25,25) |
| 182 | + Console.WriteLine("LeftClick on Button \"Reset\" at (25,25)"); |
| 183 | + string xpath_LeftClickButtonReset_25_25 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Alarms & Clock\"]/Window[@ClassName=\"Windows.UI.Core.CoreWindow\"][@Name=\"Alarms & Clock\"]/Button[@Name=\"Reset\"][@AutomationId=\"StopWatchResetButton\"]"; |
| 184 | + var winElem_LeftClickButtonReset_25_25 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickButtonReset_25_25); |
| 185 | + if (winElem_LeftClickButtonReset_25_25 != null) |
| 186 | + { |
| 187 | + winElem_LeftClickButtonReset_25_25.Click(); |
| 188 | + } |
| 189 | + else |
| 190 | + { |
| 191 | + Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickButtonReset_25_25}"); |
| 192 | + return; |
| 193 | + } |
| 194 | + |
| 195 | + |
| 196 | + // LeftClick on Button "Close Alarms & Clock" at (19,22) |
| 197 | + Console.WriteLine("LeftClick on Button \"Close Alarms & Clock\" at (19,22)"); |
| 198 | + string xpath_LeftClickButtonCloseAlarm_19_22 = "/Pane[@ClassName=\"#32769\"][@Name=\"Desktop 1\"]/Window[@ClassName=\"ApplicationFrameWindow\"][@Name=\"Alarms & Clock\"]/Window[@Name=\"Alarms & Clock\"][@AutomationId=\"TitleBar\"]/Button[@Name=\"Close Alarms & Clock\"][@AutomationId=\"Close\"]"; |
| 199 | + var winElem_LeftClickButtonCloseAlarm_19_22 = desktopSession.FindElementByAbsoluteXPath(xpath_LeftClickButtonCloseAlarm_19_22); |
| 200 | + if (winElem_LeftClickButtonCloseAlarm_19_22 != null) |
| 201 | + { |
| 202 | + winElem_LeftClickButtonCloseAlarm_19_22.Click(); |
| 203 | + } |
| 204 | + else |
| 205 | + { |
| 206 | + Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickButtonCloseAlarm_19_22}"); |
| 207 | + return; |
| 208 | + } |
| 209 | + |
| 210 | + bSuccess = true; |
| 211 | + } |
| 212 | + finally |
| 213 | + { |
| 214 | + Assert.AreEqual(bSuccess, true); |
| 215 | + } |
| 216 | + } |
| 217 | + } |
| 218 | +} |
0 commit comments