3

i'm testing my JSF with Arquillian.

a simple button looks like this:

<h:form id="myForm">
  <a4j:commandLink value="delete" 
   ajaxSingle="true" id="delete"
   action="#{controller.delete(object)}" 
   reRender="something" status="globalStatus" 
   onclick="if(!confirm('do you really wanna delete this?')){return false;}" />
</h:form>

The controller-function will looks like this

delete(Object object){ 
  do something 
}

My test looks like this

@RunWith(Arquillian.class)
public class TestCategoryPage extends Browser 

@Test
@RunAsClient
public void delete_test(){
browser.open(URL);
browser.click("id=myForm:cbDelete");
Assert.assertTrue("something", browser.isElementPresent("xpath=//p[contains(text(), 'deleted successfull')]"));

All other tests are working, but when i run this test i get the following exception:

com.thoughtworks.selenium.SeleniumException: ERROR: There was an unexpected Confirmation! [do you really wanna delete this?] at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:112)

Is there any way to catch this javascript confirmation? Thanks!

Joergi
  • 1,527
  • 3
  • 39
  • 82

3 Answers3

1

One option would be to look at Arquillian Graphene: https://docs.jboss.org/author/display/ARQGRA/Getting+Started

Graphene has built in support for ajax waits. Works as a wrapper around the Selenium APIs.

Aslak Knutsen
  • 706
  • 3
  • 4
  • alright, i will have a look on Graphene, but i really hoped that there is already a function in Arquillian or Selenium which i just don't know yet! – Joergi Sep 06 '12 at 13:59
  • `Selenium.waitForCondition(javascript, timeout)` is what Graphene use in the background. Add some 'random' javascript that can detect when the ajax call is done. – Aslak Knutsen Sep 18 '12 at 23:30
1

It seems that there is a confirmation pop up before the 'deleted successfull' message. If thats the case you need to handle the alert pop up. try following

driver.switchTo().alert().accept();

Or you can use javascript executor ot override the confirmation box:

js.executeScript("window.originalConfirm = window.confirm;window.confirm = function(m) { return true; };");
Prashant Shukla
  • 1,391
  • 9
  • 18
  • any way to do it without the webdriver? and what you mean with js.??? where is the js. from? – Joergi Sep 20 '12 at 14:05
1

well, basically I use jsexecutor to handle 'bottlenecks' with js:

//jsCLick on element function:

public void jsClick(String cssSelector){
JavascriptExecutor js = (JavascriptExecutor) driver;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("var x = $(\'"+cssSelector+"\');");
        stringBuilder.append("x.click();");
        js.executeScript(stringBuilder.toString());
}

taking into condiration post by Prashant Shukla he suggested you proper idea you can act in the following way:

public void jsAlertHandle(){
  JavascriptExecutor js = (JavascriptExecutor) driver;
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("window.confirm;");
            stringBuilder.append("window.confirm = function(m) { return true; };");
            js.executeScript(stringBuilder.toString());
}
jsAlertHandle();

Hope now a this becomes more clear to you)

eugene.polschikov
  • 7,254
  • 2
  • 31
  • 44