I'm trying to use the CodedUI Test feature of Visual Studio 2010.
I've got a problem while replaying the various actions for one of my html component. The Keyboard.SendKeys generated do not work (like if there was no input).
The code generated is :
// Type '{F4}{F4}{F2}titre{Enter}' in 'SaisieSD_DS' custom control
Keyboard.SendKeys(uISaisieSD_DSCustom, this.Params.UISaisieSD_DSCustomSendKeys, ModifierKeys.None);
If I replace the call to Keyboard.SendKeys by a call to System.Windows.Forms.SendKeys.SendWait, it does work.
I was thinking about a problem due to a loss of focus. However, if i do something like uISaisieSD_DSCustom.SetFocus(), it doesn't change the behavior.
Do you have any idea ?
thx.
Have you tried
uISaisieSD_DSCustom.WaitForReady()
Or one of the other waitfors?
Is it failing on this line? Or is it failing afterward due to this not working correctly?
You can also use the following to wait for all threads to complete before proceeding:
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.AllThreads;
Keyboard.SendKeys(uISaisieSD_DSCustom, this.Params.UISaisieSD_DSCustomSendKeys, ModifierKeys.None);
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.UIThreadOnly;
Just make sure you include the last line to turn it back to UIThreadOnly, or it will slow everything way down.
Visual Studio CodedUI Test searches for a control and sends those keys to it. In your case the control is 'uISaisieSD_DSCustom'.
You can try using:
Keyboard.SendKeys(this.Params.UISaisieSD_DSCustomSendKeys);
OR
Keyboard.SendKeys("{F4}{F4}{F2}titre{Enter}");
After typing the URL if we want to send the enter key then the below code works in Coded UI
Keyboard.SendKeys("{Enter}");
Related
I have the following code (simplified to show the problem):
var wdApp = new Application();
var wdDoc = wdApp.Documents.Open("C:\foo.docx");
wdApp.StatusBar = "Updating...";
var rng = wdDoc.Range(10, 10);
if ((bool)rng.Information(WdInformation.wdWithInTable))
{
}
//StatusBar value is gone...
What could be the reason?
How can I prevent it?
Do you know of other situations where this can happen?
Here screenshots of the problem
1 F10 (step over) later
Edit:
The provided code uses NetOffice and not the interop library from Microsoft directly, therefor the syntax is correct. You may notice in the provided screenshots that they are taken from a running application. Breakpoint, highlighting of current line of code executing, aswell as the actual result of the code in the word application on the right. Where at first there is the desired statusbar "Tabelle 8 von 17 wird neu erstellt." (Table 8 out of 17 is recreating) and at the next step my statusbar is gone and its the default stuff "165 von 8227 Wörtern" (165 out of 8227 words)
What could be the reason?
I believe this is to do with the library you are using. I tested your code but with the Word Interop library, and the only way I could get the status bar to reset was to manually click/type within the Word window.
How can I prevent it?
I would say take a look into the code base of library you are using. It is likely that it is doing something that is causing the behaviour. Unless there is a specific reason you are using NetOffice I would suggest switching to the either the standard Interop or VSTO.
Do you know of other situations where this can happen?
As above, I could only get the status bar to reset if I manually carried out some sort of input into the window.
I have over 100 tests to do .
For every test i need to show the title of testcase,
I cannot use MessageBox because it stops the tests, i need just to show a popup that contains the title and after 2 sec disappears.
I am using Selenium test drive for a web application and c#
You can enable logging . This will give clear picture about this.
https://www.seleniumeasy.com/testng-tutorials/logging-with-testng-using-listeners
Workaround at best without changing page DOM. How about writing to a html file with the test case name when each test starts in the title tag. Setup a refresh meta-tag with a time of 1-2 secs. Open up the html as a separate window and it keeps on refreshing on its own.
What about injecting html via javascript to your page at the beginning of every test?
I dont know the C# syntax, here's an idea how it may look in java:
((JavascriptExecutor) driver).executeScript( "document.body.appendChild( document.createTextNode( \"" + testName + "\") );" );
Depending on if you reuse your browser across tests, you might need an element something you can clean up after the test.
Or, just change the page title
((JavascriptExecutor) driver).executeScript( "document.title = \"" + testName + "\";" );
Just make sure you choose a way that doesn't interfere with the tests themselves.
But, what I'd really like to suggest is to look into ways of getting more confidence in your automation. If there are reasons for you to manually need to look at what your automation is doing.. that just doesn't sound optimal..
If anyone can help me I'd appreciate it.
I'm working on a C# file in Visual Studio 2010 that I need to be able to test a website with multiple form pages, for the purpose of an example we'll refer to them all as 1.aspx, 2.aspx etc.
I've my code that fills out the first page (1.aspx) fine, and click the "continue" button to load the next page, but when it gets to 2.aspx it won't continue to fill out the form.
We'll say an element on the 2.aspx page is called "DOB". On trying to run from the start (I've all the pages form data in the one .cs file) I get an error like "DOB does not exist in the current context".
Anyone's insight into this would be really appreciated!
In all honesty, it sounds like you might be better off using the WatiN Framework. I have been writing automation with it for years and the way that it is implemented and its ease-of-use make it worth the slight learning curve.
Just to add a bit more to the answer; and yes, this is pseudo-code:
[Test]
public void Should_attach_to_browser()
{
ExecuteTest(browser =>
{
browser.GoTo(NewWindowUri);
browser.Link(Find.First()).Click();
var findBy = Find.ByTitle("New window");
var newWindow = Browswer.AttachTo(browser.GetType(), findBy);
newWindow.Close();
});
}
In the code above, note the Browser.AttachTo(browser.GetType(), findBy); method. Based on what I have understood of your question, the .AttachTo() method would work well since you would be able to take the focus off the current form and assign it to the next in your work/execution flow.
I am trying to use watin to mimic login to live.com using c#. code is below.
IE myIE = new IE("http://login.live.com/");
myIE.TextField(Find.ByName("login")).TypeText("abc#abc.com");
myIE.TextField(Find.ByName("passwd")).TypeText("1234");
myIE.Button(Find.ByValue("Sign in")).Click();
However it always failed to find the textfield:
WatiN.Core.Exceptions.ElementNotFoundException: Could not find INPUT (hidden) or INPUT (password) or INPUT (text) or INPUT (textarea) or TEXTAREA element tag matching criteria: Attribute 'name' equals 'login' at http://login.live.com/
The sample code in home page of http://watin.org/ works fine for www.google.com.
Did I miss something or is there anything special on http://login.live.com that prevents watin to work?
PS: I am running windows 7 64bit. VS 2008 with .net 3.5
You're hitting issues because the email field you're trying to type in is an HTML5 element.
Create the TextFieldExtended class as defined in this SO question: WatiN support for HTML5 tags
Then your code will be like the below:
ie.GoTo("http://login.live.com/");
ie.ElementOfType<TextFieldExtended>(Find.ByName("login")).TypeText("thisismyusername#here.com");
ie.TextField(Find.ByName("passwd")).TypeText("thisismypassword");
ie.Button(Find.ByValue("Sign in")).Click();
Tested on Watin2.1, IE9, Win7-64.
You may want to try this: I got it to work on my end:
ie.Div(Find.ByCustom("innertext","someone#example.com")).Click();
ie.TextField(Find.ById("i0116")).TypeText("hello");
ie.TextField(Find.ById("i0118")).Click();
ie.TextField(Find.ById("i0118")).TypeText("Hello!");
I recommend using this test Recorder. It will give you the elemnt names to use in your source:
http://www.codeproject.com/Articles/19180/WatiN-Test-Recorder
Edit:
I was also able to get this to work when finding by divID.
ie.Element(Find.ById("idDiv_PWD_UsernameExample")).Click()
I've read several articles that tell you how to add text to the output window in visual studio from within an Add-On (specifically, a visual studio 2008 integration package, via the visual studio 2008 SDK 1.1), but no examples of how to read text from the output window. My goal is to parse text from the debug output window while debugging a certain application (TRACE output and possibly stdin/stdout). The IVsOutputWindowPane interface has no methods for reading in text from the output window. The documentation seems to imply that it is possible, but it doesn't provide an example:
http://msdn.microsoft.com/en-us/library/bb166236(VS.80).aspx
Quote: In addition, the OutputWindow and OutputWindowPane objects add some higher-level functionality to make it easier to enumerate the Output window panes and to retrieve text from the panes.
Preferably I'd like to be able to subscribe to an event that fires when a new line of text arrives, similar to a StreamReader's asynchronous reads.
It is possible, it is just a long winding path to get to it:
ServiceProvider -> IVsOutputWindow -> GetPane( debugwindow ) -> IVsUserData -> GetData( wpftextviewhost ) -> IWpfTextViewHost -> IWpfTextView -> TextBuffer -> Changed event.
Presuming you have a VS IServiceProvider from somewhere else (vsix extension/whatever, global service provider), and without any error checking, it looks like this:
IVsOutputWindow outWindow = ServiceProvider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;
Guid debugPaneGuid = VSConstants.GUID_OutWindowDebugPane;
IVsOutputWindowPane pane;
outWindow.GetPane(ref debugPaneGuid, out pane);
// from here up you'll find in lots of other stackoverflow answers,
// the stuff from here down is interesting to this question
IVsUserData userData = (IVsUserData)pane;
object o;
Guid guidViewHost = DefGuidList.guidIWpfTextViewHost;
userData.GetData(ref guidViewHost, out o);
IWpfTextViewHost viewHost = (IWpfTextViewHost)o;
IWpfTextView textView = viewHost.TextView;
textView.TextBuffer.Changed += YourTextChangedHandlerHere;
Your text changed handler will then get called every time the output window gets more data. you won't necessarily get it line by line, but you'll probably more likely than not get big chunks you'll need to deal with on your own.
It is highly likely that some of the above did not even exist in VS in 2010. But it exists now!
The default behavior (when you don’t set the listener explicitly) of VS is to display trace massages in the debugger output window, which you appreciate if you want a simple solution and do no other actions with the massages.
Unfortunately this is not your case. So you have to define a trace listener to send (and store) your trace massages where you then will be able to read them. The trace listener could be a file (for example XML) or you can create a custom listener by deriving a class from the base class TraceListener if you don't want to bother yourself with an additional file.
I don't know that what you ask is possible. But, you can register your add-in as a debugger for your application so that you get the output the trace messages. These are typically routed to OutputDebugString, and can be captured as described in this article: http://www.drdobbs.com/showArticle.jhtml?articleID=184410719. It does not give you the normal output, only debug, but it does not depend on the technology of the debugged application.
The solution on this page selects the text in order to read it. I'm hoping there's a better way.
Automatically stop Visual C++ 2008 build at first compile error?
Private Sub OutputWindowEvents_OnPaneUpdated(ByVal pPane As OutputWindowPane) Handles OutputWindowEvents.PaneUpdated
pPane.TextDocument.Selection.SelectAll()
Dim Context As String = pPane.TextDocument.Selection.Text
pPane.TextDocument.Selection.EndOfDocument()
End Sub