Watin: Handling Security Alert Pop Up - watin

HI ,
Am automating a website, when tried to login its dispalying one security alert pop up.
Wanted to click "Yes" of that pop up,Can anyone give the solution for this.

There are two ways to handle this, add a dialog handler at the start of the test or add one explicitly when you need it. Here is how you add one at the start that runs is a seperate thread.
IE ie = new IE();
ie.AddDialogHandler( new SecurityDialoghandLer() .. or the appropriate dialog handler ...);
The rest of your test ...

I had a mix of security warnings and certificate warnings every time the server got new code. This works for me:
browser.AddDialogHandler(new DialogHandlerHelper());
browser.AddDialogHandler(new SecurityAlertDialogHandler());
Assert.IsTrue(browser.Link(Find.ByText("Login")).Exists);
browser.Link(Find.ByText("Login")).Click();
if (browser.Element("expertContentHeading").Exists)
{
browser.Element("expertContentHeading").Click();
browser.Button("exceptionDialogButton").Click();
int Handle = browser.hWnd.ToInt32();
object BT = true;
WshShell WSH = new WshShell();
WSH.SendKeys("{TAB}", ref BT);
WSH.SendKeys("{TAB}", ref BT);
WSH.SendKeys("{TAB}", ref BT);
WSH.SendKeys("{TAB}", ref BT);
WSH.SendKeys("{ENTER}", ref BT);
}
if (browser.Links.Exists("overridelink"))
{
browser.Link("overridelink").Click();
}

Related

Visual Studio extension - get reference to currently selected item in Git history

I managed to get a custom button added to the Git history context menu thanks to the help offered here.
I'm continuing work at the same extension and am again stuck. Once the button I've added to the context menu is clicked I need to get a reference to the commit that is selected when it is clicked. The idea is that I then need to grab the code changes associate with that commit.
I've gotten as far as getting a reference to the ActiveWindow which has a caption of "History - master". Which makes me believe I'm close. However, ActiveWindow.Selection is null. So I'm not sure where to go next to get the selected commit.
This is what I'm using to get the ActiveWindow property.
EnvDTE80.DTE2 dte = ServiceProvider.GetService(typeof(DTE)) as EnvDTE80.DTE2;
Anyone know how to grab a reference to the selected commit? Then use that to grab information about the commit including the changed files?
My question looks similar to this one, but for Git instead of TFS.
Thanks in advance for the help!
Took forever, but I finally managed to get at the selected commit. It involves reflection because a lot of the types used in the git extension are internal. There's got to be a better way to do this.
The IGitCommit that I'm able to retrieve doesn't have the changes for the commit populated. Hopefully getting the changes that are part of the commit isn't as challenging.
private IGitCommit GetSelectedCommit()
{
ThreadHelper.ThrowIfNotOnUIThread();
EnvDTE80.DTE2 dte = ServiceProvider.GetService(typeof(DTE)) as EnvDTE80.DTE2;
// GUID found via dte.ActiveWindow.ObjectKind
Guid gitHistoryWindowGuid = new Guid("116D2292-E37D-41CD-A077-EBACAC4C8CC4");
IVsUIShell vsUIShell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell));
int toolWindowReturn = vsUIShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fFrameOnly, ref gitHistoryWindowGuid, out IVsWindowFrame vsWindowFrame);
WindowFrame windowFrame = (WindowFrame)vsWindowFrame;
ToolWindowView toolWindowView = (ToolWindowView)windowFrame.FrameView;
// panel is of innaccessible type Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.ContentHostingPanel
// so use base System.Windows.Controls.Grid
Grid contentHostingPanel = (Grid)toolWindowView.Content;
// Type Microsoft.VisualStudio.Platform.WindowManagement.Controls.GenericPaneContentPresenter is internal
// so use base ContentPresenter
ContentPresenter genericPaneContentPresenter = contentHostingPanel.Children[1] as ContentPresenter;
// Microsoft.VisualStudio.TeamFoundation.ToolWindowBase.ToolWindowBaseProxy is innaccessible
// so use base ContentPresenter
ContentPresenter toolWindowBaseProxy = (ContentPresenter)genericPaneContentPresenter.Content;
// Is of type Microsoft.TeamFoundation.Git.Controls.History.HistoryView,
// but this class is defined as internal so using base UserControl.
UserControl historyView = (UserControl)toolWindowBaseProxy.Content;
// Is of type Microsoft.TeamFoundation.Git.Controls.History.HistoryViewModel,
// but this class is defined as internal so using base Microsoft.TeamFoundation.MVVM.ViewModelBase.
ViewModelBase historyViewModel = (ViewModelBase)historyView.DataContext;
// Use reflection to get at properties of internal type HistoryViewModel and ObservableCollection<GitHistoryItem>
object gitHistoryItem = ((IList)historyViewModel.GetType().GetProperty("SelectedItems").GetValue(historyViewModel, null))[0];
IGitCommit gitCommit = (IGitCommit)gitHistoryItem.GetType().GetProperty("Commit").GetValue(gitHistoryItem, null);
return gitCommit;
}

