Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Trying to Switch to a New Browser Tab Opened By The App

Speedy993
Speedy993 Posts: 72

I have a webapp that creates a PDF document in a new browser tab. I want to confirm that it is a PDF report and not a simple error message that will be displayed if the generation of the report failed for some reason. The tab is created by the app but focus remains in the application tab.
The problem I am having is that each report is always given a unique name that basically looks like it is a hexadecimal character so I am unable to use the tab title to specify the element. Also, what kind of action do I perform on it if I am able to locate it? Click? Hover? I have tried to click on the report blob and spcify

Here is the HTML when I do an Inspect on the PDF report in the Edge browser.

Searching the Forum I was only able to find a post from 2018 that pointed to the SOATest documents that did not seem to really answer the question (at least to me).

Thanks for any assistance you can offer.

Comments

  • Speedy993
    Speedy993 Posts: 72

    Sorry, it appears the HTML was lost ands the Forum apparently does not like it so I took a screenshot of the code. I'm sure there is a way to get it to display cleanly but I am frustrated and out of patience at the moment.

  • Speedy993
    Speedy993 Posts: 72

    So, looking at my previous posts, it appears that they were somewhat of a mess. I will try to explain things a little better.
    The web application will generate a PDF report that is displayed on a new tab in the browser. Focus is on this tab. The problem is that we want to make sure what is displayed on the new tab is actually a PDF report and not an error message. I have tried several times to perform an Action of Click on a several different elements on the new tab but always get an error stating that the element is not found. It acts like the second tab (Windows 2: (anonymous)) is not the window actually looked at for the test. If I disable that test, the next one closes the browser tab that the report is on. The Close action is performed on Window 2 and is successful as long as I don't try to to click on the PDF report in the previous step. I don't need to look at anything in the PDF, just make sure that it was generated.
    Am I missing something obvious? Is there more needed that I don't know?

    Thanks for any suggestions you may have.

  • tony
    tony Posts: 33 ✭✭
    edited August 2

    Because you are expecting a PDF document in the open window and Browser Testing Tools do not validate PDF content, it would probably be best for you to add some kind of validation to the request made by the browser for the PDF document. You will first need to add application/pdf to the binary MIME Types allowed in the Traffic Viewer and Outputs under Preferences> Parasoft> Browser> Allowable Binary Files in Traffic Viewer and Outputs> MIME types. When you play back your scenario you should see your PDF request in the traffic viewer for the step that opens the PDF document. If you do not see it, try adding an additional "Wait for Specified Time" wait condition to the step to ensure the file has had enough time to transfer.
    Then you will right-click the Browser Testing Tool that contains the request to the PDF and choose Add Output... > HTTP Traffic and select the request for the PDF. Choose Response > Body and then you can add a tool to verify the PDF content, such as a Search Tool that searches for the term %PDF and "Display Message If Search Term: Not Found."

    For reference, you can access windows by their index only using a special name in this format:
    ;index:N where N is the order in which the window appeared, starting at 0 for the first window. For reference, the complete format is windowName;index:N where windowName is the expected name of the window. windowName will first be used to identify the window and then the index. For this reason, window name is optional and so the format ;index:N can be used to only specify the index.
    To use this special name in the Browser Testing Tool, under User Action change the Window to "Custom" and enter a value such as:
    ;index:1

    This can be helpful in scenarios where the window name is always changing but the window index stays the same.

  • tony
    tony Posts: 33 ✭✭
    edited August 2

    Because you are expecting a PDF document in the open window and Browser Testing Tools do not validate PDF content, it would probably be best for you to add some kind of validation to the request made by the browser for the PDF document. You will first need to add application/pdf to the binary MIME Types allowed in the Traffic Viewer and Outputs under Preferences> Parasoft> Browser> Allowable Binary Files in Traffic Viewer and Outputs> MIME types. When you play back your scenario you should see your PDF request in the traffic viewer for the step that opens the PDF document. If you do not see it, try adding an additional "Wait for Specified Time" wait condition to the step to ensure the file has had enough time to transfer.
    Then you will right-click the Browser Testing Tool that contains the request to the PDF and choose Add Output... > HTTP Traffic and select the request for the PDF. Choose Response > Body and then you can add a tool to verify the PDF content, such as a Search Tool that searches for the term %PDF and "Display Message If Search Term: Not Found."

    For reference, you can access windows by their index only using a special name in this format:
    ;index:N where N is the order in which the window appeared, starting at 0 for the first window. For reference, the complete format is windowName;index:N where windowName is the expected name of the window. windowName will first be used to identify the window and then the index. For this reason, window name is optional and so the format ;index:N can be used to only specify the index.
    To use this special name in the Browser Testing Tool, under User Action change the Window to "Custom" and enter a value such as:
    ;index:1

  • Speedy993
    Speedy993 Posts: 72

    Sorry I have taken so long to reply back, Tony. Your suggestion has worked to add an output to the Search Tool that is searching for the string %PDF. At least it was working for a while. The application that this test is for is still being developed. At this point the only way to force an error while generating a report is to kick off a report without any criteria to narrow down the data to be displayed. This will result in the browser timing out waiting for the report to be returned. That is fine for these purposes. The issue here is that when the timeout error is thrown, the test is halted. I want the next two steps to run if the report is displayed or not. These steps will close the browser tab with the report or with the error message. The second step is to close the browser itself. The last two steps work fine when a report is displayed but when the report times out, the test ends right there. I tried copying the 2 steps to close the browser but have two run on successful complete of the report step and the other two when the step fails but the failed test still does not close the browser tabs.
    Is there a configuration I am missing or a tweak needed? I have tried changing the timeout duration in the preferences but get the same results. Thanks!
    Error Message:
    (Edge 128.0.2739.42) Unable to check if script dialog is present due to an unexpected error. View
    details for more information.

    Additional Details:
    timeout: Timed out receiving message from renderer: 30.000
    (Session info: MicrosoftEdge=128.0.2739.42)
    (Driver info: msedgedriver=127.0.2651.74
    (dbf5b0aa014c4e70e3d5e2d73248e21264f82957),platform=Windows NT 10.0.19045 x86_64) (WARNING: The
    server did not provide any stacktrace information)
    Command duration or timeout: 30.02 seconds
    Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time:
    '2016-06-30 19:26:09'

  • tony
    tony Posts: 33 ✭✭

    You can try unchecking the "Abort scenario on: Fatal error" setting under the parent scenario's "Execution Options" tab. See: https://docs.parasoft.com/display/SOA20241/Configuring+Test+Suite+Properties#ConfiguringTestSuiteProperties-abort-scenario-on

  • Speedy993
    Speedy993 Posts: 72

    Thanks Tony! That worked great.