Coded UI test is not running while setting the UIElementText in the Playback - wpf

I have recorded the coded UI test using the VS2015 Coded UI Test builder. based on my recording the following function is created for my test method,
public void RecordedMethod1()
{
#region Variable Declarations
WpfText uIItemText = this.UIMainWindowWindow.UIAddNewRowControlCustom.UIGridCellCustom.UIItemText;
WpfEdit uIItemEdit = this.UIMainWindowWindow.UIAddNewRowControlCustom.UIGridCellCustom.UIItemEdit;
WpfText uIItemText1 = this.UIMainWindowWindow.UIAddNewRowControlCustom.UIGridCellCustom1.UIItemText;
#endregion
// Double-Click label
Mouse.DoubleClick(uIItemText, new Point(73, 3));
//// Failed in the following line and the test is not running after that.
// Type 'aaa' in text box
uIItemEdit.Text = this.RecordedMethod1Params.UIItemEditText;
// Double-Click label
Mouse.DoubleClick(uIItemText1, new Point(79, 10));
// Type 'bbb' in text box
uIItemEdit.Text = this.RecordedMethod1Params.UIItemEditText1;
// Type '{Enter}' in text box
Keyboard.SendKeys(uIItemEdit, this.RecordedMethod1Params.UIItemEditSendKeys, ModifierKeys.None);
}
After reaching the line to set the recorded value to the uiEditItem.Text the test case is not running further cased the failure in the test case.
I have googled for the solution and have found a one that says, you need to rewrite the test cases with the Kebord.SendKeys instead of directly setting the value to the Text property of the EditItem.
By this way I have made my code changes at the line as follows and its working.
// Type 'aaa' in text box
//uIItemEdit.Text = this.RecordedMethod1Params.UIItemEditText;
// Replaced the above line with the SenKeys
Keyboard.SendKeys(this.RecordedMethod1Params.UIItemEditText);
Is that the only solution for this problem (Manullay rewrite the test methods by using the SendKeys method instead of directly assigning a value to the uiEditItem.Text property) ? If not, please provide the feasible solution for this.

Related

Selenium get text returning NULL

I'm adding some data through my automation script and once it is added, I need to verify it on screen.
However when I'm using below code to verify the text present on screen - get text method always returns NULL.
Here is the code which I'm using
String expectedOC = "9999";
String actualOC = driver.findElement(By.xpath("//*[#id='104429O']/div/div[1]/div[2]")).getText();
Assert.assertTrue(actualOC.contains(expectedOC));

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();

clear text field using DELETE or BACK SPACE key in webdriver

