Closed shshaakk closed 4 years ago
Is there anything special that needs to be done if on win10 using .NET 4.7? I'm trying a simple POC and I'm hitting File not found error.
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
at TestStack.White.Application.Launch(ProcessStartInfo processStartInfo)
at TestStack.White.Application.AttachOrLaunch(ProcessStartInfo processStartInfo)
at ConsoleApp1.Program.Main(String[] args) in C:\Users\vincent-j\Documents\poc\poc2\ConsoleApp1\Program.cs:line 21
The code is what I'm trying to do, following what I've seen online...
using TestStack.White;
using TestStack.White.Factory;
using TestStack.White.UIItems.Finders;
using TestStack.White.InputDevices;
namespace ConsoleApp1
{
class Program
{
private const string ExeSourceFile = @"C:\Windows\System32\calc.exe";
//Global Variable to for Application launch
private static TestStack.White.Application _application;
//Global variable to get the Main window of calculator from application.
private static TestStack.White.UIItems.WindowItems.Window _mainWindow;
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(ExeSourceFile);
TestStack.White.Application _application = TestStack.White.Application.AttachOrLaunch(psi);
}
}
}
Hi megaspaz,
Try Below code I think it will help you:
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using TestStack.White; using TestStack.White.Factory; using TestStack.White.UIItems; using TestStack.White.UIItems.Finders; using TestStack.White.UIItems.WindowItems; using TestStack.White.UIItems.WindowStripControls; using TestStack.White.InputDevices; using System.ServiceProcess; using System.Windows.Automation; using System.Windows; using TestStack.White.Utility; using System.Windows.Forms; using System.Text.RegularExpressions; using System.Configuration; using TestStack.White.Configuration; using SharpCompress.Common; using TestStack.White.WindowsAPI;
public static void sample() { string ExeSourceFile = @"C:\Windows\System32\calc.exe"; //Global Variable to for Application launch TestStack.White.Application _application; //Global variable to get the Main window of calculator from application. TestStack.White.UIItems.WindowItems.Window _mainWindow;
Console.WriteLine("Hello World!");
_application = TestStack.White.Application.Launch(ExeSourceFile);
}
TestStack.White Automation Regarding
Launch new application: TestStack.White.Application application = TestStack.White.Application.Launch(tallyApplicationPath);
Launch new application with its working directory: (using System.Diagnostics;) ProcessStartInfo p = new ProcessStartInfo(applicationPath); p.WorkingDirectory = applicationWorkingDirectoryPath; TestStack.White.Application application = TestStack.White.Application.Launch(p);
Connect with already launch application: TestStack.White.Application applicationOfvideoWindow = TestStack.White.Application.Attach("TallyVideoPlayer");
Set timeout: TestStack.White.Configuration.CoreAppXmlConfiguration.Instance.FindWindowTimeout = 10000; TestStack.White.Configuration.CoreAppXmlConfiguration.Instance.BusyTimeout = 300000000; // 5 Hours
Find window with name: (using System.Linq;) var getvideoWindow = applicationOfvideoWindow.GetWindows().Where(t => t.Title == GeneralDeclarations.TallyVideoWindowTitle).FirstOrDefault(); do { getvideoWindow = applicationOfvideoWindow.GetWindows().Where(t => t.Title == GeneralDeclarations.TallyVideoWindowTitle).FirstOrDefault(); } while (getvideoWindow == null); Window videoWindow = getvideoWindow;
Close window: videoWindow.Close();
Find all UIItems of a window: Window windowTransfer = getWindowTransfer; IUIItem[] windowTransferWindowAllUItems = windowTransfer.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.All);
Find,set and click a UIItem of a window:
IUIItem btnNo = null; btnNo = windowTransferWindowAllUItems.Where(t => t.Id == "No").FirstOrDefault(); btnNo.Click();
Find,set and click a comboBox of a window:
mainWindow = application.GetWindows().Where(t => t.Title == GeneralDeclarations.TallyMainWindowTitle).FirstOrDefault(); TestStack.White.UIItems.ListBoxItems.ComboBox SelcallcmbBox = mainWindow.Get(SearchCriteria.ByAutomationId("23945"));
SelcallcmbBox.Focus();
var selectAllcmbItem = SelcallcmbBox.Items.Where(t => t.Name == "All Tax Returns").FirstOrDefault();
selectAllcmbItem.Select();
selectAllcmbItem.Click();
Find,set and click a MenuBar’s menu item of a window:
MenuBar menuBar = mainWindow.MenuBar; Thread.Sleep(1000);
Set Keyboard for particular window and Press Special Key one time:
TestStack.White.InputDevices.AttachedKeyboard mainKeyboard = mainWindow.Keyboard; mainKeyboard.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.TAB);
Set Keyboard for particular window and Press Ctrl + P one time:
mainKeyboard.HoldKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.CONTROL); mainKeyboard.Enter("P"); mainKeyboard.LeaveKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.CONTROL);
Key Press for entire PC:
Desktop.Instance.Keyboard.PressSpecialKey(TestStack.White.WindowsAPI.KeyboardInput.SpecialKeys.RETURN);
Get Checkbox and Select and Unselect it:
Window printCenterWindow = mainWindow.ModalWindow(GeneralDeclarations.TallyPrintCenterWindowTitle); IUIItem[] printCenterWindowAllUIItems = printCenterWindow.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.All);
filingCopyCheckBox.Select();
Browse a folder using path given path:
Window browseForFolderWindow = getBrowseForFolderWindow; IUIItem[] browseForFolderWindowAllUIItems = browseForFolderWindow.GetMultiple(TestStack.White.UIItems.Finders.SearchCriteria.All); TestStack.White.UIItems.TreeItems.Tree selectPathTree = (TestStack.White.UIItems.TreeItems.Tree)browseForFolderWindowAllUIItems.Where(t => t.Id == "100").FirstOrDefault();
Click an element dynamically using another elements location:
WriteLog(GeneralDeclarations.LoggingPath, "rfreshBtn getting start." + Environment.NewLine, GeneralDeclarations.LoggingEnabled, true); IUIItem rfreshBtn = mainWindowAllUItems.Where(t => t.Id == "Item 41476").FirstOrDefault(); WriteLog(GeneralDeclarations.LoggingPath, "rfreshBtn getting done." + Environment.NewLine, GeneralDeclarations.LoggingEnabled, true);
Useful C# .net laibraries for automation:
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using TestStack.White; using TestStack.White.Factory; using TestStack.White.UIItems; using TestStack.White.UIItems.Finders; using TestStack.White.UIItems.WindowItems; using TestStack.White.UIItems.WindowStripControls; using TestStack.White.InputDevices; using System.ServiceProcess; using System.Windows.Automation; using System.Windows; using TestStack.White.Utility; using System.Windows.Forms; using System.Text.RegularExpressions; using System.Configuration; using TestStack.White.Configuration; using SharpCompress.Common; using TestStack.White.WindowsAPI;