How to test AjaxEventBehavior("onClick") for Apache Wicket radio button? - ajax

I'm using apache wicket and I run into trouble regarding testing the AjaxEventBehavior for a Radio button. Actually I want to test the "onClick" event like in my case when I select/click a radio button from a RadioGroup a specif page is rendered.
Code snippet:
RadioGroup<Boolean> selectPageRadioGroup =
new RadioGroup<Boolean>("selectPageRadioGroup", new Model<Boolean>(Boolean.TRUE));
selectPageRadioGroup.setDefaultModel(new Model<Boolean>(Boolean.TRUE));
final Radio<Boolean> radioButton1 =
new Radio<Boolean>("radioButton1", new Model<Boolean>(Boolean.FALSE));
radioButton1.add(new AjaxEventBehavior("onclick") {
#Override
protected void onEvent(AjaxRequestTarget target) {
setResponsePage(MyWebPage.class);
}
});
selectPageRadioGroup.add(radioButton1);

Assuming you have already done
WicketTester tester = new WicketTester();
tester.startPage(PageContainingRadioButton.class);
or a similar startPanel (Wicket 1.4) or startComponent (Wicket 1.5), so that your test has rendered a page containing the button at a known path you should be able to make WicketTester simulate the ajax behavior by something like
tester.executeAjaxEvent("blabla:form:selectPageRadioGroup:radioButton1", "onclick");
(You'll need to adjust that path of course.)
and then check that it did the right thing with
tester.assertRenderedPage(MyWebPage.class);

Related

Selenium "Element is not clickable at point" error in Firefox

In regards to the Webdriver error
Element is not clickable at point (X, Y). Another element would recieve the click instead.
For ChromeDriver, this is addressed at Debugging "Element is not clickable at point" error, however the issue can occur in Firefox as well.
What are the best ways to resolve this when it occurs in FirefoxDriver?
This happens in the below cases-
When the element is loaded into the DOM, but the position is not
fixed on the UI. There can be some other div or images that are not
loaded completely.
The page is getting refreshed before it is clicking the element.
Workaround
Use Thread.sleep before actions on each web element in UI, but it is
not a good idea.
Use WebDriverWait ExpectedConditions.
I was facing the same issue, the page load time was more and a loading icon was overlapping on entire web page.
To fix it, I have implemented WebDriverWait ExpectedConditions, which waits for the loading icon to disappear before performing click action on an element
Call this function before performing an action (I am using data driven framework)
public void waitForLoader () throws Exception {
try {
String ObjectArray[]=ObjectReader.getObjectArray("LoadingIcon");
if(checkElementDisplayed(ObjectArray[3],ObjectArray[2]))
{
WebDriverWait wait = new WebDriverWait(remotewebdriver,10);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(ObjectArray[3])));
}
} catch (NoSuchElementException e) {
System.out.println("The page is loaded successfully");
}
}
If your problem is that the element is scrolled off the screen (and as a result under something like a header bar), you can try scrolling it back into view like this:
private void scrollToElementAndClick(WebElement element) {
int yScrollPosition = element.getLocation().getY();
js.executeScript("window.scroll(0, " + yScrollPosition + ");");
element.click(); }
if you need you could also add in a static offset (if for example you have a page header that is 200px high and always displayed):
public static final int HEADER_OFFSET = 200;
private void scrollToElementAndClick(WebElement element) {
int yScrollPosition = element.getLocation().getY() - HEADER-OFFSET;
js.executeScript("window.scroll(0, " + yScrollPosition + ");");
element.click();
}
You can direct click using JavascriptExecutor (Not recommanded)
WebElement element= driver.findElement(By."Your Locator"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
Hope it will help you :)
My same problem is solved by Javascript, Please try following code instead of selenium click
WebElement rateElement = driver.findElement(By.xpath(xpathContenRatingTab));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", rateElement);
Careful matching of the Selenium jar version with the Firefox version can fix the issue. Selenium should automatically scroll an element into view if it isn't on the page. Forcing an element into view with JavaScript is unnecessary.
We never see this issue in Firefox 31.5.0 with selenium-server-standalone-2.44.0.jar, however when upgrading to Firefox 38.7.0 with selenium-server-standalone-2.52.0.jar, it became an issue.
See https://github.com/seleniumhq/selenium/issues/1543
I had the same problem and I solved it using certain capability. While you are using FirefoxDriver, you can set "overlappingCheckDisabled" to true to solve your problem.
capabilities.setCapability("overlappingCheckDisabled", true);
ActionBuilder can resolve the error. Sometimes there is another element in front of the object that needs to be clicked, so an ActionBuilder click to the location of the element may work in cases where a traditional click fails
Actions actions = new Actions(driver);
actions.moveToElement(clickElement).click().perform();
or try the middle of the element
Actions actions = new Actions(driver);
Integer iBottom = clickElement.getSize().height;
Integer iRight = clickElement.getSize().width;
actions.moveToElement(clickElement, iRight/2, iBottom/2).click().perform();
This Error coud ocur when for example u make to many accesses to some service , for example if u are making as I a bot .... For example instagram will block u for some period if u ar taged as blocked and then that error coud ocour not allowing u to click some elements in the page.
Try make another acount and switch to a vpn becouse probably your ip is already marked as blocked
Try to maximize the browser when you are working with resolutions greater than 1024x768. It works for me in js.
driver.manage().window().maximize();