How to enable 'Microsoft.Windows.Common-Controls' for specificate control?

I have a old MFC application that I can't to enable 'Microsoft.Windows.Common-Controls' to all controls in this application because new behavior of some controls. But I need it for CEdit that support to EM_SETCUEBANNER.
I try to do that in OnInitDialog:
m_edt = (CEdit *)GetDlgItem(edit_id);
int i= SetWindowTheme(m_edt->m_hWnd, L"Explorer", NULL);
SetWindowTheme returns 0 but I still cannot use the EM_SETCUEBANNER message.
How can I enable Microsoft.Windows.Common-Controls only for CEdit?
You need to create an Activatation Context that uses a ComCtrl32 v6 manifest. Then you can activate the context before creating the CEdit, and deactivate the context afterwards.
See How can you use both versions 5 and 6 of the common controls within the same module? on Raymond Chen's blog on MSDN.
For example, I did a quick test:
// setup main UI as needed, then...
// I borrowed code from https://stackoverflow.com/a/10444161/65863
// for testing purposes, but you can set lpSource to your own manifest
// file, if needed...
ACTCTX ctx = {};
ctx.cbSize = sizeof(actCtx);
ctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID
| ACTCTX_FLAG_SET_PROCESS_DEFAULT
| ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
ctx.lpSource = TEXT("shell32.dll");
ctx.lpAssemblyDirectory = TEXT("C:\\Windows\\System32\\"); // <-- don't hard-code this in production code!
ctx.lpResourceName = MAKEINTRESOURCE(124);
HANDLE hActCtx = CreateActCtx(&ctx);
if (hActCtx == INVALID_HANDLE_VALUE) {
// handle error ...
return;
}
ULONG_PTR ulCookie = 0;
if (!ActivateActCtx(hActCtx, &ulCookie)) {
// handle error ...
ReleaseActCtx(hActCtx);
return;
}
// make single Edit control as needed ...
DeactivateActCtx(0, ulCookie);
ReleaseActCtx(hActCtx);
And this was the result:
The app was compiled without any manifest at all, so ComCtrl32 v5 would be the default. The top Edit control was created using the process's default Activation Context, and the bottom Edit control was created with an explicit Activation Context using a ComCtrl32 v6 manifest, and then EM_SETCUEBANNER applied to it (if you don't want to create your own manifest, you can use resource #124 from shell32.dll, per this answer to How to enable visual styles without a manifest).

How to click UI element using JXA

