Cross-posting from Denis’ blog.
Today we have updated S# with another sample covering the use of Windows Automation API from within a common S# script.
Auto# (AutoSharp)
This is a demo project shows how easily your S# scripts can be enhanced with a set of functions that target Windows UI Automation API and the ways of forming a QA-friendly language on the top of S# runtime. Full source code for this sample is available within the latest S# runtime update here.
Note: Sample project targets Windows 7 Notepad and may not work properly on other versions of Windows because of control ids difference.
To find Windows Automation API for your version of Windows please refer to this article.
Auto# introduces 9 functions that provide Windows Automation support S# scripts:
The following workflow is executed in order to automate Notepad:
Here’s how the S# script may look like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
// Close existing instances of Notepad Kill("notepad"); // Launch a new Notepad instance and get main window window = Launch("notepad"); // Wait 1 second Wait(1000); // Get main editor region edit = FindByClassName(window, "Edit"); // focus main editor FocusEditor(edit); // Send sample text to the editor region SendKeys.SendWait("Automating Notepad using Windows UI Automation and S#"); Wait(3000); // Find [File] menu mnuFile = FindById(window, "Item 1"); // Expand [File] menu Expand(mnuFile); Wait(1000); // Invoke [Save As] menu item InvokeById(window, "Item 4"); Wait(1000); // Get [Save As] dialog saveAsDialog = FindByName(window, "Save As"); // Get access to [FileName] textbox saveAsName = FindById(saveAsDialog, "1001"); // Focus filename editor FocusEditor(saveAsName); // Write down file name SendKeys.SendWait("D:\\MyTextFile"); // Send [Enter] keypress SendKeys.SendWait("{ENTER}"); Wait(1000); // Check whether Overwrite Dialog appeared confirmSaveAs = FindByName(saveAsDialog, "Confirm Save As"); if (confirmSaveAs != null) { // Click [OK] button InvokeById(confirmSaveAs, "CommandButton_6"); Wait(1000); } // Expand [File] menu Expand(mnuFile); Wait(1000); // Click [Exit] item InvokeById(window, "Item 7"); |
Demo project also includes a very simply UI providing possibility to alter the script above and execute it.
I noticed that Script.NET supported compact framework. When can I expect a version of S# that supports it?
By ChadG December 14, 2009 - 5:29 am[...] full post on Orbifold Link to this post! Share and Enjoy: Tags: Automating, Automation, Notepad, [...]
By Windows Automation: Automating Windows 7 Notepad within S# Script | OOP - Object Oriented Programing May 6, 2010 - 6:36 pm