angular ui-grid filter on button click

I'm new in angular. We are using UI-grid for data presentation is is possible to customize filter process. I want to customize it in that way, that filtering is peformmed on button click, not on keydown?
This is idea
$scope.search = function (){
$scope.personCardGrid.useExternalFiltering = false; $scope.grid1Api.core.notifyDataChange(uiGridConstants.dataChange.ALL);
$scope.gridApi.core.refresh() $scope.personCardGrid.useExternalFiltering = true;
$scope.grid1Api.core.notifyDataChange(uiGridConstants.dataChange.ALL);
$scope.gridApi.core.refresh() }
Regards
You need to define your own headerCellTemplate for the column. In the template, add a input text box and a button too. Then, define a function in the controller and call it using the external scope which will filter the records.

Adding functionality to wicket palette button

I want to add some functionality to the right arrow button, the one that puts the user selection into the selected elements panel. Specifically, when the user selects an element from the avaliable choices, I don't want the element to be taken to the selected elements panel if there are elements at the right panel of another palette. So basically, what I need is to execute custom java code when the button is pressed, and alter the default behavior of the palette when a condition occurs.
I found the solution somewhere else. Just in case someone needs it, here is what you have to do.
myPalette = new Palette<MyClass>(...) {
#Override
protected Recorder newRecorderComponent() {
Recorder<MyClass> recorder = super.newRecorderComponent();
recorder.add(new AjaxFormComponentUpdatingBehavior("onchange") {
protected void onUpdate(AjaxRequestTarget target) {
// Custom code
...
if (target != null)
// Update another component
target.add(anotherComponent);
}
}
);
return recorder;
}
};

Wicket Panel not refreshed when swapped in via an AJAX request

I have a Panel that I initially replace with another panel (a spinning circle saying "loading") and after a while in an AJAX event replace back. So what I do is:
#Override
protected void onConfigure() {
if (!content.isLoaded()) {
tmp = new LoadingCircle(getId(), "Loading...");
this.replaceWith(tmp);
}
}
public void onLoaded(AjaxRequestTarget target) {
if (tmp != null) {
tmp.replaceWith(this);
tmp = null;
}
target.add(this);
}
This works, so the panel is shown back in the page. However, this panel has some subpanels with some labels and they are not refreshed. I see the updated labels when I reload the page but not immediately after showing the whole panel with AJAX.
I notice that the onConfigure and onBeforeRender methods are called only once - when the panel is created but not again when it is actually shown for the first time using AJAX. The same for the subpanels, so that would explain why they are not refreshed. But the question is - why is the panel not refreshed (the updated model values are not used) when it is added to the AJAX request target?
EDIT: I think this may be relevant: https://issues.apache.org/jira/browse/WICKET-5107. Still, I wonder what I should change in my code to make it work?
IMO it looks like you should use an AjaxCallDecorator instead to do what you are trying to do with the spinner.

ExtJS 4 how to properly create a KeyMap for a window when using MVC

I have a simple ExtJS application that is written MVC style (much of my information from here).
My application creates a viewport, and has a view with a form, some fields and a button.
The application has a controller with a 'loginButtonClick" function, and the controller watches the click event with a:
this.control({
'loginwindow button[action=save]': {
click: this.loginButtonClick
}
}
That works great, but now when the login window is showing, I want the enter key to also execute the loginButtonClick method.
I have tried all kinds of things, but the basic issue I am having is WHERE to put the code for creating the keymap, and how to bind it to the proper instances.
For example, if I create the keymap in the controller (which is my preference), I need to get the specific view instance for that controller (I might have multiple windows open of the same kind).
So, How would you create a key map (or?) from within a controller for it's view (window), calling a local method (this.loginButtonClick) when the enter key is pressed?
What you can do is bind the code that initializes the keyMap to the login window afterrender event like this:
this.control{(
'loginwindow' : {
afterrender: this.initializeKeyMap
}
Then make a function that sets up the keyNav:
initializeKeyMap: function(window, options) {
this.keyNav = Ext.create('Ext.util.KeyNav', window.el, {
enter: this.loginButtonClick,
scope: this
});
}
Now when the dialog is loaded if the user presses the Enter key, it should execute your function.
You could setup all these things on your window render event. So when it is rendered you add an eventlistener for the enter key, and in the handler you call programatically click on the login button.
You can achieve this by adding the following listeners to your text/password fields in the form
listeners: {
specialkey: function(field, e){
if (e.getKey() == e.ENTER) {
var form = this.up('form').getForm();
submitLoginForm(form);
}
}
}
Here 'form' is your form and 'submitLoginForm' is the function called at form submit which I guess is loginButtonClick in your case.
Hope this helps.

Resources