CodedUI Test HtmlButton disabled in JS - angularjs

I'm having an issue in Coded UI where a HTMLButton is disabled until the user selects an item in a list box. At which point the button is enabled via javascript. The problem I'm having is that the recorder is not picking up the change. When I run the test I get a "ActionNotSupportedOnDisabledControlException". I've tried the WaitForControlEnabled, Find and WaitForCotrolReady methods but nothing seems to work. Is there a way I can make the button enabled in code?

First you need to check control is disabled or not visible.
I have faced same issue where control was hidden under another control, so it was not visible directly.
You can enable button by executing Javascript from your Coded UI test/script.
Javascript Code:
document.getElementById<ID>.disabled = false;
document.getElementsByClassName<>.style.visibility='visible';
Test/Script Code:
this.UIMap.Window.ExecuteScript(<above / your JavaScript>);

Related

TestRecorder with MaterialCommand in Toolbar

In a test-class, is there any way to invoke Buttons inside the toolbar, without a name (""), which were added like this?
getToolbar().addMaterialCommandToRightBar("", FontImage.MATERIAL_PICTURE_AS_PDF, e -> createPDF());
Or can I somehow tell the test-class to show a specific form ?(which is happening when I click the button without a label).
The test recorder is not generating any code in that case. It seems that it is only working with buttons, which have a non-empty String as name, as they are simply invoked by
clickButtonByLabel("Label");
The test recorder was written before the Toolbar existed, we tried to update it for the Toolbar recently but this proved to be pretty difficult.
We have this issue that covers this bug. As a workaround you can post the command directly in the code of the test.

Customizing & Styling Angular X-Editable Popover Input

I'm using angular x-editable in my project for an editable popover. I've successfully made changes to the look of my confirmation button to an .svg I wanted to use and removed the Cancel button doing:
app.run(function(editableOptions, editableThemes) {
editableOptions.theme = 'default';
editableThemes[default].cancelTpl = '';
editableThemes[default].submitTpl = '<img class="popoverSubmitBtn"
src="images/confirmationBtn.svg" ng-click="$form.$submit()">';
});
However I am having issues when trying to change editableThemes[default].inputTpl. It seems like changes to inputTpl are not being registered for some reason. What I would like is for the input box that shows in the popover to have a circular 'x' button to clear the current input WITHIN the input text field.
This was actually default behavior in the original x-editable (see here at Twitter typeahead.js demo). While there is an equivalent to use editableOptions.displayClearButton=true, this creates an entire button next to the input box, much like the confirmation button, which is not what I want.
My plan was to use a directive here that provides the 'clear' button and use editableThemes[default].inputTpl = '<input type="text" reset-directive>'; but again, seems like its broken. Even this open issue here leads me to believe it was never working as intended.
Has anyone had any luck with this or knows of any workarounds that may help in my situation?
ALSO- a bit unrelated but on the topic of styling, how do I move the position of where the popover shows up? Currently it's smack-dab in the middle of where my cursor is when I click the text to activate popover, but I would like it a bit higher and to the right.
Got it working. For those with similar issues:
Styling for the popover can be controlled through xeditable.css found in the bower_components directory after installation
While inputTpl isn't functioning the way I expected, I added the
custom directive to the input field using e-* (i.e. e-my-directive) with no issues.

Scroll down on the terms and condition Textbox and click on Agree selenium

I am working on Protractor tests. Recently my web page changed where the terms and conditions are inside a textbox. Button Submit works only when the user scrolls through the textbox and clicks on Agree button. I tried the following option to scroll down but it is not scrolling down. Any help is greatly appreciated.
var scrollbar = element(by.id('terms-conditions'));
var checkbox = element(by.id('checkbox'));
scrollbar.click()
browser.executeScript('arguments[0].scrollIntoView()', scrollbar.getWebElement());
browser.executeScript('window.scrollTo(0,670);')
checkbox.click();
I followed the below link too but no luck.
Protractor: Scroll down
The second js execute statement you are using contains Window.scrollTo which references an open window in a browser. and using it only scrolls the complete window but not the pop-ups that appear inside a browser window
Refer here for documentation on Window.scrollTo
Normally terms and conditions shows up in a pop-up or may be a div and hence Window.scrollTo doesn't work
there are two ways you can do it
SOLUTION 1: use Jquery scrollTop() to scroll inside a specific webElement
Step 1: Identify the exact div that holds your terms of Service scroll bar
Step 2: Refine your js statement by trying directly in Chrome console
$('.modal-body').scrollTop() -> This returns the current position of scroll
$('.modal-body').scrollTop(10000) -> This sets the value of top position
Step 3: Incorporate this in your protractor script
browser.executeScript('$('.modal-body').scrollTop(10000)');
You can professionalize this by passing the element & scroll amount as arguments. Refer here
SOLUTION 2; The best way I see to submit a pop-up is not to deal with interface but to deal with the 'form' element behind it. Similar to how we deal with file uploads.No fuss & effective
May be try something like this, by making button visible first and then submit form
browser.executeScript is an asynchronous call, so you will need to put it into the controlFlow so that it will complete before clicking the checkbox:
scrollbar.click();
browser.controlFlow().execute(function() {
browser.executeScript('arguments[0].scrollIntoView()', scrollbar.getWebElement());
browser.executeScript('window.scrollTo(0,670);');
});
checkbox.click();

Displaying Windows Forms inside unit test methods

I just discovered unit test projects in Visual Studio .NET and am using test methods to set up examples of global code I have developed.
Some global methods involve displaying reusable dialogs like a date-picker and input box. Trouble is, sometimes forms will display and sometimes they won't.
I thought it was related to modality, because I have a report preview form that can be shown modally or non-modally. When I show that non-modally, it does not display. When I show it modally, it does.
Trying my input box never works:
string input = "";
using (InputBox box = new InputBox(Title, Prompt, Default))
{
DialogResult result = box.ShowDialog();
input = box.txtInput.Text.Trim();
}
return input;
Execution stops at the "box.ShowDialog()" line, and at that point I can inspect box and see that its dimensions, location, and visibility are all properly configured -- yet I cannot see the form. I've got to cancel the test to stop everything.
I'd love to use a unit testing project to act as a playground and showcase of existing code, but it seems very limited if I can't display certain forms. I realize this is not really what unit testing is meant for, but I hoped I could build a fun little sandbox this way to help get my developers up to speed.
I finally had some consistent success (and lack thereof) based on a single form property: ShowInTaskbar.
When a form had that property set to true, such forms would NOT display from a unit test method. When that property is false, all forms display. So, here are the rules as far as I know them to make sure a form can display from a unit test:
The form should be created as a standard Windows Form item in the project.
The form should have its ShowInTaskbar property set to FALSE.
The form needs to be displayed modally (i.e. with ShowDialog()).
This has let me display and test all of my utility forms like date selectors and login screens.
I had the same issue. The dialog was blinking visible then disappearing. It was already TopMost, and I tried the other trick of setting it to visible then not visible before showdialog was called, but nothing worked.
Then I checked the other dialog that was working fine and it had ControlBox = true. I tried that, and it worked!
This is definitely applicable to the question.

WP7 - Is it possible to automatically launch the camera capture without a button press?

I'm using this code to grab barcodes from the camera:
http://blogs.msdn.com/b/stephe/archive/2011/11/07/wp7-real-time-video-scan-a-barcode-qr-code-in-your-app-using-zxing-lib.aspx
It works fine if it is called from a button press, but if you put it in page load nothing happens, I assume this is a security feature?
Is there any way around it?
Thanks
All must be Ok with Loaded event. Maybe you put code inside constructor instead...

Resources