Not able to enter text in a edit field inside a modal/dialog using Teststack/White - white-framework

I am trying to enter text in a edit field in a modal window. I get an error "Failed to get (ControlType=edit or ControlType=document),AutomationId=1118,ClassName=Edit"
The following is my code.
var window = app.GetWindow("Toolkit Version");
Window AuthWindow = null;
AuthWindow = window.ModalWindow("Please Authenticate");
TextBox userNameField = AuthWindow.Get<TextBox>(SearchCriteria.ByClassName("Edit").AndAutomationId("1118"));
userNameField.Text = "Administrator";
From Inspect
Error details -
TestStack.White.AutomationException: 'Failed to get (ControlType=edit or ControlType=document),AutomationId=1118,ClassName=Edit'
Any suggestions or workarounds?
Thanks!

Off the top of my head:
Perhaps your SearchCriteria are too restrictive? Try:
TextBox userNameField = AuthWindow.Get<TextBox>(SearchCriteria.ByAutomationId("1118"));
or even
TextBox userNameField = AuthWindow.Get(SearchCriteria.ByAutomationId("1118")) as TextBox;
It might not be very elegant, but it looks like your window is small and has few controls. Why not picking them this way?
TextBox userNameField = AuthWindow.GetMultiple(SearchCriteria.ByControlType(System.Windows.Automation.ControlType.Edit)[0]
I supposed your textbox is at position 0 but of course you can change that.

Related

SearchCommand in Toolbar no longer showing correctly

I noticed that after an update of CN1 some time ago, the Search doesn't display correctly in the toolbar anymore.
When you click the search icon, the toolbar will change and the icons will show, but the textfield for entering the search text (and which normally shows a hint) doesn't show up even if you start to type. It is only shown when you provoke a refresh of the screen, e.g. click in the search field or on the form.
Form hi18 = new Form("FormTitle");
hi18.setLayout(BoxLayout.y());
Container cont18 = hi18.getContentPane();
hi18.getToolbar().addSearchCommand((e) -> {
String text = (String) e.getSource();
for (Component c : hi18.getContentPane()) {
c.setHidden(c instanceof Label && ((Label) c).getText().indexOf(text) < 0);
}
hi18.getComponentForm().animateLayout(150);
});
for (int i = 0; i < 20; i++) {
Label l = new Label("Label " + i);
cont18.add(l);
}
hi18.show();
Looks fine for me considering you created a title with no text in it for the test case so it might be shrinking on you. I suggest adding text to the title and making sure your styling doesn't impact this too much. I would also suggest adding screenshots when discussing something that doesn't look right so we're all on the same page.
These were generated with your code on the current trunk:

Concurrency Error WinForms Binding Source Navigator

I have a form with customer info that needs to be processed one transaction per page. I'm using the binding navigator to manage my pagination.
It works in all but some cases. In the cases where it doesn't work, I have to open a different window to look up information and return it to the main form. Here is the code for that:
// save current work
updateDataTable();
// Open a window and get new customer info
// CurrentCustomer is returned from the opened window
using (SqlConnection cx = new SqlConnection(GetConnectionString()))
{
DataRowView dataRow = (DataRowView)procBindingSource.Current;
dataRow.BeginEdit();
dataRow["CUSTOMER"] = CurrentCustomer;
dataRow.EndEdit();
updateDataItems();
SqlCommand cmd = new SqlCommand(
#" select acct_no from cust_processing where id = #id ", cx);
cmd.Parameters.AddWithValue("#id", (int)dataRow["ID"]);
cx.Open();
var results = cmd.ExecuteScalar();
if (results != null)
{
dataRow.BeginEdit();
dataRow["ACCT_NO"] = results.ToString();
dataRow.EndEdit();
updateDataItems(); <------ CONCURRENCY ERROR
}
}
The error I am getting is a concurrency error. I think that I have more than one version of the row possibly ? I thought I was making sure that I was on the most recent version of the row by calling updateDataTable(). I am the only user so I know I am creating the problem myself.
Here is my update method which is called when I change pages or save and exit or want to write the commit the data:
void updateDataItems()
{
this.procBindingSource.EndEdit();
this.procTableAdapter.Update(xyzDataSet);
xyzDataSet.AcceptChanges();
}
I have tried executing updateDataItems from various places such as after I assign dataRow["ACCT_NO"] = results.ToString() or before and after assigning that.
I'm pretty much down to guess and check so any thoughts, help and advice will be appreciated and +1.
Okay -- so the problem was that I was trying to update the current row from the program and also using the binding navigator. They were not working together properly.
The solution was to add a text box to the form in the forms designer and set visible = false and bind it to ACCT_NO. Once I got the results from my other form, I just needed to set the .text property of the ACCT_NO textbox to the new value and the binding navigator managed all my updates for me correctly.
txtAcct_No.text = results.ToString();

Codenameone: Alert Dialog message

we want dialog message in this format and look and fill
Can you please let me know how to resolve it. My application needs to be supported on all platforms (Android, iOS, Windows) and I don't want to write native code for all platforms separately.
Actually customizing the look is easier in Codename One as everything is written in Java you can customize literally everything about the look of anything.
For simplicity sake I used code rather than styles which would be better, you can customize the Dialog UIID and other UIID's in the theme designer to get more flexibility and have this easier. However, this would require many screenshots and explanations so I did the customization in code:
Form f = new Form("Test");
Button b = new Button("Show Dialog");
f.add(b);
b.addActionListener(e -> {
Dialog dlg = new Dialog("Authentication");
Style dlgStyle = dlg.getDialogStyle();
dlgStyle.setBorder(Border.createEmpty());
dlgStyle.setBgTransparency(255);
dlgStyle.setBgColor(0xffffff);
Label title = dlg.getTitleComponent();
title.setIcon(finalDuke.scaledHeight(title.getPreferredH()));
title.getUnselectedStyle().setFgColor(0xff);
title.getUnselectedStyle().setAlignment(Component.LEFT);
dlg.setLayout(BoxLayout.y());
Label blueLabel = new Label();
blueLabel.setShowEvenIfBlank(true);
blueLabel.getUnselectedStyle().setBgColor(0xff);
blueLabel.getUnselectedStyle().setPadding(1, 1, 1, 1);
blueLabel.getUnselectedStyle().setPaddingUnit(Style.UNIT_TYPE_PIXELS);
dlg.add(blueLabel);
TextArea ta = new TextArea("This is the text you want to appear in the dialog, this might line break if the text is too long...");
ta.setEditable(false);
ta.setUIID("DialogBody");
ta.getAllStyles().setFgColor(0);
dlg.add(ta);
Label grayLabel = new Label();
grayLabel.setShowEvenIfBlank(true);
grayLabel.getUnselectedStyle().setBgColor(0xcccccc);
grayLabel.getUnselectedStyle().setPadding(1, 1, 1, 1);
grayLabel.getUnselectedStyle().setPaddingUnit(Style.UNIT_TYPE_PIXELS);
dlg.add(grayLabel);
Button ok = new Button(new Command("OK"));
ok.getAllStyles().setBorder(Border.createEmpty());
ok.getAllStyles().setFgColor(0);
dlg.add(ok);
dlg.showDialog();
});
f.show();
I would recommend doing the dialog customization in the theme designer and using a 9-piece image border which is better looking.

How to open Color and Font Dialog box using WPF?

I want to show the color and font dialog box in WPF .net 4.5, how to can I do?
Please help me anybody.
Thnx in Advanced!
The best out of the box solution is using FontDialog form System.Windows.Forms assembly, but you will have to convert it's output to apply it to WPF elements.
FontDialog fd = new FontDialog();
var result = fd.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
Debug.WriteLine(fd.Font);
tbFonttest.FontFamily = new FontFamily(fd.Font.Name);
tbFonttest.FontSize = fd.Font.Size * 96.0 / 72.0;
tbFonttest.FontWeight = fd.Font.Bold ? FontWeights.Bold : FontWeights.Regular;
tbFonttest.FontStyle = fd.Font.Italic ? FontStyles.Italic : FontStyles.Normal;
TextDecorationCollection tdc = new TextDecorationCollection();
if (fd.Font.Underline) tdc.Add(TextDecorations.Underline);
if (fd.Font.Strikeout) tdc.Add(TextDecorations.Strikethrough);
tbFonttest.TextDecorations = tdc;
}
Notice that winforms dialog does not support many of WPF font properties like extra bold fonts.
Color dialog is much easier:
ColorDialog cd = new ColorDialog();
var result = cd.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
tbFonttest.Foreground = new SolidColorBrush(Color.FromArgb(cd.Color.A, cd.Color.R, cd.Color.G, cd.Color.B));
}
It does not support alpha though.
You can use classes from System.Windows.Forms, there is nothing wrong with using them. You'll probably need to convert values to WPF-specific though.
Alternatively, you can implement your own dialogs or use third-party controls, see Free font and color chooser for WPF?.

