Watin - how to test site with popup pages - automated-tests

I'm using WatiN (Web Application Testing in .Net) to do integration testing on a Dynamics CRM 4.0 website.
CRM uses a lot of popup windows - eg clicking on a Contact in a list opens a new browser window with the Contact's details.
I want to test:
login to CRM (done)
go to the Contact list (done)
click on an Contact, thus trigger the popup (done)
test functionality within the Contact entity/form (can't do)
So I need to get hold of the popped up window.
How?
Thanks.

//after the click that opens the popup:
IE iepopup_1 = IE.AttachToIE(Find.ByUrl(theUrlOfThePopup));
//operate on iepopup_1

Syntax has changed slightly in newest version of WatiN (v2.0.20.1089), is now:
IE poppedUpBrowser = IE.AttachTo<IE>(Find.ByUrl("http://www.popped-up-site.co.uk/"));

Maybe searching for only part of the URL would solve it. This can be done using regular expressions:
System.Text.RegularExpressions.Regex popupHiddenRegEx = new System.Text.RegularExpressions.Regex("part_Of_URL");
IE poppedUpBrowser = IE.AttachTo<IE>(Find.ByUrl(popupHiddenRegEx));

Related

Visual Foxpro attempting to .click() a submit button on web or .submit() the webform - failing

I am programming in Visual Foxpro. I tried to programatically .click() at the submit button. It used to work, but now it triggers nothing. Alternatively I tried to .submit() the form. This too triggers nothing. But if I click the submit button at the website, it works perfectly. Can anyone help me out? arunkasi.co#gmail.com
My coding as as follows:
declare Sleep in kernel32 integer nmilliseconds
WebMain = CREATEOBJECT("InternetExplorer.application")
WebMain.navigate("https://epayment.hasil.gov.my/fpx/one.php")
WebMain.visible = .t.
DO WHILE WebMain.busy .OR. WebMain.readystate#4
Sleep(300)
ENDDO
WebMain.Document.Forms("LogonForm1").jenis_id.selectedindex = 1
WebMain.Document.Forms("LogonForm1").no_id.Value = "123456781234"
WebMain.Document.Forms("LogonForm1").kapca.Value = "56789"
WebMain.Document.Forms("LogonForm1").cmdSubmit.click() && IT DOES NOT WORK !
WebMain.Document.Forms("LogonForm1").Submit() && ALTERNATIVELY, THIS TOO DOES NOT WORK !
Most likely cause of your change in behavior is an update to Internet Explorer, wherein they improved the security model to keep malicious websites from injecting unwanted behavior into them.
See if the website you are attempting to reach has an actual web service that applications can use to send POST messages via HTTP instead of using a web page, (such as using the MSXML.XMLHTTPRequest object). If that website is your company's, creating a proper web service is a far better use of time than automating internet explorer through FoxPro.
But, if that's not possible, I believe you can adjust your code to use the IE-specific fireEvent method.
Add a parameter to click() or submit(). This will work:
WebMain.Document.Forms("LogonForm1").cmdSubmit.click(1)
or
WebMain.Document.Forms("LogonForm1").Submit(1)

Disabling Submit Button in ASP.NET 3.5 Application with JavaScript breaks BlackBerry submission

The following code is being used to disable a Submit button once it has been clicked. This works great on desktop browsers and most BlackBerry mobile browsers.
Submit.Attributes.Add("onclick", "javascript:this.disabled=true;" +
ClientScript.GetPostBackEventReference(Submit, null));
Unfortunately, when using a BlackBerry Storm clicking the submit button causes the device to just reload the page. If I remove this code the Storm browser submits the page just fine. I need to disable the button when the browser is capable of doing so but do not want to affect browsers that are not JavaScript capable.
I realize I could add the jQuery framework and only attach the event client side, but am trying to look for the simplest fix (read least intrusive) as this is a legacy application. Any suggestions?
I believe you can do it this way - I haven't done this in a long time and some of the HttpCapabilities API has been tagged as obsolete, but in general you can detect if the browser supports javascript by doing this:
var myBrowserCaps = Request.Browser;
if (((HttpCapabilitiesBase)myBrowserCaps).EcmaScriptVersion.Major > 1)
{
// Browser supports javascript
Submit.Attributes.Add("onclick", "javascript:this.disabled=true;" +
ClientScript.GetPostBackEventReference(Submit, null));
}

Open Default page without Addressbar, Menubar & Statusbar in ASP.NET

How can I open my Default.aspx page without Addressbar, Menubar & Statusbar?
Remember it's the user with an already-opened web browser that chooses to visit your website, effectively Default.aspx page, whether or not the browser is launched by you or a program while testing your website. So a bit of client-side/JavaScript "magic" is needed to modify or fake the desired result based on an already existing browser window...
Using JavaScript, you can launch a new window with those features turned off, and close the old window. For example, IE's window.open(..) args are specified here.
It provides an example
varCustomFeatures = 'titlebar=no, status=no,menubar=no,resizable=yes, scrollbars=no,toolbar=no,location=no,directories=no,left=0,top=0,height=';
window.open(windowURL, '_blank' , varCustomFeatures,true);
Details may vary between browser in which case you will likely need to employ browser detection.
You can't.
However, you can create a popup windows without the bars in Javascript using open method, like this:
open("MyPage.aspx", "MyWindow", "toolbar=no,status=no,menubar=no");

How do I POST to a web page using Firebug?

How do I POST to a web page using Firebug?
You can send POST request to any page by opening console (e.g. in FireFox ctrl + shift + k) and typing simple JS:
var formPost = document.createElement('form');
formPost.method = 'POST';
formPost.action = 'https://www.google.com'; //or any location you want
document.body.appendChild(formPost);
formPost.submit();
AFAIK Firebug can't do this. However, there is a very useful Firefox extension, in the spirit of Firebug, called Tamper Data. This should be able to do what you want.
It allows you to monitor each request made by the browser, and you can turn on an option that allows you to look at, and edit, every single request before it gets sent.
Firefox 27 (maybe earlier versions too, never checked) has built-in developer tools to modify and resend requests. If you don't have Firebug installed, the console is available by pressing the F12 key. If Firebug is installed, press Ctrl+Shift+K instead.
I know this is an old question, but I recently stumbled upon the same problem and wanted to share the method I am using.
Assuming the web site you want to POST to has a form with method="POST" (a very likely scenario), you can use Firebug's JavaScript command line to programmatically submit a POST request. Just click the "Show Command Line" icon in Firebug and enter something like this in the narrow text box at the very bottom of the window:
document.forms[0].submit()
Maybe this helps someone.
Another simple solution is to load any webpage that uses jQuery, and type up a $.post() in the console.
HTTP resource test is a firefox plugin that can do this.
Another powerful Firefox plugin to perform post request and some more features is the Hackbar.
Related:
To resend a POST already made, right click the POST request in the Net/XHR view and click "Resend".
Using Firebug 1.12.0:
Got here looking for a Firebug way of doing this. Then I realized that I could use Fiddler. This is the most powerful tool I know when it comes to debugging web requests.
Fiddler The free web debugging proxy for any browser, system or
platform
Click the Composer tab and write your request as desired - then click Execute.
NO NEED of plugins !!
Just drag any url in BOOKMARK BAR, then right click and EDIT, and insert javascript code:
javascript:var my_params=prompt("Enter your parameters","var1=aaaa&var2=bbbbb"); var Target_LINK=prompt("Enter destination", location.href); function post(path, params) { var form = document.createElement("form"); form.setAttribute("method", "post"); form.setAttribute("action", path); for(var key in params) { if(params.hasOwnProperty(key)) { var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", key); hiddenField.setAttribute("value", params[key]); form.appendChild(hiddenField); } } document.body.appendChild(form); form.submit(); } parsed_params={}; my_params.substr(1).split("&").forEach(function(item) {var s = item.split("="), k=s[0], v=s[1]; parsed_params[k] = v;}); post(Target_LINK, parsed_params); void(0);
then enter the target site-link, and click that button in BOOKMARK BAR! That's all!
( source: https://stackoverflow.com/a/38643171/2377343 )

Programmatically open a new tab in ie7

I am developing web applications with c#, Aspnet 3.5, and Ajax 2.0.
Question - I run Application_1 in ie7. I would like to programmatically start running Application_2 from Application_1 in a new tab, no matter what the client settings are.
Until now I have been opening Application_2 in a new window from Application_1 using
ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, "window.open('theurl',' width=800, height=500'); ", true);
I would like to do something similar to open a new tab.
Unfortunately there is no way to control whether the window opens in a new tab or new window. This is a user setting that can't be overridden in code.
Here is Microsoft's justification if you're interested.
"Regarding script, there is no "target='_tab'" feature or any direct access to tabs from script beyond what is available with multiple windows today. We are working on balancing the default behavior for whether a window opened from script opens as in a new frame or a tab."
IEBlog
You could inform your user that by holding ctrl+shift and clicking a link will open in a new tab.
As Paul already noted, this cannot be done via any script or code.
I think it's best to let your users decide (via their individual browser settings) how they want to open the new page - in a new window or in a new tab in the same window.

Resources