using LoginPI.Engine.ScriptBase; using System; public class slackDesktop : ScriptBase { void Execute() { /* -Disclaimer: This workload is provided as-is and might need further configuration and customization to work successfully in each unique environment. For further Professional Services-based customization please consult with the Login VSI Support and Services team. Please refer to the Help Center section "Application Customization" for further self-help information regarding workload crafting and implementation. -Run the workload against the "target" using Script Editor to ensure it will work before uploading it and testing with it -Go through the workload to understand what it's doing. Comment out any unneeded app tests (code blocks) or add on any needed functional testing -Workload version and changelist: --V1.0 | original -Leave Application running compatibility: true Notes: -Please read each of the commented-out portions of this script, to see what it does and if there are lines which should be commented out or changed (variables, for example) -Environment: Win 10 Pro x64 winver 1909 18363.720 | Slack for Windows version 4.4.0 | Login Enterprise ScriptingToolset version 4.0.11 -Google Chrome browser is optional to be installed -- if Slack needs to be logged into/authenticated via a web browser, then Chrome will be needed (or another web browser, but the script will need to be customized to support it) This script will: -Start Slack for Windows (desktop GUI) and ensure it's started -Look for the Sign In button, but move on if not found -If the sign in button is present it will process the defined sign in process, with the defined user credentials, into the defined workspace. -If Sign In button not present then the script will assume the workspace is already logged into, and just continue on with the defined workload actions thereafter -Interact with the logged in version of Slack desktop, verifying it has opened successfully to the landing page -Open the defined Slack channel name by clicking on it -Click on the new message field after the defined Slack channel has been opened -Send test messages, with the defined loop amount, into the Slack channel via the message field -Close out of Slack for Windows */ // Set variables int globalTimeout = 10; // This is how long, in seconds, metafunctions will wait before timing out int uiCatchupWait = 2; // This is how long to sleep the workload execution, in seconds, in between functions string slackURL = "http://yourslackurl.com"; // This is the Slack URL to type in in the Slack web GUI, to access the workspace int charactersPerMinuteType = 500; // This is for the typing functions -- other than the test messages being typed out -- how quickly to type in characters per minute int charactersPerMinuteTypeTestMessages = 3000; // This is for the typing functions -- how quickly to type test messages in characters per minute string slackChannelName = "Slack Channel Name"; // This is the name of the test Slack channel to open and send test messages within int messageSendLoopAmount = 3; // This is how many times to send the looped message in chat int waitTimeForSignInButtonVisible = 3; // This is how long to wait in seconds for the sign in button to be present in Slack. If it's present then Slack will be logged into. If not then the workload will assumed that Slack's been logged into already int waitTimeLongSlackDesktopUILoad = 3; // When launching Slack desktop, this is how long it will wait in seconds for the Slack desktop to load before interacting with it int waitBetweenMessagesSending = 2; // This is how long to wait in seconds in between each new message sending string localHostname = System.Environment.MachineName; string localUsername = Environment.UserDomainName + "\\" + Environment.UserName; string chromeInvocationConcatenation = @"c:\program files (x86)\google\chrome\application\chrome.exe --force-renderer-accessibility google.com"; // Replace this line with the URL to navigate to in the Chrome web browser in order to log into the Slack workspace, if need be // Making sure no preliminary processes running ShellExecute("taskkill /f /im sla*",waitForProcessEnd:true,timeout:globalTimeout); // This is optional to taskkill slack ShellExecute("taskkill /f /im chr*",waitForProcessEnd:true,timeout:globalTimeout); // This is optional to taskkill google chrome browser Wait(uiCatchupWait); // Starting Slack and ensuring it's started START(mainWindowTitle:"*Slack*",processName:"slack",timeout:globalTimeout); Wait(uiCatchupWait); var initialSlackWindowCheck = FindWindow(title:"*Slack*",processName:"slack",timeout:globalTimeout); // This will look for the sign in button, but move on it it doesn't find it. var signInButton = initialSlackWindowCheck.FindControl(className : "Button", title : "Sign In",timeout:waitTimeForSignInButtonVisible,continueOnError:true); if (signInButton != null) // If the sign in button exists, then do the following code { // If the sign in button is present it will process the sign in process into the defined workspace. //If it's not present then the script will assume the workspace is already logged into, and it will just continue on with the defined interactions/actions/steps ShellExecute(chromeInvocationConcatenation,waitForProcessEnd:false); var chromeWindow = FindWindow(title : "*Sign in | Slack*", processName : "chrome",timeout:globalTimeout); Wait(uiCatchupWait); // This will locate the sign in window var workspaceField = chromeWindow.FindControlWithXPath(xPath : "Pane/Pane[1]/Pane[1]/Document/Unknown/Unknown/Unknown/Unknown/Unknown[2]/Edit",timeout:globalTimeout); // This will find the workspace field chromeWindow.Focus(); Wait(uiCatchupWait); workspaceField.Click(); Wait(uiCatchupWait); // This will log into the defined Slack URL Type(slackURL,cpm:charactersPerMinuteType); Type("{enter}",cpm:charactersPerMinuteType); chromeWindow.FindControl(className : "TabItem", title : "Sign in to * | Slack",timeout:globalTimeout); // This makes sure the sign in button window is present Wait(uiCatchupWait); // The following will sign in with the defined credentials var signInWithYourCredentialsButton = chromeWindow.FindControlWithXPath(xPath : "Document:Chrome_RenderWidgetHostHWND/Unknown/Unknown/Unknown/Unknown/Hyperlink/Unknown/Text",timeout:globalTimeout); signInWithYourCredentialsButton.Click(); var openSlackWindowPopup = chromeWindow.FindControl(className : "TitleBar", title : "Open Slack?",timeout:globalTimeout); // This looks for the popup named Open Slack?, which has an okay button on it, and it will open slack externally (desktop Slack UI) Wait(waitTimeForSignInButtonVisible); openSlackWindowPopup.Focus(); Wait(uiCatchupWait); // This will finalize the logging into Slack via the Chrome web browser Type("{tab}{enter}"); FindWindow(title:"*Slack | *",processName:"slack",timeout:globalTimeout); chromeWindow.Close(); Wait(uiCatchupWait); } // The following will interact with the logged in version of Slack desktop, verifying it has opened successfully to thye landing page FindWindow(title:"*Slack | *",processName:"slack",timeout:globalTimeout); Wait(uiCatchupWait); var slackMainDesktopUI = FindWindow(title:"*Slack | *",processName:"slack",timeout:globalTimeout); // This will open the define Slack channel name by clicking on it var openChannelButton = slackMainDesktopUI.FindControl(className : "Hyperlink", title : slackChannelName,timeout:globalTimeout); Wait(uiCatchupWait); openChannelButton.Click(); // This will select the new message field after the defined Slack channel has been opened var newMessageBodyField = slackMainDesktopUI.FindControl(className : "Edit", title : "Message "+slackChannelName,timeout:globalTimeout); Wait(uiCatchupWait); // This will, in the defined amount, loop sending messages into the channel via the message field int startMessageLoopInt = 0; while(startMessageLoopInt <= messageSendLoopAmount) { newMessageBodyField.Click(); Wait(waitBetweenMessagesSending); Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; Type("I'm user " + localUsername + " on host " + localHostname + ". The UTC Unix time in seconds is " + unixTimestamp + ".{enter}",cpm:charactersPerMinuteTypeTestMessages); Log(startMessageLoopInt); startMessageLoopInt++; } // The following code block will close out of Slack Wait(uiCatchupWait); slackMainDesktopUI.Close(); ShellExecute("taskkill /f /im sla*",waitForProcessEnd:true,timeout:globalTimeout); // this is optional to ensure the Slack for Windows desktop app has been closed out of } }