/* * * * HowtoTest_tryEUAautoAnswer.js.txt -EUA automation Script * * Automating the PC EUA app, using Windows shell scripts and javascript. * Starts EUA and joins call 02920210042 * * looks out for other window titles and presses {ESC} to close them * * * Doug Rice, BT (C) 15/03/2016, 16/03/2016, 12/01/2019 * * https://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx * * Usage: * From NGTS.ORG.UK Download zipped version of EUA * unpack to desktop in a folder called NGT Lite. * copy this file into the directory and rename it to "HowtoTest_tryEUA.js" so it ends in .js * double click HowtoTest_tryEUA.js which will try to start the EUA * * Script walks around app using TAB key and alt-key commands. * It can test if the expected dialogue pops. Unfortunately that is about the limits of it. * * wscript HowtoTest_tryEUAautoAnswer.js rem =================================== rem rem start script with wscript rem rem wscript HowtoTest_tryEUAautoAnswer.js wscript /h:wscript /x /d HowtoTest_tryEUAautoAnswer.js rem =================================== * * Objective:- How do you make a test script? * Automate starting the EUA and Auto joining incoming calls * Automate the reconnect * * Automate walking around the EUA and see if you get to where you expect? * How do you know where you have got to? * We can see if we can focus and report the result. This reports true or False. * So we can get to the same place repeatedly. * * There is little else available. * * * WSH is limited. It can see titles * for each point what can you see , what can WSH see/report? * WSH can push keys but not move the mouse. C:\Users\doug>wscript /? C:\Users\doug>cscript /? Microsoft (R) Windows Script Host Version 5.812 Copyright (C) Microsoft Corporation. All rights reserved. Usage: CScript scriptname.extension [option...] [arguments...] Options: //B Batch mode: Suppresses script errors and prompts from displaying //D Enable Active Debugging //E:engine Use engine for executing script //H:CScript Changes the default script host to CScript.exe //H:WScript Changes the default script host to WScript.exe (default) //I Interactive mode (default, opposite of //B) //Job:xxxx Execute a WSF job //Logo Display logo (default) //Nologo Prevent logo display: No banner will be shown at execution time //S Save current command line options for this user //T:nn Time out in seconds: Maximum time a script is permitted to run //X Execute script in debugger //U Use Unicode for redirected I/O from the console C:\Users\doug> */ /* ********************************************************************************** * SEC 1.0 Test Functions ********************************************************************************** */ /* * test001_startEUA() * * Start EUA - pass if it satrts * */ function test001_startEUA(){ WshShell.Run("cmd "); WScript.Sleep(tPause); WshShell.SendKeys ("java -jar NGTS_EUA.jar{ENTER}"); WScript.Sleep(tPause*5); result = WshShell.AppActivate("NGT"); opStr += "test: Activate NGT Lite " + result +"~" WScript.Sleep(tPause); if ( !result ){ result = WshShell.AppActivate("NGT"); opStr += "test: Activate NGT Lite " + result +"~" } return result } /* ********************************************************************************** * SEC 2.0 MAIN ********************************************************************************** */ tPause = 1000 // ms WScript.Echo( "Starting Script...Dial ( 640909 ) 02920210042, then press OK" ); opStr = "Test Results~=============~" var incall = ( 1 == 0 ) /* var WshShellClip = WScript.CreateObject("WScript.Shell"); oExec = WshShell.Exec("clip") */ var WshShell = WScript.CreateObject("WScript.Shell"); //http://www.nilpo.com/2007/08/windows-xp/scripting-the-clipboard-contents-in-wsh/ var objIE = WScript.CreateObject("InternetExplorer.Application"); objIE.Navigate("about:blank"); WScript.Sleep(1000); // wait for selected number to go blue var opStr = ":\n" result = test001_startEUA(); /* * You need a Watch dog timer to end the WSH script * Set Watchdog and the timer counts down each time around the loop * When it gets to zero end the script * */ var watchDogTimer = 60; // minute var pressedJoinTimer = -1 ; finished = ( 1 == 0 ) nextKeys = "" finished = ( 1==0 ) while( ! finished ){ WScript.Sleep(1000); // wait for selected number to go blue // Keep the script active if ( WshShell.AppActivate("NGT Lite Disconnected") ) { WshShell.SendKeys ("%r"); // press ALT-r to reconnect watchDogTimer = 3; } // //If you press the CALL button in a call the Call Finished dialogue box pops up. // if ( WshShell.AppActivate("Call Finished") ) { WshShell.SendKeys ("{ENTER}"); // press ALT-r to reconnect watchDogTimer = 3; } // //Occassionally this happens // if ( WshShell.AppActivate("Bad") ) { WshShell.SendKeys ("{ENTER}"); // press ALT-r to reconnect watchDogTimer = 3; } // If pressed Join call try and type 1 to get to the help desk. if ( incall ){ WshShell.SendKeys ("The Quick brown fox jumps over the Lazy Dog 2"); //Type 2 to get text number incall = ( 1 == 0 ) WshShell.SendKeys ("^a^c"); // copy text watchDogTimer = 3; } if ( WshShell.AppActivate("cmd.exe") ) { //WScript.Sleep(2000); } if ( WshShell.AppActivate("Options") ) { WScript.Sleep( 2000 ); WshShell.SendKeys ("{ESC}"); } if ( WshShell.AppActivate("Phrases") ) { WScript.Sleep( 2000 ); WshShell.SendKeys ("{ESC}"); } if ( WshShell.AppActivate("Calls") ) { //WScript.Sleep(6000); // wait for selected number to go blue // Keep pressing alt J until it does WshShell.SendKeys ("%j"); WScript.Sleep(1000); // Else press escape to close box WshShell.SendKeys ("%j"); // it takes a long time to respond // its not possible to see the join button // sometimes the join button is not enabled if no call // you have to press alt-J WScript.Sleep(1000); // Else press escape to close box WshShell.SendKeys ("{ESC}"); // set a flag to say we are in the call. incall = (1==1); pressedJoinTimer = 15; // if there is a Join button then the Calls dialogue box goes. // if there is not a join button or it takes a long time to go active then the dialogue stays. // It is not possible to Use another watchdog to timeout watchDogTimer = 3; } // If I can see the EUA screen, kick the watchdog timer if ( WshShell.AppActivate( "NGT Lite 1." ) ) { watchDogTimer = 3; } else { //WScript.Echo( "EUA app window not found then press OK" ); //finished = ( 1==1 ); } /* * * Run the watch dog timers. * */ if ( pressedJoinTimer > 0 ){ pressedJoinTimer += -1; if ( pressedJoinTimer == 0 ){ WshShell.SendKeys ("Hello"); } } watchDogTimer += -1 if ( watchDogTimer < 0 ){ finished = ( 1==1 ); } } WScript.Sleep( tPause ); // could do with a timeout test // // // open and focus a text file using Notepad and type results // //appendResults( opStr ) WScript.Echo( "End of Script....press OK" );