Best way to show huge text in WPF?

I need to show a really huge amount of text data in WPF code. First i tried to use TextBox (and of course it was too slow in rendering). Now i'm using FlowDocument--and its awesome--but recently i have had another request: text shouldnt be hyphenated. Supposedly it is not (document.IsHyphenationEnabled = false) but i still don't see my precious horizontal scroll bar. if i magnify scale text is ... hyphenated.
public string TextToShow
{
set
{
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add(value);
FlowDocument document = new FlowDocument(paragraph);
document.IsHyphenationEnabled = false;
flowReader.Document = document;
flowReader.IsScrollViewEnabled = true;
flowReader.ViewingMode = FlowDocumentReaderViewingMode.Scroll;
flowReader.IsPrintEnabled = true;
flowReader.IsPageViewEnabled = false;
flowReader.IsTwoPageViewEnabled = false;
}
}
That's how i create FlowDocument - and here comes part of my WPF control:
<FlowDocumentReader Name="flowReader" Margin="2 2 2 2" Grid.Row="0" />
Nothing criminal =))
I'd like to know how to tame this beast - googled nothing helpful. Or you have some alternative way to show megabytes of text, or textbox have some virtualization features which i need just to enable. Anyway i'll be happy to hear your response!
It's really wrapping not hyphenation. And one can overcome this by setting FlowDocument.PageWidth to reasonable value, the only question was how to determine this value.
Omer suggested this recipe msdn.itags.org/visual-studio/36912/ but i dont like using TextBlock as an measuring instrument for text. Much better way:
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add(value);
FormattedText text = new FormattedText(value, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(paragraph.FontFamily, paragraph.FontStyle, paragraph.FontWeight, paragraph.FontStretch), paragraph.FontSize, Brushes.Black );
FlowDocument document = new FlowDocument(paragraph);
document.PageWidth = text.Width*1.5;
document.IsHyphenationEnabled = false;
Omer - thanks for the direction.

Resources