I'm using Watin in C# console app to crawl websites, there are five console app running at the same time.
The reason I partly use Watin as crawler is because a few websites use javascript(or ajax) to set page content.
Following is the sample code to get a page comment count:
Settings.Instance.MakeNewIeInstanceVisible = false;
using (var browser = new IE(commentLink, true))
{
browser.Link(Find.ByUrl(commentLink)).WaitUntilExists(20);
Span commentSpan = browser.Span("COUNT_TOTAL");
if (commentSpan.Exists)
{
int commentCount;
if (Int32.TryParse(commentSpan.InnerHtml, out commentCount))
{
return commentCount;
}
}
}
My problem is after running these 5 console app for a while (90 min), a lot of IE instances are stayed open (because of timeout or error or IE is busy), so the system is quite slow and need to reboot. How do I change my code to prevent this thing happen and make my apps stay effecient?
I have the Problem with the File Upload window. When I used it the first time it works perfect but when I call the same functionality to open and upload a File the open button (in the "Choose File to Upload" Dialog) is pressed to fast. So the Test can not write the complete path of the File over set and so the I can not open the File. The Source Code of the function:
public void OpenFileDialogAndUploadCsvFileWithName(string fileName, IE editPage) { var fileUploadDialog = editPage.HtmlDialog(Find.ByTitle(PageTitle)); fileUploadDialog.WaitForComplete(); FileUpload fileUpload = fileUploadDialog.FileUpload(Find.ById(new Regex("_FileUpload"))); fileUpload.Set(fileName); Image image = fileUploadDialog.Image(Find.BySrc(new Regex("/icons/upload.png"))); Element parentElement = image.Parent; parentElement.FireEventNoWait("onmouseup"); parentElement.FireEventNoWait("onmousedown"); }
The Upload File Dialog is open from Internet Explorer Modal Dialog Window.
What is the best place for javascript that is specific to a partial view? For example, if I have a partial view (loaded via ajax call) with some divs and I want to turn those divs into an accordian, would it be better put the $("#section").accordion() in script tags inside of the partial view, or in a .js file in the function that retrieves that partial view and inserts it into the DOM?
Obviously, common methods I will be keeping in a .js file, however I am more talking about javascript very specific to the partial view itself. Most things I find on the net seem to say to put all javascript into a separate .js but nothing addresses the idea of partial views.
Process[] processes = Process.GetProcessesByName("iexplore"); foreach (Process p in processes) { if (p.MainWindowTitle == url + " - Microsoft Internet Explorer") { // this doesn't find it. } }
I'm testing a site that serves up some binary (i.e. non-HTML) content. Some links directly deliver custom images, other links custom PDF's.
I'm building test cases in WatiN and NUnit. Wondering if there's a way, using WatiN to get it load a page and then get the byte[] contents of that page.
Currently, I'm just launching a WebClient to grab the content, rather than through WatiN but that's more untested code in my test suite.
We're having an intermittent problem that occurs when running certain integration tests on our continuious integration server..
For some reason, every now and then, we get an autocomplete popup that causes a timeout and ultimately a build failure. Is there an eloquent way to detect the popup and click through it?
I want to write a few web tests (over WatiN/Selenium + CassiniDev web server) for my asp.net web application.Problem I encountered is that I dont know what to do in such situations: there is a page where user can click the button to call some third-party service. In my web test i want to create mock of this service, which will always return static value (some value in these test case and other value in other test case).How can i do that?
Currently i use IoC/DI container Microsoft Unity. And my pages gets his dependencies in a manner described in http://msdn.microsoft.com/en-us/library/ff664622%28v=pandp.50%29.aspx.
The only solution that comes to my head is: place all dependencies in web.config for each test case and copy necessary web.config on SetUp of test.
I am writing Watin test in MVC Asp.net app. I mvc app, all input are wrpped with form and every time an input or textarea is changed their form gets submitted by jquery like code below:
This is perfect when changes are done by keyboard. However this doesn't trigger the form submit when input/textarea are changed by Watin TypeText() method. I tried to call Change() and Blur() events by Watin and also tried PressTab() with no luck.
When I use WatiN to go to a specific web page, how can I fake the HTTP referrer with a query string (i.e. request is from google search with query string q=search_term)? So I can verify that the response header has the 301 redirect for specific referrer URL.
I am using a gridview as a dropdown extender for a textbox which works nice. I want to select a row in the gridview and fill in some textboxes with data from that row. I know how to do the Attributes.Add for cells in the RowDatabound event. But I have always passed the cell data to another page as parameters. How can I stay on the same page and fill in the textboxes?
Do I setup a javascript and pass the parameters to it and have it fill in the textboxes? I have other texboxes that the user has entered and need to keep that data there.
I have view.aspx page that when I open page and don't do any thing in this page i.e for 10 minutes when I come back to this page after 10 minutes and click on hyperlink or button below error happen. Why this error happen?
Based on this article, I've written a custom class which implements the Watin.Core.interfaces.IFindByDefaultFactory, but I don't think I'm correctly assigning it to the watin settings, because it is never used.
Basically, Where/when should I assign to the Settings.FindByDefaultFactory? I've tried in my test Setup, and the text fixture's constructor, but neither seem to cause my custom class to be used. The tests still run and work, but I have to use the full asp.net ID's.
I'm using Watin 2.0.15.928 in VS2008 from nUnit 2.5.2.9222. I am running visual studio as administrator, and tests run sucessfully as long as I don't rely on my custom find logic.
Here's what the start of my text fixture looks like, where I set the FindByDefaultFactory namespace Fundsmith.Web.Main.BrowserTests { [TestFixture] class WatinHomepageTests { private IE _ie; [SetUp] public void Setup() { Settings.FindByDefaultFactory = new FindByAspIdFactory(); _ie = new IE("http://localhost/somepage.aspx"); } //etc etc...
And this is what my custom Find By Default factory looks like (simplified), unfortunately, it's never called.
using System.Text.RegularExpressions; using WatiN.Core; using WatiN.Core.Constraints; using WatiN.Core.Interfaces; namespace Fundsmith.Web.Main.BrowserTests { public class FindByAspIdFactory : IFindByDefaultFactory { public Constraint ByDefault(string value) { // This code is never called :( // My custom find by id code to cope with asp.net webforms ids... return Find.ById(value); } public Constraint ByDefault(Regex value) { return Find.ById(value); } } }
Edit: Extra information after the fact. Based on me fuguring this out, (see answer below), It turns out that the way I was consuming Watin to find the elements was wrong. I was explicitly calling Find.ById, rather than letting the default action occur. So I'd reassigned the default but was then failing to use it!
[Test] public void StepOneFromHomepageShouldRedirectToStepTwo() { _ie.TextField(Find.ById("textBoxId")).TypeText("100"); //Other test stuff... }
Now if you click the "toggle" button div tag id sub3 will display. If you click different button div tag blah will display.If you click refresh then both the toggle and different div tags disappear. Is there a way so that when you click refresh that the both div tags stay visible through the postback?
I have a popup window of course through the use of modalpopup extender that searches a record. In the popup window, I have two buttons - a search and a close button. Whenever, I click on the search buttton, the popup window immediately disappear. How am be able to make my modal popup window to stay visible even I click on the search button?
I have a Gridview which is inside a Updatepanel which is updated through a Timer Control every 5 seconds. So every 5 seconds I get new data in the rows. I am facing an issue in which I want to display the whole mult-line content of my Textbox(es).It displays fine but the modal window disappears after the UpdatePanel is updated.
How do I display this pop-up modal window and make it stay while the UpdatePanel continues to update the rows in the background?
I've a dataentry screen where I've to give the users aprovision to enter date and for doing that I've used a DatePicker control. The problem is when I'm clicking on the next/prev button to change the month of the calender, the calender is not staying on the screen. So in order to select other month the user has to re click on the button. find below the stepwise description of the problem I'm facing.
1. I click on the calender icon and the calender popps up.
2. Now user tries to navigate months (i.e June to July or June to May) using Next/Prev button of the Calender Control.
3. When Navigating from current month to next/prev month I want the calender to be shown on the screen but actually on click of the Next/Prev button one postback is happening hence I'm loosing the calender from the screen as the calender is loaded again.
4. I'm getting the selected date using onselectedChange event handler.
5. The users will have to click the button again if he wants to navigate to another month.
Is there any way to keep the calender on the screen during the month got changed.
When I inserted item to database, the Form refresh and return to all blank or standard selection. What can I do if I want it keeps the last entered value after inserting record ?
I need this because there are many items to insert and only partial fields need changes from last entered records.
Although there are a number of floating menu tuts out there, I can't seem to find one that will simply let a div tag stay in one position with relation to the screen size. I have a div tag in the middle right of my page that must basically stay there even if the user scroll down.
I know I'm missing some simple little thing here...
[code]....
(I put in an Exit Sub at the very top so I'm sure it's not the code).
Essentially, everything is working just great except I need the modal popup to close only if the form data is correct and I choose to close it. The UpdatePanel, "UpdateInfo", is in place to allow form processing without interfering with the UpdatePanel, "UpdatePopup". In my real code, I have a hidden label that I use to report errors. The UpdateInfo is vital for showing/hiding the error but the popup must remain showing...and modal. (I had something like it working once before but I've re-written it since and just can't remember how to do it.)
I have a HTML table in a webpage of an ASP.NET website.
I want this table to stay in the screen when I scroll the page.in fact it's like a toolbox for me and I should always have easy access to it.how should I do that?
I have an asp.net page "demo.aspx", that has a normal link called "Demo Link" which uses jQuery Thick box. The page that is wrapped inside the Thickbox is "target.aspx", that has a button "Demo Button" and a label.
If I click on the Demo Link, it show the "target.aspx" wrapped inside the Thickbox nicely. However, If I click on the "Demo Button", Thickbox is disappeared, "target.aspx" is not wrapped in Thickbox anymore, it is displayed like a normal asp.net page.
Here's the mark-up code of demo.aspx:
<a href="target.aspx?height=600&width=800" class="thickbox" title="">Testing Thickbox with Post-back</a>
Here's the code-behind of target.aspx:
Protected Sub btnDemo_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnDemo.Click lblDemo.Text = "Hello World!" End Sub
How do I keep target.aspx in the Thickbox after the post-back of itself?