Service Virtualization

Expand all | Collapse all

Handling new windows and Popup's in DevTest

Marcy Nunns

Marcy NunnsAug 11, 2016 02:52 PM

  • 1.  Handling new windows and Popup's in DevTest

    Posted Aug 10, 2016 03:18 PM

    Does CA DevTest Support Handling new windows and Popup when we import selenium as json?

    I am able to open new window But not able to execute script inside a new window. so if any one has a solution let me know.



  • 2.  Re: Handling new windows and Popup's in DevTest

    Broadcom Employee
    Posted Aug 11, 2016 11:35 AM

    Can I get some more information from you on this?

     

    What version of DevTest are you on?

    Can you show what your json script is doing?



  • 3.  Re: Handling new windows and Popup's in DevTest

    Posted Aug 11, 2016 12:07 PM

    Version of DevTest is 9.1.0

     

    we are trying to execute this script which goes to new window to execute Reports and comes back to same window.

     

    [{"negated":false,"step_name":"17.","name":"TheNewWindow","type":"switchToWindow"}]

    [{"negated":false,"title":"***","type":"waitForTitle"}]

    In "***", I am trying to click on reports getting execption.

    [{"negated":false,"type":"clickElement","locator":{"type":"xpath","value":"//a[text()='Reports']"}}]

    | Error executing Selenium Step :

    [{"negated":false,"type":"clickElement","locator":{"type":"xpath","value":"//a[text()='Reports']"}}]

    ============================================================================

    | Step:        ClickElement: Home

    ----------------------------------------------------------------------------

    | Message:     {"negated":false,"type":"clickElement","locator":{"type":"xpath","value":"//a[text()='Reports']"}} failed.

    ----------------------------------------------------------------------------

    | Trapped Exception: {"negated":false,"type":"clickElement","locator":{"type":"xpath","value":"//a[text()='Reports']"}} failed.

    | Trapped Message:   java.lang.RuntimeException: {"negated":false,"type":"clickElement","locator":{"type":"xpath","value":"//a[text()='Reports']"}} failed.

    ----------------------------------------------------------------------------

    STACK TRACE

    java.lang.RuntimeException: {"negated":false,"type":"clickElement","locator":{"type":"xpath","value":"//a[text()='Reports']"}} failed.

    at com.sebuilder.interpreter.TestRun.executeStep(TestRun.java:81)

    at com.itko.lisa.glass.SeleniumScriptExecutor.executeStep(SeleniumScriptExecutor.java:373)

    at com.itko.lisa.glass.SeleniumScriptExecutor.executeStep(SeleniumScriptExecutor.java:305)

    at com.itko.lisa.glass.SeleniumStep.execute(SeleniumStep.java:313)

    at com.itko.lisa.test.TestNode.executeNode(TestNode.java:981)

    at com.itko.lisa.test.TestCase.execute(TestCase.java:1295)

    at com.itko.lisa.test.TestCase.execute(TestCase.java:1210)

    at com.itko.lisa.test.TestCase.executeNextNode(TestCase.java:1195)

    at com.itko.lisa.test.TestCase.executeTest(TestCase.java:1136)

    at com.itko.lisa.coordinator.Instance.run(Instance.java:204)

    Caused by: org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //a[text()='Reports'] (WARNING: The server did not provide any stacktrace information)

    Command duration or timeout: 335 milliseconds

    For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html

    Build info: version: 'unknown', revision: 'unknown', time: 'unknown'

    System info: host: 'ITS0830D5030576', ip: '10.232.151.71', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_60'

    Driver info: org.openqa.selenium.ie.InternetExplorerDriver

    Capabilities [{browserAttachTimeout=0, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:24694/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]

    Session ID: 66401d70-8869-4443-8901-58b82b6fe134

    *** Element info: {Using=xpath, value=//a[text()='Reports']}

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

    at java.lang.reflect.Constructor.newInstance(Unknown Source)

    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)

    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)

    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)

    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:353)

    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:490)

    at com.sebuilder.interpreter.Locator$Type$7.find(Locator.java:131)

    at com.sebuilder.interpreter.Locator.find(Locator.java:48)

    at com.sebuilder.interpreter.steptype.ClickElement.run(ClickElement.java:28)

    at com.sebuilder.interpreter.TestRun.executeStep(TestRun.java:75)

    ... 9 more

    ============================================================================

    I hope this info could help.

     

    Thanks



  • 4.  Re: Handling new windows and Popup's in DevTest

    Broadcom Employee
    Posted Aug 11, 2016 12:10 PM

    Daniel Mazzei - can you look at this and add this as a use case to your Selenium doc?



  • 5.  Re: Handling new windows and Popup's in DevTest

    Posted Aug 11, 2016 01:51 PM

    Hi, Yeshwanth.jakkula,

    It looks like there is an issue with the path:

    Caused by: org.openqa.selenium.NoSuchElementException: Unable to find element with xpath ==

    Have you tried with other windows/applications?



  • 6.  Re: Handling new windows and Popup's in DevTest

    Posted Aug 11, 2016 02:04 PM

    Hi,I tried to playback in IE.  

    I think when a new window opens its not recognizing or pointing to the existing window. So we are getting an Exception. would you provide any code that opens a new window and reads the content of current window and goes back to it.

    thanks



  • 7.  Re: Handling new windows and Popup's in DevTest

    Broadcom Employee
    Posted Aug 11, 2016 02:52 PM

    Does this work with Firefox or Chrome?



  • 8.  Re: Handling new windows and Popup's in DevTest

    Posted Aug 12, 2016 11:18 AM

    No,I have tried to record in Firefox But when new window popup's its not reading the inputs from new window or when we click any tabs in new window they aren't been recorded. So I am trying to write a script were selenium can handle a new window and point to current window.

    thanks



  • 9.  Re: Handling new windows and Popup's in DevTest

    Posted Aug 14, 2016 10:38 PM

    The new window is modal? or modeless?

    And when opening the new window, is the JavaScript "window.open" function used?

     

    When using Firefox, it is possible to set the behavior of opening the new window in the "about:config".

    The procedure is as follows.

     

    1. Settings in "about:config" of Firefox.

    browser.link.open_newwindow  1
    browser.link.open_newwindow.restriction  0
    

    2. Record the operation with Selenium Builder.

    3. Import the JSON script to DevTest.

    4. Add a new step of "switchToWindowByIndex" after opening the new window action in DevTest Workstation.

     

    I verified this workaround with DevTest 9.5.1, Firefox 44.0.2 and a new modeless window.



  • 10.  Re: Handling new windows and Popup's in DevTest

    Posted Aug 15, 2016 12:46 PM

    I tried to record in Firefox while playback seeing Error unable to create Driver.

    In v9.1.0 I haven't seen this step,could you provide this step "switchToWindowByIndex".

    thanks



  • 11.  Re: Handling new windows and Popup's in DevTest
    Best Answer

    Posted Aug 15, 2016 09:15 PM

    "switchToWindowByIndex" is one of the step of Selenium Builder.

     

    First, create a JSON script that contains the switchToWindowByIndex.

    Next, import the JSON script to DevTest test case in Workstation.

    Then, use the "switchToWindowByIndex" that copied from the Test case.

     

    By the way, Firefox Binary is in the right place?

    By using a selenium-config.json in {{LISA_HOME}} dir, it is possible to explicitly specify the Firefox Binary's location.

     

             "Capabilities": [
                {
                   "name": "browserName",
                   "value": "firefox",
                   "type": "string"
                },
                {
                   "name": "firefox_profile",
                   "value": "<default>",
                   "type": "string"
                },
                {
                   "name": "firefox_binary",
                   "value": "C:/opt/firefox/firefox.exe",
                   "type": "string"
                },
    


  • 12.  Re: Handling new windows and Popup's in DevTest

    Posted Aug 15, 2016 09:34 PM

    I have attached a sample of DevTest 9.5.1 and images of the before and after changes of the test case.

    Attachment(s)

    zip
    CACommunity.zip   8 KB 1 version


  • 13.  Re: Handling new windows and Popup's in DevTest

    Posted Aug 22, 2016 02:49 PM

    Hi, Yeshwanth.jakkula, and thanks tommy_jp!

     

    You should be able to use the SwitchToWindow step in Selenium as mentioned.

     

    Also, try using Chrome instead of Firefox. I've seen some issues with FireFox playback that I do not see in Chrome.