Please tell me how do I click in point coordinates in application window?
I trying to UI automate my application on OSX 10.10 using JXA technology.
In documentation I found that it's possible using click at event. By I'am beginner of JXA and cant find how make a call.
Code snippet which I tried in Script Editor:
var app = Application('my_application_path')
app.window.click.at('{100,100}')
Thank you for help
You can interact with an application's user interface using the System Events application. Here is a script that clicks at certain coordinates in Safari:
// Activate Safari, so you will be able to click like a user
Application("Safari").activate()
// Access the Safari process of System Events
var SystemEvents = Application("System Events")
var Safari = SystemEvents.processes["Safari"]
// Call the click command, sending an array of coordinates [x, y]
Safari.click({ at: [300, 100] })
If you want to click a specific button (or other element of the user interface), it is more appropriate to click that specific element. For example:
// Click the third button of Safari's first window to minimize it
Safari.windows[0].buttons[2].click()
To learn what user interface elements can be interacted with and how, check out the Processes Suite in System Events' scripting dictionary. To open the dictionary, in Script Editor's menu bar, choose Window > Library, then select System Events in the Library window.
See https://github.com/dtinth/JXA-Cookbook/wiki/System-Events#clicking-menu-items
For example:
var fileMenu = proc.menuBars[0].menuBarItems.byName('File');
Below is an example of a portion of a script I wrote that automates creating mailboxes (aka folders) in Mail. I ended up using the UI file menus and click because using make() in the Mail DOM had issues for me. Hope it helps someone.
(() => {}
//this is part of a script that automates creating mailboxes (ie folders) in Apple Mail
//I used the file menu UI because when I tried the Mail library and make() method
//there was strange behavior when trying to interact with the new mailbox.
//However, when creating the new mailboxes thru the file menu, all seems to work fine
const Mail = Application('Mail');
const strId = Mail.accounts.byName('Exchange').id();
const exchange = Mail.accounts.byId(strId);
const activeClientFolder = exchange.mailboxes.byName('ActiveClient');
const SysEvents = Application('System Events');
const mail = SysEvents.processes.byName('Mail');
//next two lines insure Mail will be open and in front
mail.windows[0].actions.byName('AXRaise').perform();
mail.frontmost = true;
const mailboxMenu = mail.menuBars[0].menus.byName('Mailbox');
//below shows EXAMPLES of using .click(), keystroke(), and keyCode()
let newFolder = function (parentFolder, newFolderName, addTrailingDelay = true) {
//next line will select the parent mailbox (aka folder) where the new mailbox will be inserted
Mail.messageViewers[0].selectedMailboxes = parentFolder;
mailboxMenu.click();
delay(.2);
mailboxMenu.menuItems.byName('New Mailbox…').click();
delay(.2);
SysEvents.keystroke(newFolderName);
SysEvents.keyCode(36);
//delay is needed when creating multiple mailboxes with a loop
if (addTrailingDelay == true){
delay(1);
}
}
//now the payoff
const count = newActiveClients.length;
for(let i=0;i<count;i++){
/* Client Root Mailbox */
newFolder(activeClientFolder, newActiveClients[i], true);
/* Client Email Folders */
newFolder(activeClientFolder.mailboxes.byName(newActiveClients[i]), 'Client', true);
newFolder(activeClientFolder.mailboxes.byName(newActiveClients[i]).mailboxes.byName('Client'), 'Client_FYI_Sent');
newFolder(activeClientFolder.mailboxes.byName(newActiveClients[i]).mailboxes.byName('Client'), 'Client_FYI_Inbox');
newFolder(activeClientFolder.mailboxes.byName(newActiveClients[i]).mailboxes.byName('Client'), 'Client_FYI_Client_To');
newFolder(activeClientFolder.mailboxes.byName(newActiveClients[i]).mailboxes.byName('Client'), 'Client_From', false);
}
})()

How to get control id from its handle?

How would one get an id of a control given its handle?
I want to set a tooltip on ListView control's header. As far as I figured out I need an id of the control to which I want to add this tooltip. As described in MSDN.
To answer your immediate question, GetDlgCtrlID().
Note that the sample you linked to immediately converts the toolID back to a handle again making your call redundant.
Here is a simple method I wrote for that:
// get identifier to a window
void showWindowID(HWND windowTarget) {
int theID = GetDlgCtrlID(windowTarget);
wchar_t text_buffer[100] = { 0 };
// convert
swprintf(text_buffer, _countof(text_buffer), L"%d", theID);
// print to console
//OutputDebugString(text_buffer);
// output result to a messagebox
MessageBox(nullptr, text_buffer, L"The ID", MB_OK);
}
Use ListView_GetHeader() to get the HWND of the ListView's Header control (which would be the replacement for the GetDlgItem() call in the sample you linked to). You do not need to get the Header's Control ID.

Edit Control not updating with Spin Control MFC

I am trying to use an edit control along with a spin control using MFC visual studio .net 2003. I have carried out the basic settings for the spin control like setting the "AutoBuddy" property and "SetBuddyInteger" property to True so that the Spin control works in coordination with the edit control next to it. In my Spin control's event handler, I am facing a problem when I am trying to call my Invalidate() function. The float value in my edit control does not update and stays zero. If I remove the Invalidate(), then the value increments but my paint function is not updated obviously. A code of the following is given below:
void CMyDlg::OnSpinA(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
// TODO: Add your control notification handler code here
UpdateData();
m_A = m_ASpinCtrl.GetPos(); // m_A is my edit control float value variable
Invalidate(); // Invalidate is to be called to update my paint function to redraw the drawing
UpdateData(false);
*pResult = 0;
}
I have carried out the tab order correctly as well for the two controls.
Any suggestions on where I am going wrong?
Thanks in advance.
If you just want to have a spinning integer, you don't have to override anything.
The spin control has to be right next to the edit control in the tab order. With AutoBuddy that's all you have to do.
m_A when getting the position back would do something weird and would not return you the correct value. Try using the pointer to get your position and value and then carry out the invalidate().
{
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
// TODO: Add your control notification handler code here
UpdateData();
CString tempStr;
m_A += pNMUpDown->iDelta;
tempStr.Format("%f",m_A);
m_ACtrl.SetWindowText(tempStr); // Like a CEdit m_ACtrl to display your string
Invalidate();
UpdateData(false);
*pResult = 0;
}
This should work perfectly well. Let me know if you still get any problems.

Resources