I am trying to clear a text field using this action:
emailField.sendKeys("gmail.com");
emailField.sendKeys(Keys.CONTROL,"a",Keys.DELETE);
In above code, the last line only selects the text, does not delete it, but if I separate the actions it works.
emailField.sendKeys(Keys.CONTROL,"a");
emailField.sendKeys(Keys.DELETE);
From the JavaDoc for WebElement.clear():
If this element is a text entry element, this will clear the value.
Has no effect on other elements. Text entry elements are INPUT and
TEXTAREA elements. Note that the events fired by this event may not be
as you'd expect. In particular, we don't fire any keyboard or mouse
events. If you want to ensure keyboard events are fired, consider
using something like sendKeys(CharSequence) with the backspace key. To
ensure you get a change event, consider following with a call to
sendKeys(CharSequence) with the tab key.
Most likely you simply need to call:
emailField.sendKeys("gmail.com");
emailField.clear();
But if you need the clearing to be done via the keyboard for some reason, use Keys.BACKSPACE.
keys.DELETE can not work to delete the input text,you should use keys.BACKSPACE.
emailField.sendKeys(Keys.BACKSPACE)
From the JavaDoc for Keys.chord
chord(java.lang.CharSequence... value)
Simulate pressing many keys at once in a "chord".
You should be able to use
emailField.sendKeys(Keys.chord(Keys.CONTROL,"a",Keys.DELETE));
Tested in chrome driver
WE.send_keys(' \b')
This will add space then delete it (backspace)
I use in javascript and it's working fine:
await textBox.sendKeys(value);
await textBox.sendKeys(Key.BACK_SPACE);
emailField.sendKeys(Keys.BACKSPACE)
doesn't worked for me .
I used 'Key' instead of 'Keys'
emailField.sendKeys(protractor.Key.BACKSPACE)
emailField.sendKeys(Keys.CONTROL + "a",Keys.DELETE);
In PHP:
if you use php-webdriver (https://github.com/php-webdriver/php-webdriver) you must:
use Facebook\WebDriver\WebDriverKeys AS Keys;
.
.
.
$this->driver->findElement(By::id('demo'))->sendKeys([Keys::BACKSPACE,'Any other text']);
Just adding another working C# example using the Google Chrome webdriver.
SendKeys only takes one parameter so created a string with the Crtl + A. This code sequence will select the current text in the field then delete the text.
Code example:
var crtlA = Keys.Control + "a";
driver.FindElement(By.XPath("//div[3]/div[1]/div[2]/div/div[2]/div[2]/div/div/div[1]/div/span/input")).SendKeys(crtlA); Wait(5000); // Select current text
driver.FindElement(By.XPath("//div[3]/div[1]/div[2]/div/div[2]/div[2]/div/div/div[1]/div/span/input")).SendKeys(Keys.Delete); Wait(5000); // Clear current text
driver.FindElement(By.XPath("//div[3]/div[1]/div[2]/div/div[2]/div[2]/div/div/div[1]/div/span/input")).SendKeys(newItemSku); Wait(5000); // Input SKU name
1. in WebdriverIO, i tried to edit the text by clear text (which contains special charactes like #, +, _) in text field by below following step. Eventhough it was not successful.
example: text=> abc+1234#gmail.com
step1:browser.clearElement(selector);
step2:browser.execute(function () {
document.querySelector(>>>Cssselector<<<).value="";
});
step3: browser.doubleClick(selector);
browser.keys("Delete");
step4: browser.click(selector);
browser.keys(['Meta',a]);
browser.keys('Meta');
browser.keys('Delete');
Note: below step is resolved this issue.
var count= browser.getAttribute(selector, value).length;
for (var i=0;i<count;i++)
{
if (browser.getAttribute(selector, value)=='')
break;
}
else
{
browser.doubleClick(selector);
browser.keys("Delete");
}
browser.pause(200);
// it will clear your text field easily.
Note:
You can add the new text now.

Intern test returns incorrect value for range input

I have a test that checks the value an HTML5 range input.
return this.remote
// etc.
.findById('range')
.getAttribute("value")
.then(function(val){
expect(parseInt(val)).to.equal(2);
});
The value is correct when I check its initial value, but if I change the value then check, it has not been updated. I found that the value doesn't update in the developer tools either. I tried using
.sleep(3000)
between changing the value and calling
.getAttribute('value')
but that didnt' seem to be the issue.
In this JSfiddle, inspecting the range element with your browser's developer tools will show the title change, but the value does not (even though the value is correctly changed in the textbox). So this may be an issue with the webdriver, but I'd like to know if anyone has run into this issue.
Is this related to the test's failure to get the updated value? Is there another method I can use to read values(attributes)?
Edit:
It seems like the browser's onchange/oninput event is not triggering properly (similar problems: WebDriver: Change event not firing and Why does the jquery change event not trigger when I set the value of a select using val()?), and the webdriver is possibly not able to, either. Do I have to add Jquery as a define for my test, even though I only need to use trigger() ? Or is there another solution?
Edit2: I've added a better example of how I'm using the range input in this new JSfiddle. I added plus/minus buttons, which fail to trigger the change event that should update the value attribute of the range input, (and which fails to enter the value into the textbox).
You could fire the change event manually in your test. I was able to get the 'textValue' input in your JSFiddle to update that way and I imagine it might work similarly in your test.
rangeBar = document.querySelector('#range');
function myFire(element, eventType) {
var myEvent = document.createEvent('UIEvent');
myEvent.initEvent(
eventType, // event type
true, // can bubble?
true // cancelable?
);
element.dispatchEvent(myEvent);
}
myFire(rangeBar, 'change');
This comes up often enough that I have a helper in my base test class (Java)
public enum SeleniumEvent
{blur,change,mousedown,mouseup,click,reset,select,submit,abort,error,load,mouseout,mouseover,unload,keyup,focus}
public void fireEvent(WebElement el, SeleniumEvent event)
{
((JavascriptExecutor) getDriver()).executeScript(""+
"var element = arguments[0];" +
"var eventType = arguments[1];" +
"var myEvent = document.createEvent('UIEvent');\n" +
"myEvent.initEvent(\n" +
" eventType, // event type\n" +
" true, // can bubble?\n" +
" true // cancelable?\n" +
");\n" +
"element.dispatchEvent(myEvent);", el, event.toString());
}
Another thought. getAttribute("value") might not be getting what you think it does. In JavaScript, document.querySelector('#range').getAttribute('value') always returns the hard-coded value attribute (i.e. the default or initial value), not the input's current value.
document.querySelector('#range').value returns the current value.

codenameone how to reference field contents in addArgument command

i have a form that contains several text fields and a 'register' button.
when the register button is pressed i want to send the contents of the fields to a web svc.
I have successfully connected to my webservice and passed hardcoded post variables.
I am having trouble getting the proper syntax to addArgument to pass the contents of the text fields.
For example, if I have a form (Register) and on that form i have a text field (txtFirstName),
what is the syntax to add the contents of the txtFirstName field to the addArgument command?
My code follows:
#Override
protected void onRegister_BtnRegisterAction(Component c, ActionEvent event) {
// register new user
ConnectionRequest r = new ConnectionRequest();
r.setUrl("http://localhost/ihsnj/websvc.php");
r.setPost(true);
r.addArgument("R", "Y"); // R = register
// this is the line generating the error <cannot find symbol>
r.addArgument("FirstName",txtFirstName.getText());
InfiniteProgress prog = new InfiniteProgress();
Dialog dlg = prog.showInifiniteBlocking();
r.setDisposeOnCompletion(dlg);
NetworkManager.getInstance().addToQueueAndWait(r);
}
Your problem isn't related to ConnectionRequest. You need to use find methods not fields since components are only constructed when the form is actually showing (to preserve RAM).
Use findTxtFirstName(c).getText() as the second argument e.g.:
req.addArgument("first_name", findTxtFirstName(c).getText());

Resources