Coded UI - How to Capture Image After a Mouse Click Event - visual-studio

What is the best option of capturing image after each mouse click in recorded session of Coded UI?
For example, in UIMap.Designer.Cs file I have entered image capturing lines:
Mouse.Click(uIOutagesandSafetyHyperlink, new Point(62, 2));
Image MSOPic1 = UITestControl.Desktop.CaptureImage();
MSOPic1.Save(#"C:\Automation\TestAutomation\web\Recordings\FullSite1\Screenshots\MSO\HomePage_" + DateTime.Now.ToString("ddMMyyyyHHmmss") + ".png");
The above code takes a screenshot but it does not take the current browser's screenshot, just captures another screen where the current browser window does not exist. How can I capture screenshot of the active browser where the test is taking place?
One more question: Does Visual Studio provide an alternative way to capture images during playback? Like through configuration?

One more question: Does Visual Studio provide an alternative way to capture images during playback? Like through configuration?
By default coded ui test should take a screenshot with each action it does.
You can find these screenshots in the html outputs for your tests.
See: https://msdn.microsoft.com/en-us/library/jj159363.aspx
If in any case it is not enabled for your tests you have to set:
Playback.PlaybackSettings.LoggerOverrideState = HtmlLoggerState.AllActionSnapshot;
If you want to have this setting in all tests and for all actions call it in the [TestInitialize()] method of each test you want to apply it to.
Like so:
[TestInitialize()]
public void MyTestInitialize()
{
Playback.PlaybackSettings.LoggerOverrideState = HtmlLoggerState.AllActionSnapshot;
}

The UITestControl class has a CaptureImage method. To get an image of the current browser, find its UITestControl object (which may be derived from that) and call its CaptureImage method.
Please do not edit the uimap.designer.cs file as it is an auto-generated file and your edits may be lost. See this answer.

Related

How to capture and display text for auto appearing and disappearing pop-up using cypress

i Would like to know the method on How to capture and display text for auto appearing and disappearing pop-up using cypress.
I had used the window methods for capturing the text and displaying it, but it doesn't capture the message.
The pop-up/alert is designed to appear whenever user generates a report and it automatically disappears after 3 secs.
Please help
Depends on what creates the popup.
For window alert, this question How can we test the alert and text uses stub to capture the call.
It asserts the stub is called with certain text.
const stub = cy.stub()
cy.on ('window:alert', stub)
cy.get('button').contains('Generate Report').click()
.then(() => {
expect(stub).to.be.calledWith('I am an alert box!')
})
From Cypress Window-Alert
If the popup is generated by framework, e.g React the approach is the same as any text on the page.
You might need to use cy.clock() to control the timing, presuming you want to assert the appear/disappear cycle.

How to write Xamarin.UITest case for Software Back Button on Android

I am writing UITest cases for my Xamarin forms project. Now, i am stuck at Navigation Part. I know using "app.Back()" we can navigate back but on our Project Hardware Back Button is disabled. Is there any way we can use Navigation Bar "Back button" ?
I tried to get elements in Page by using following code "AppResult[] results = app.Query();" but still i am not able to find any element which says barbackbutton or backbutton etc in the list.
Bharat, after reading this a couple times, I think what you are asking is "how do I find the automation ids / elements to target".
There's a couple different ways to do this. My preferred one is App.Repl(). Here's the Microsoft docs on it, but in short:
at the point in your test where you are on the application view that you want to find an element on, put in App.Repl()
[Test]
public void CanTapButton()
{
App.Repl();
}
Run the test. When the test gets to this point, a repl window will open and the test will pause. End the test if you want, but keep the command window. It will look like this:
Type into the command prompt tree, to see the full layout of the page visible on the device.
You can use the app query calls in the Repl window to draft queries. For example,
app.Query(x => x.Marked("cpgTitle"));
will return the cpgTitle element that you can see listed in the tree. You can then use that app query to interact with the element, using something like App.Tap(appQueryVariable).
AppQueries docs are here and overall, it's very similar to selenium-style selectors.

SwitchTo method for Coded UI

I am working on a, hand coded, Coded UI test for an application.
The application has a certain function that operates in 2 windows. When a button is clicked, a new window appears and then the user makes a selection upon which that window closes, and then the user continues taking actions on the main window.
With Selenium, I would handle that by iterating through all the window handles and switching by using passing it the URL of the page I wanted using the "driver.SwitchTo().Window(handle)" method. However, with Coded UI, I have not found a similar solution. Using the Process class I can do something similar that could work:
Process[] myList = Process.GetProcessesByName("iexplore");
foreach (Process item in myList)
if (item.MainWindowTitle.Contains("Window Title"))
{
item.Kill();
}
The problem is that the application that I am testing is poorly designed and all windows throughout the application have the same name, thus it will not work.
Is there a method which can be used to switch to a different window on Coded UI? Or what would be the best approach?
Take a look at this question, it might help: Interacting with multiple instances of an application in Coded UI
You don't do "switching" in CUIT, every window and control is accessed via a UITestControl object. If you want to do stuff on an other window you create a new object for it. If you can't differentiate the two windows with search properties you can use the Instance property or FindMatchingControls method.
To catch a window creation event you can use a winhook. It gives you the window handle of every window created. Using that you can find out if the window created is the window you are waiting for and then use the UITestControlFactory.FromWindowHandle to create a UITestControl for CUIT to interact with. If you have a generated class for that window you can create an instance of that class and call its CopyFrom method to pass to it the control you created from the window handle.
I am using:
public static HtmlDocument WaitForPopup(string popupName, string text)
{
BrowserWindow browser = new BrowserWindow();
browser.SearchProperties.Add(BrowserWindow.PropertyNames.Name, popupName,
PropertyExpressionOperator.Contains);
browser.WindowTitles.Add(popupName);
browser.WaitForControlExist();
browser.WaitForControlReady();
browser.SetFocus();
HtmlDocument html = new HtmlDocument(browser);
html.SearchProperties.Add(HtmlDocument.PropertyNames.InnerText, text,
PropertyExpressionOperator.Contains);
html.WaitForControlExist();
html.WaitForControlReady();
Playback.Wait(1000);
return html;
}
Just call WaitForPopup("your window name", "some constant text in window") and continue with tests there.
Note that this method will return html of the new window and you can use it further on.

Import Images from File delphi

I'm familiar with delphi scripting so I basically need a strong direction to start from. I've done importing images from files in other languages and it has been quite trivial, but I can find little documentation about this for delphi.
I need to be able to register a control event on a button that will open up a "choose folder/file" dialouge, and then import an image into an object that I can append to a List of some sort.
Anyone have any documentation on this?
Although your question is rather broad and "delphi scripting" sounds interesting here is an example that might get you started:
Project: Let the user select an image and display this image
This form contains a TButton, a TOpenPictureDialog and a simple TImage for displaying one image (sorry, no list of pictures in this example).
Part 1 ("register a control event on a button"):
Attach an OnClick event handler to the button by double clicking the button in the form designer. If your button's Name is btnOpenPicture then the auto-generated handler will have the name btnOpenPictureClick (see the following code). The code in this handler will be executed when the user clicks the button.
procedure TForm1.btnOpenPictureClick(Sender: TObject);
begin
if OpenPictureDialog1.Execute(Self.Handle) then
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;
Part 2 ("'choose folder/file' dialouge") is represented by OpenPictureDialog1.Execute which opens a dialog where the user can choose a picture. The Execute command waits until the user closes the dialog and returns True if the user chose not to cancel the dialog but rather chose an image file (the filename is stored in OpenPictureDialog1.FileName).
Part 3 ("import an image into an object") would then be Image1.Picture.LoadFromFile which instructs the TImage component to load and display the file the user chose.
I cannot immediately name a component included in Delphi which could be used easily as a list for displaying images visually (that's your "append to a List of some sort"). I only know some third-party components which are not available for free, thus not good for quick experimenting.
Maybe this can be a base for asking more specific questions (as already encouraged by the commentators of your question). I already have one: "Is there a VCL component I could use for displaying a list of images?"
There are lots of articles and tutorials on how to do this. Code for loading images can be found in this Stackoverflow question; to complete your problem, you need a TButton and probably a TOpenPictureDialog.

Edit onClipEvent Actionscript

I am a beginner so please take it easy. First some history, I am trying to modify a flash movie (not created by me) that has 4 images in it.
I have to now add 2 more images (pic5.png and pic6.jpg) to the "slideshow" as shown in the attachment, I have added the 2 images to the library. The problem I am having (as I understand, I may be incorrect) is that _root.count = 4 causes the movie to jump back to the first image after it displays the 4th one which does not display the 5th & 6th image.
My question, how do I edit the value of _root.count to 6, so that it will show all the 6 images. Additionally how do I create a hyperlink on each image.
Please can someone guide me.
Many thanks.
Looking at your screen shot, Layer 2 (which contains the slideshow movieclip) is locked. If you unlock the layer by clicking on the padlock icon you should then be able to edit the script.
To edit the script double-click on the script in the Movie Explorer panel and the Actions panel should open. You can edit the script here.
The second part of your question - how to create a hyperlink - is very broad and there are many different ways to approach it. The most elegant approach would depend on how your project was structured.
The simplest way might be to define a variable to hold the path to the current image and add another onClipEvent handler.
So in the existing onLoad you would add…
this.path_to_image = http://your-domain.com/images/your-first-big-image.jpg;
Then add the new event handler
onClipEvent(mouseUp){
getURL (this.path_to_image);
}
You would then have to update the path_to_image variable whenever the image changed.
slideshow.path_to_image = http://your-domain.com/images/your-next-big-image.jpg;

Resources