CUITe/Coded UI : mouse.Click position wrong (Screen resolutions) - coded-ui-tests

I'm using CUITe to automate the testing of a UI piece (captured as a Page Object model).
I have a class that captures the buttons in my UI, like so:
class Navigators : CUITe_BrowserWindow
{
public new string sWindowTitle = "Window";
public CUITe_HtmlInputButton next = new CUITe_HtmlInputButton("Id=Content_btnNext");
// Other such buttons
//And a method to click any button
public void ClickButton(string id)
{
CUITe_BrowserWindow.GetBrowserWindow<Navigators>().Get<CUITe_HtmlInputButton>(string.Concat("Id=", id)).Click();
}
}
And the test I'm trying to automate is this, the click of a button:
CUITe_BrowserWindow.Launch<Navigators>("url");
CUITe_BrowserWindow.GetBrowserWindow<Navigators>().ClickButton("Content_btnNext");
My problem is this:
When I project my screen to a secondary monitor and extend it, the 'Next' button is clicked perfectly. However, on my system, the mouse passes over the button to another position and the click doesn't happen.
I have tried refreshing the CodedUI cache (by setting SearchConfiguration to Always), but that hasn't worked. Also, SetFocus on the control works correctly, whereas DrawHighlight shows the wrong position.
Any help would be greatly appreciated.
EDIT
When I changed my screen's resolution to 1440x900 (which is that of the secondary monitor's), the click happened.
I would be glad if someone could provide links that show how to handle screens of different resolutions in Coded UI

This is how I click controls on Win 8.1 store app which may or maynot be of help to you:
Mouse.Click(new Microsoft.VisualStudio.TestTools.UITest.Input.Point(uiControl.Left + (uiControl.Width / 2), uiControl.Top + (uiControl.Height / 2)));

Below is how I've been doing it in my CUITe scripts & it works fine at 1920x1080 on my larger monitor & at 1280x1024 on my laptop screen.
Given your OR definition above.
using Navigators.ObjectRepository; //guessing the name here
var pgNavigator = new Navigators();
//whatever else you do before clicking on next
Navigators.next.Click();

Related

Create a generic popup panel

I have added a Global Button with the following code.
public override void Initialize()
{
if (!String.IsNullOrEmpty(Base.PrimaryView))
{
Type primaryViewItemType = Base.Views[Base.PrimaryView].Cache.GetItemType();
PXAction action = PXNamedAction.AddAction(Base, primaryViewItemType, "SubmitTicket", "Submit Ticket", TestClick);
}
}
public IEnumerable TestClick(PXAdapter adapter)
{
throw new PXException("Button clicked from graph" + Base.GetType().Name);
}
And it renders the button like this in each of the pages.
Now, I would like to display a popup panel, on button's click. I know I can create a popup panel on screen section. But, is there some way that I can have a general popup panel created in one place and can be displayed on each of the pages on the button's click?
Thank you.
As #HB_ACUMATICA mentioned there is no good easy way.
Providing another alternative to his post, you can create a graph and use it as a reusable popup by calling:
throw new PXPopupRedirectException(graph, string.Empty, true)
One thing I ran into was a sizing issue on the popup...
Changing the height/width when calling another graph as an in-page popup using PXPopupRedirectException
If you do copy and paste the PXSmartPanel you can create re-usable business logic by implementing the reusable business logic pattern found in this help as a starting point:
Reusing Business Logic
If I understand correctly you want to share the same PXSmartPanel control in different pages without having to copy/paste it in every screen.
In Acumatica Framework this is achieve by custom container controls like 'PXUploadDialog' which derives functionality from other controls like 'PXSmartPanel'. This is the control that is used when you attach files in all screen.
Unfortunately there seems to be no documentation on how to achieve this.
The closest I found is this SO question which is essentially unanswered:
Create custom User Control for Acumatica
Considering this, you may want to copy/paste the same smart panel in all screen.
To ease copying you can use the 'Edit ASPX' feature, make sure you backup the project before.
Edit ASPX to get to the code:
Copy paste your smart panel in the page and click 'GENERATE CUSTOMIZATION SCRIPT' to package the changes in the project:

