2 Replies Latest reply on May 7, 2013 4:04 AM by Sarojini Pandiyan

    Test opening a new window via JavaScript

    Axel Wilhelm Berle Newbie

      Has anybody tested the following scenario:

       

      • clicking on a button
      • the button click triggers a javascript function opening a new window via window.open(...)
      • verify if the window has been opened

       

      I tried it with the following code:

       

           client.click("addGroup");

             
           // Verify the popup window exists
           WebClient webClient = jsfSession.getWebClient();
           List<WebWindow> openWindows = webClient.getWebWindows();   
             
           assertEquals("We are expecting 2 windows", 2, openWindows.size());
             
           for (WebWindow window: openWindows) {
                LOGGER.debug("Open window: " + window.getName());      
           }

       


      Sometimes it works, when debugging the code. Is it necessary to wait until the opened window has been fully initialized?

       

      Thanks for any help!

        • 1. Re: Test opening a new window via JavaScript
          Axel Wilhelm Berle Newbie

          I found the following solution:

           

          • After clicking, yield control for some (small) time


          The test then passes:


                  // wait some time
                  try {
                      Thread.currentThread().sleep(10);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }

                 
                  // Verify the popup window exists
                  WebClient webClient = jsfSession.getWebClient();
                  List<WebWindow> openWindows = webClient.getWebWindows();   
                 
                  assertEquals("We are expecting 2 windows", 2, openWindows.size());
                 
                  for (WebWindow window: openWindows) {
                     
                      LOGGER.debug("Open window: " + window.getName());
                     
                  }

          • 2. Re: Test opening a new window via JavaScript
            Sarojini Pandiyan Newbie

            Hi Axel,

            Have you worked on testing the contents  of the  new window? that is the buttons and its actions inside the new window, above the parent Window?

            If so help me.