2 Replies Latest reply on Sep 27, 2013 10:16 AM by kgoedert

    graphene wait api question

    kgoedert

      Hi,

       

      I have a test that clicks on a link on a table, than has to wait until a dialog with a question pops up to confirm the action. Since the test runs fast, I want the test to wait for a little bit so the dialog is properly rendered and the button can be clicked.

      In my test I have this:

       

      @Test
        public void deleteUser(){
        this.insertDataAndGetLoginUrl();
      
        loginPage.login("admin", "Admin123");
      
        userPage.registerUser("deleteme", "Admin123", "Admin123", "15/02/2010", "test");
      
        browser.findElement(By.xpath("//a[@id='userTable:4:delete_link']/i")).click();
      
        waitAjax().withTimeout(10, TimeUnit.SECONDS); //this line does not work
      
        waitAjax().until().element(By.id("deleteDialog")).is().enabled();
      
      
        browser.findElement(By.id("yes_button")).click();
      
        userPage.waitForMessage("Sucess.");
      
        String location = browser.getCurrentUrl();
        assertThat(location, containsString("/create" + Constants.JSF_EXTENSION));
      
        assertFalse(browser.getPageSource().contains("deleteme"));
      

       

      But non of my waitAjax()... seem to work. I am using the chrome driver to run the test. Graphene is version 2.0.0.CR1.

       

      Is this the correct way to wait for something to be rendered on a page?

        • 1. Re: graphene wait api question
          jhuska

          Hello Kelly,

           

          waitAjax().withTimeout(10, TimeUnit.SECONDS).until().element(By.id("deleteDialog")).is().present();

           

          should work for you.

           

          If clicking on the deleting link fire an AJAX request, more powerful waiting in this situation would be using of Graphene.guardAjax, like this:

           

          @Test  
           public void deleteUser(){  
            this.insertDataAndGetLoginUrl();  
            
            loginPage.login("admin", "Admin123");  
            
            userPage.registerUser("deleteme", "Admin123", "Admin123", "15/02/2010", "test");  
            
            Graphene.guardAjax(browser.findElement(By.xpath("//a[@id='userTable:4:delete_link']/i"))).click();  
            
            browser.findElement(By.id("yes_button")).click();  
          
          /.. the rest is the same
          

           

          Guard will wait until the AJAX request is done as its side effect. Its main reason is asserting that the AJAX request was made.

           

          Off topic: Have you considered to use e.g:

           

          @FindBy(xpath="//a[@id='userTable:4:delete_link']/i")
          WebElement deleteLink;
          

           

          And other page abstractions can give you more readable tests in result.

          1 of 1 people found this helpful
          • 2. Re: graphene wait api question
            kgoedert

            Thanks, it works now. I used your suggestions and I also had to get the element by a css selector instead of the id (I suppose primefaces may be changing the id by appending a value.)