Messed up BackStage with Universal App (Windows Phone 8.1)

I'm having problems with the Navigation in my windows phone 8.1 part of a universal app I created. I'll try to explain.
I have the following (sorry my spacing/tabbing appears to be messed up below!)
1) Home Page (click on a + on the app bar and it navigates to 2)
->> 2) New Item Page (click on the image preview and it navigates to 3)
->> 3) Capture Page (tap on a button)
->> From Cam button (not implemented)
->> From Photo button
->> 4) Select from album or Take a photo
[- -----Tap Accept and it goes back to New Item (2) and
display the photo as a preview.
But when I click on the back key, it should technically bring me back
to my Home Page(1) but instead it does the following:
First back press: Goes back to Capture Page (3)
Second back press: Goes back to New Item Page (2)
Third back press: Goes back to Home (1)
I'm using the WP File Picker to select a photo, but whether I select
one or press the back key, it goes to my OnActivated event located in
my App.xaml.cs
In the async Method (WPPickedFile) which is called when selecting a
photo or pressing the back key, it checks if args.Files.Count has
returned a photo or not and I've added the following lines of code to
see if it would make a difference:
if (((Frame)Window.Current.Content).BackStackDepth > 2)
((Frame)Window.Current.Content).BackStack.Remove(((Frame)
Window.Current.Content).BackStack[2]);
if (((Frame)Window.Current.Content).BackStackDepth > 1)
((Frame)Window.Current.Content).BackStack.Remove(((Frame)
Window.Current.Content).BackStack[1]);
but it doesn't make one bit of difference. If I press the back key
instead of selecting a photo, my BackStageDepth is 2 and it
contains the Home Page (1) and New Item Page (2). If I select a photo,
it contains these 2 and it also contains the Capture Page (3).
But here is the weird behaviour I don't get. Assume that I press the back
key and did not select a photo. My BackStageDepth is 2 and contains only
the Home Page (1) and the New Item Page (2) so when I get the the lines
described above, it skips the one with > 2 and it removes the New Item
Page (2). When I check it is removed and my BackStageDepth has dropped to 1.
This is not what I want to achieve but I'm trying to understand what's
going on. Anyway, when I continue running the code, I get my New Item Page (2)
displayed and my preview image remains empty since I pressed the back key
on the WP File Picker.
Now the strange is that when I press the back key once again, I put a
break point on the HardwareButtons_BackPressed which is located in
the NavigationHelper but if I check (Frame)
Window.Current.Content).BackStackDepth, it's now telling me that it 2
rather than 1. If I check it, (Frame)Window.Current.Content).BackStack[0]
is still my Home Page (1) but (Frame)Window.Current.Content).BackStack[1]
is now set to the Capture Page (3) which wasn't listed when I checked it
in the method WPPickedFile.
Why is that? I'm totally confused but I can't figure out what I'm doing wrong but it's obviously related to the fact that I'm leaving the app when the WP File Picker is launched as if I don't i.e. go from Home Page(1) to
Capture Page (3) without clicking on the button to launch the WP File Picker,
the navigation works as expected.
Any suggestions would be appreciated
Thanks.
PS: Sorry for the poor formatting but I couldn't fix it!
My backstack wasn't actually messed up. I found out the hard way that windows phone 8.1 could have multiple frames and I totally
In regards to navigating back to the previous page before the one that's calling the FilePicker, I finally figured out a way, which appears to be clean and doesn't call the nagivation and therefore the page to the backstack
#if WINDOWS_PHONE_APP
protected async override void OnActivated(IActivatedEventArgs e)
{
base.OnActivated(e);
continuationManager = new ContinuationManager();
Frame rootFrame = CreateRootFrame();
await RestoreStatusAsync(e.PreviousExecutionState);
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(LocationsPage));
}
var continuationEventArgs = e as IContinuationActivatedEventArgs;
if (continuationEventArgs != null)
{
if (rootFrame.Content is CaptureTypePage)
{
if (rootFrame.CanGoBack)
rootFrame.GoBack();
}
// Call ContinuationManager to handle continuation activation
continuationManager.Continue(continuationEventArgs, rootFrame);
}
Window.Current.Activate();
}
#endif
The important part is:
if (rootFrame.Content is CaptureTypePage)
{
if (rootFrame.CanGoBack)
rootFrame.GoBack();
}
continuationManager.Continue(continuationEventArgs, rootFrame);
By calling the GoBack, it removes the CaptureTypePage and sets the CurrentSourcePageType of the rootFrame to the 'New Item Page' where the preview window is.
I then implemented the interface IFileOpenPickerContinuable on the 'New Item Page' and this is called by the continuationManager.Continue function i.e.
case ActivationKind.PickSaveFileContinuation:
var fileSavePickerPage = rootFrame.Content as IFileSavePickerContinuable;
if (fileSavePickerPage != null)
{
fileSavePickerPage.ContinueFileSavePicker(args as
FileSavePickerContinuationEventArgs);
}
break;
I hope this helps someone else and won't waste time the way I did! If you have a cleaner way of doing this, please add to this post. I'd love to know.
Thanks.

