I am trying to collaborate using multiple text boxes. For example, when textbox1 get changed in one Chrome browser window, textbox1 in another Chrome browser window must also get changed. When textbox2 get changed in one Chrome browser window, textbox2 in another Chrome browser window must also get changed. I have modified the existing code provided at https://developers.google.com/drive/realtime/realtime-quickstart
Here is my changed code...
Index.html
<!-- Text areas that will be used as our collaborative controls. -->
<input id="editor1" style="width:400px" placeholder="Type some text here..." autofocus><br />
<input id="editor2" style="width:400px" placeholder="Type some text here...">
function initializeModel(model) {
var string1 = model.createString('Hello Realtime World1!');
model.getRoot().set('text', string1);
var string2 = model.createString('Hello Realtime World2!');
model.getRoot().set('text', string2);
}
function onFileLoaded(doc) {
var string1 = doc.getModel().getRoot().get('text');
var string2 = doc.getModel().getRoot().get('text');
// Keeping one box updated with a String binder.
var textArea1 = document.getElementById('editor1');
gapi.drive.realtime.databinding.bindString(string1, textArea1);
var textArea2 = document.getElementById('editor2');
gapi.drive.realtime.databinding.bindString(string2, textArea2);
....
When I tried to run this application and change the textbox1, textbox2 also get changed and in the other windows, both the textboxes get changed with the same text.
Please advise...thanks.
In initializeModel you are creating two collaborativeStrings, but assigning them both to the same key in the root "text".
Later on you are getting the same string "text" out of the root for both string1 and string2:
var string1 = doc.getModel().getRoot().get('text');
var string2 = doc.getModel().getRoot().get('text');
You need to change one of those 'text' in both places to something else.
Related
Here're video examples of what's happening:
Without sanitizing,
https://i.lithi.io/6GLS.mp4
With Sanitizing
https://i.lithi.io/TVIu.mp4
When clicked, this is supposed to make the text above, render the full text.
To do this, I have created a function
$scope.loadMore = function($event)
{
var element = $($event.currentTarget);
//console.log(element.data('text'));
var text = $scope.toHtml(element.data('text'));//$compile(element.data('text'));
//$sce.trustAsHtml(element.data('text'))
console.log(text);
if (element.parent().find('#text_data').length) {
element.parent().find('#text_data').html(text);
} else {
/*element.parent().find('#text_data').html(
element.data('text').length > 100 ?
element.data('text').substring(0, 100)
:
element.data('text')
);*/
}
}
I'm calling this function with ng-click. Basically it gets the parent, and then selects the element with the text inside.
The button has a Data Attribution with the full length text (not limited to 100 chars).
When I sanitize it inputs blank text? Whereas if I don't sanitize, it inputs the text.
I don't know if it's the right way to actually do it, but I just replaced the
tag with \n in my PHP, now it doesn't render them. Since YouTube doesn't support other HTML, it should be fine.
This is because your HTML is encoded. You have to decode it like this before displaying.
//angular hack to html decode
let decoded = angular.element('<div />').html(data).text()
$scope.decodedData = $sce.trustAsHtml(decoded);
There is nothing like $scope.toHtml(data)
Fiddle: https://jsfiddle.net/codeandcloud/54mzkjqe/
I am really stuck in testing an extJS web based application which contains many drop down combo boxes. and each box have the same class name and ids are dynamically changing each time the page gets loaded.
The combo boxes is not a typical drop down box. It contains a text box, followed by drop down button image and then clicking on that drop down button providese all the options in the drop down box. I want to select a particular element from the drop down box .
When inspect the drop down button element using firepath, its html code is
<div id="ext-gen1103" class="x-trigger-index-0 x-form-trigger x-form-arrow-trigger x-form-trigger-first" role="button"/>
similarly if i inpsect the drop down text box (whose id alone is constant and does not change)the html code is
<input id="NSClientCombo-inputEl" class="x-form-field x-form-text x-form-focus x-field-form-focus x-field-default-form-focus" type="text" placeholder="Select One" name="NSClientCombo" autocomplete="off" aria-invalid="false" data-errorqtip="" style="width: 100%; height: 28px;"/>
and if i inspect any of the drop down elements the html code for that is
<div id="boundlist-1048-listEl" class="x-boundlist-list-ct x-unselectable" style="overflow: auto; height: 187px;">
<ul class="x-list-plain">
<li class="x-boundlist-item" unselectable="on" role="option">****HELP NG****</li>
<li class="x-boundlist-item" unselectable="on" role="option">ABC Inc.</li>
I want to choose "HELP NG" or ""ABC Inc"" from drop down box. But i am really struck how to integrate and how to write selenium webdriver code to choose an element from drop down box since the drop down button contains only id and class (id keeps changing and class name for all the other drop down buttons are same). Have anyone crossed across such scenerios and please help me in sorting out this issue since this is taking away the time totally.:(
You need to use Ext.getCmp() function to retrieve a webElement of this combo.
see the code below.
This code will return the web Element
public static IWebElement ExtJsGetWebElementById(this IWebDriver driver, string id)
{
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
var script = "return Ext.getCmp('" + id + "').el.dom";
var Element = js.ExecuteScript(script) as IWebElement;
return Element;
}
The next function will be used to open the combo box and set a particular value to it using keyboard shortcuts.
public static void ExtJsSetComboValueWithKeyBoard(this IWebDriver driver, string comboId, string valueToSet)
{
var element = driver.ExtJsGetWebElementById(comboId);
element.SendKeys(Keys.Down);
Thread.Sleep(3000);
element.SendKeys(valueToSet);
Thread.Sleep(3000);
element.SendKeys(Keys.Enter);
Thread.Sleep(3000);
}
to Use the above method, use it like this in your test case.
_webDriver.ExtJsSetComboValueWithKeyBoard("NSClientCombo","ABC Inc.");
I am working on a markdown editor.
<textarea class="wnd-content-textarea"
name="" id="" cols="30" rows="10"
ng-model="content"
ng-change="">
</textarea>
I use a jquery plugin to update the a model that is binded on textarea element:
scope.execEditorCmd = function (cmd) {
// List of commands:
// 'cmd-bold',
// 'cmd-italic',
// 'cmd-quote',
// 'cmd-unorder-list',
// 'cmd-order-list'
/**
* Get selected text in textarea tag.
* textrange() is dependent on jquery-textrange plugin
* #type {Object}
* e.g.: {position: 4, start: 4, end: 8, length: 4, text: "reqw"}
*/
var selectedTextObj = $textAreaElement.textrange('get');
// Execute the string replace command using structure defined before
var boldedText = selectedTextObj.text
.replace( markdownCmd[cmd].search , markdownCmd[cmd].replace);
// Actually replace the orginal text with executed string in textarea.
// $timeout();
$textAreaElement.textrange('replace', boldedText);
// Not sure if it is the right way, but I have to do it to update model.
scope.content = $textAreaElement.val();
};
The jquery plguin is here:
The text on in the textarea changed in browser, but the model actually still remains the same. I checked it by {{}} outputing in in browser and log it in console.
At this moment, if I type a space in textarea, then all the changes that this plugin had done will reflected in model.
I tried scope.$apply, which result in console error.
I also tried $timeout(function(/* jquery updating */){}), nothing changes.
How do I make the change reflected on model?
- trigger it dirty?
- any best practice?
Thank you!
I am new for coded ui and I have got stuck for processing message display on webpage. As we used to get text from web page in selenium using method getText(), is such kind of possibility are available in coded ui.?
I would appreciate your help!!!!
Thanks,
Dani
updated - 5/14/2014
script code:
public void FPInternetExplorer()
{
#region Variable Declarations
HtmlEdit uIUserNameEdit = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UIUserNameEdit;
HtmlEdit uIPasswordEdit = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UIPasswordEdit;
HtmlInputButton uILoginButton = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UILoginButton;
HtmlEdit uISecurityQuestionAnswEdit = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UISecurityQuestionAnswEdit;
HtmlInputButton uIValidateButton = this.UIFundingPilotPortalWiWindow.UIFundingPilotPortalDocument.UIValidateButton;
#endregion
this.UIInternetExplorerEnhaWindow6.LaunchUrl(new System.Uri(this.FPInternetExplorerParams.UIInternetExplorerEnhaWindow6Url));
// Type 'test#test.test' in 'User Name' text box
uIUserNameEdit.Text = this.FPInternetExplorerParams.UIUserNameEditText;
// Type '{Tab}' in 'User Name' text box
Keyboard.SendKeys(uIUserNameEdit, this.FPInternetExplorerParams.UIUserNameEditSendKeys, ModifierKeys.None);
// Type '********' in 'Password' text box
uIPasswordEdit.Password = this.FPInternetExplorerParams.UIPasswordEditPassword;
// Click 'Login' button
Mouse.Click(uILoginButton, new Point(62, 19));
//Code to get the text from div tag. This is the code I have added
HtmlDiv testLabel = new HtmlDiv();
testLabel.SearchProperties[HtmlDiv.PropertyNames.Id] = "SecurityQuestion_AnswerText";
string myText = testLabel.InnerText;
Console.Write("myText " + myText);
// Type 'Computer' in 'SecurityQuestion.AnswerText' text box
uISecurityQuestionAnswEdit.Text = this.FPInternetExplorerParams.UISecurityQuestionAnswEditText;
// Type '{Tab}' in 'SecurityQuestion.AnswerText' text box
Keyboard.SendKeys(uISecurityQuestionAnswEdit, this.FPInternetExplorerParams.UISecurityQuestionAnswEditSendKeys, ModifierKeys.None);
// Click 'Validate' button
Mouse.Click(uIValidateButton, new Point(81, 25));
}
// When run this code using coded UI, system gives exception: Message - 'To test Windows Store apps, use the Coded UI Test project template for Windows Store apps under the Windows Store node.' Is something missing in this code? Would appreciate if you could provide link to configure missing component
The property you're looking for is "InnerText". So, for example, on a hyperlink like:
HtmlHyperlink target = new HtmlHyperlink();
target.SearchProperties[<search property>] = <value>;
string myText = target.InnerText;
You can extrapolate this to just read all of the text on the page by selecting the outer container of the page and getting the InnerText of it, then parse through the string for what you want, but I've found it a lot simpler if you work in the most focused object.
I have 2 combo boxes and 1 input text field. On change of the 1st combo I set some value in the input field and partial refresh the panel where the input field is.
OnComplete of this refresh, i partial refresh (using XSP partialRefreshPost) the panel of the 2nd combo box. This combo box value as you can see is just the 1st combo's value.
The problem is:
The combo value is set but the input value is not! Although input's panel refresh comes first and on complete comes the combo's panel refresh. If i remove the code from inside the 2nd combo's value tab then the input field works. (or if i just remove the reference of the 1st combobox from the 2nd combobox then it works again).
The weird thing is:
if i use a listbox instead of the second combo box then it works!!
The xpage design is:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:table>
<xp:tr>
<xp:td>
<xp:comboBox id="comboBox1">
<xp:selectItem itemLabel="a" itemValue="a"></xp:selectItem>
<xp:selectItem itemLabel="b" itemValue="b"></xp:selectItem>
<xp:selectItem itemLabel="c" itemValue="c"></xp:selectItem>
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="panel1">
<xp:this.action><![CDATA[#{javascript:var inputText1:com.ibm.xsp.component.xp.XspInputText = getComponent("inputText1");
inputText1.setValue("aaaaaa");}]]></xp:this.action>
<xp:this.onComplete><![CDATA[alert("refreshed panel1");
XSP.partialRefreshPost("#{id:panel0}",{onComplete: function(){alert("refreshed panel0");}});]]></xp:this.onComplete>
</xp:eventHandler></xp:comboBox></xp:td>
<xp:td></xp:td>
</xp:tr>
<xp:tr>
<xp:td></xp:td>
<xp:td></xp:td>
</xp:tr>
</xp:table>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:panel id="panel0">
<xp:comboBox id="comboBox2">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:var comboBox1:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("comboBox1");
if(comboBox1.getValue()!=null){
return comboBox1.getValue().toString();
}else{
return "its empty";
}}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox></xp:panel>
<xp:br></xp:br>
<xp:panel id="panel1">
<xp:inputText id="inputText1"></xp:inputText>
</xp:panel>
<xp:br></xp:br>
<xp:br></xp:br></xp:view>
Just replace 2nd combo with this and see....
<xp:listBox id="listBox1">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:var comboBox1:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("comboBox1");
if(comboBox1.getValue()!=null){
return comboBox1.getValue().toString();
}else{
return "its empty";
}}]]></xp:this.value>
</xp:selectItems>
</xp:listBox>
Any ideas?
When using a combobox, the first value in the list is the selected value. When you are using a list box, you have to choose a value from the list first. If you select a value, your example will fail too.
Because you are changing the allowed values of the combobox/listbox programmatically, and then try to set a value which is not longer in the list (the value is posted back to the server when doing a partial refresh), a validation error occurs, and the value of the inputText ('aaaaa') is not set in the backend.
You can add a xp:messages component inside of the panels, then you can see the error message.
Try doing this bind the controls to a viewScope then it should work.
I always bind my components to something scope variable, field or bean because if you don't you can get lot's of strange value problems. That's my experience.
I've tested you code and my suggestion works as far as I can see.