How to hide the application bar in a Windows Phone 8.1 (WinJS) app?

I have a single AppBar declared in default.html for use throughout my application.
On some of the pages I need to show the App Bar and in some of the I need to hide the AppBar.
So far, my efforts to find the methods to hide and show the AppBar have met a dead end.
The documentation on MSDN says:
AppBar.hide method :
Hides the app bar on Windows and the secondary command menu on Windows Phone.
So, that method only hides the AppBar for Windows and not for a Windows Phone project.
I have also tried giving display:none as a CSS style, to no effect.
Any help will be appreciated :)
AppBar.Hide hides the secondary command bar on Windows Phone, not the main AppBar. If you want the entire AppBar to go away then this isn't the right property.
The easiest way is to declare the AppBar on pages that you want to show it and to leave it out on pages that you don't want it, but you should be able to hide it by disabling the AppBar on pages that you don't want it on.
I just modified the appbar-commands.js file in the HTML AppBar control sample as follows and the appbar hides and shows as I click the hide and show buttons:
// These functions are used by the scenario to show and hide elements
function doShowItems() {
document.getElementById('commandsAppBar').winControl.disabled = false;
//document.getElementById('commandsAppBar').winControl.showCommands([cmdFavorite, cmdCamera]);
document.getElementById('scenarioShowButtons').disabled = true;
document.getElementById('scenarioHideButtons').disabled = false;
}
function doHideItems() {
document.getElementById('commandsAppBar').winControl.disabled = true;
//document.getElementById('commandsAppBar').winControl.hideCommands([cmdFavorite, cmdCamera]);
document.getElementById('scenarioHideButtons').disabled = true;
document.getElementById('scenarioShowButtons').disabled = false;
}
I also confirmed with the single-page navigation model navigating between two pages. If you aren't seeing the appbar hide and show when disabled and enabled then make sure you are calling the code to disable / enable the appbar. The PageControl's ready function may not be called when returning to a cached page.
You'll have to do it with C#, You can simply just type.. (If your appbar is called ApplicationBar)
ApplicationBar.Visibility = Visibility.Collapsed;
This will instantly hide the AppBar! If you want your HTML Page to perform this action, it will be much complicated.
Cheers
I think you can try below step in your code.
Add a event listener for appbar beforeshow
In code of before show Check a condition with specific page name
Like : if (WinJS.Navigation.location.match("test.html"))
According to you condition you can Disable your appbar.
All the best..!!

Hide Controls At Design-Time [duplicate]

I need to handle multiple panels, containing variuous data masks. Each panel shall be visible using a TreeView control.
At this time, I handle the panels visibility manually, by making the selected one visible and bring it on top.
Actually this is not much confortable, especially in the UI designer, since when I add a brand new panel I have to resize every panel and then design it...
A good solution would be using a TabControl, and each panel is contained in a TabPage. But I cannot find any way to hide the TabControl buttons, since I already have a TreeView for selecting items.
Another solution would be an ipotethic "StackPanelControl", where the Panels are arranged using a stack, but I couldn't find it anywhere.
What's the best solution to handle this kind of UI?
You need a wee bit of Win32 API magic. The tab control sends the TCM_ADJUSTRECT message to allow the app to adjust the tab size. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form.
You'll get the tabs at design time so you can easily switch between pages. The tabs are hidden at runtime, use the SelectedIndex or SelectedTab property to switch between "views".
using System;
using System.Windows.Forms;
class StackPanel : TabControl {
protected override void WndProc(ref Message m) {
// Hide tabs by trapping the TCM_ADJUSTRECT message
if (m.Msg == 0x1328 && !DesignMode) m.Result = (IntPtr)1;
else base.WndProc(ref m);
}
}
A good solution would be using a TabControl, and each panel is contained in a TabPage.
But I cannot find any way to hide the TabControl buttons, since I already have a
TreeView for selecting items.
For the above,
You need to set the following properties of TabControl.
tabControl.Multiline = true;
tabControl.Appearance = TabAppearance.Buttons;
tabControl.ItemSize = new System.Drawing.Size(0, 1);
tabControl.SizeMode = TabSizeMode.Fixed;
tabControl.TabStop = false;

How to set background image for Dialog?

I am trying to do this:
public class DialogMenuHawaii extends Dialog {
Style s = UiFactory.getBaseStyle();
s.setBgTransparency(0);
s.setBgImage( <my image >);
this.setUnselectedStyle(s);
}
but it doesn't work.
First, I suggest you use a theme. We constantly change small implementation details e.g. customizations like the one you are doing will not be portable between LWUIT 1.4 and 1.5. There is no reason whatsoever not to use a theme for something like this.
If you are interested in the pain and suffering of manually coding view logic into your application you can use several methods such as getDialogComponent() to get the style from them and manipulate that. Dialog is a complex beast due to the fact that its really a form padded away from the edges.
Open your '.res' file in resource Editor and select your preferred theme,
Under 'Unselected' tab open the DialogContentPane style, if you don't have one create it look at the end of this answer on HOW TO DO IT?, and set the background image to the image you need to show as Dialog bg
Under 'Unselected' tab open the DialogBody style, if you don't have one create it look at the end of this answer on HOW TO DO IT?, and set the background transparency as '0' and also make sure the background image type is NONE
NOTE: The above code will reflect for all the Dialogs in your application. If you want a particular dialog with background image than derive new styles from these default styles, and follow the above steps to apply it to your DialogMenuHawaii or any runtime Dialogs.
HOW TO: I would recommend you to go through the Shai's blog posts LWUIT Resource Editor Tutorial Part 1 till part 10. To better understand the Resouce Editor its features and capabilities.
:
:
:
PS: Programmatic-ally i haven't been able to achieve it using TextArea which is the case for default Dialog's. If you replace the dialog body component with Label if works fine, the code sample is given below. I haven't delved much into why is it so ? maybe will do it in my free time. Hence i have proposed a working alternative solution which is scripted above using Resource Editor and below using the code
class MyDialog extends Dialog {
public void show() {
Container octnPane = this.getDialogComponent();
octnPane.getUnselectedStyle().setBgTransparency(0, false);
Container ctnPane = (Container)((BorderLayout)octnPane.getLayout()).getCenter();
ctnPane.getUnselectedStyle().setBackgroundType(Style.BACKGROUND_IMAGE_SCALED, false);
ctnPane.getUnselectedStyle().setBgImage(myImage, false);
Label t = new Label("Dialog");
t.setUIID("DialogBody");
t.getUnselectedStyle().setBgTransparency(0, false);
ctnPane.addComponent(t);
super.show();
}
}
This is for Dialog background.
Dialog dialog = new Dialog();
dialog.getDialogStyle().setBgImage(Image.createImage("/image/image.png"));
If you want to set transparency of Dialog with image.
dialog.getStyle().setBgImage(Image.createImage("/image/image.png");

Resources