Table of Contents
1. Limitations When Testing PDF Viewer
1-1. PDF Files Cannot Be Downloaded
Currently, MagicPod does not support automating PDF file downloads in Chrome PDF Viewer.
This is because the UI tree obtained via UI Scan does not include the Download button, which means MagicPod cannot capture it as a UI element.
1-2. Individual Elements Inside a PDF File Cannot Be Targeted
Similarly, the UI tree obtained via UI Scan does not include information about individual elements inside a PDF file, such as text or images.
Therefore, you generally cannot execute commands against specific text or image elements within a PDF file.
However, it is still possible to perform visual regression testing using Visual diff checks, or verify page contents using AI Assertion.
These options are explained later in this article.
1-3. Switching to the Chrome PDF Viewer Tab or Subsequent Steps May Fail
In some cases, Chrome PDF Viewer may be recognized as an independent browser tab due to its extension behavior. This can cause issues when switching tabs or executing subsequent steps.
If this happens, try adding a wait step of a few seconds during the tab switch and see if the issue improves.
If adding a wait step does not resolve the issue, please try using the "Retry on Failure" feature.
If the behavior remains unstable even after that, this is a limitation that is difficult for us to fix on our side. In that case, we recommend excluding this scenario from the scope of automated testing.
2. What You Can Test on PDF Viewer
2-1. Visual Regression Testing Using Visual Diff Checks
If you want to verify whether the content displayed in a PDF file is correct, you cannot use assertion commands for individual elements.
Instead, you can use the Assert there is no visual diff command to compare the displayed content visually.
To make the image comparison more stable, you can set exclusion areas on the expected image for regions outside the currently selected page.
2-2. Content Validation Using AI Assertion
As an alternative to visual regression testing with the Assert there is no visual diff command, you can also verify PDF content using the Assert with AI command.
As an example, the screenshot below shows the result of running the Assert with AI command against the displayed PDF page.
2-3. How to display the entire PDF within a screen
In Chrome PDF Viewer, the default display setting may prevent the entire PDF from displaying within the screen.
When running Visual Diff Check Tests or AI assertion tests, you may want to display the entire PDF within a screen. To do this, you can append a parameter such as #zoom=72 to the end of the URL to open the PDF at a specified zoom level.
To add #zoom=72 to the URL, use the Run TypeScript Code command as follows:
Code editor:
function magicpodCustomStep(args) {
const url = args.current_url;
const zoomedUrl = url.split('#')[0] + '#zoom=72';
return [zoomedUrl];
}The overall steps should be configured as follows (be sure to execute the Reload command at the end).
This allows the entire PDF to display within the screen.
2-4. How to Display the Second Page and Beyond
How to display pages 2–4
To display pages 2–4 in the PDF Viewer, use the Click specified position command on the area covering the entire PDF Viewer, and specify the coordinates of the target page in the left sidebar.
At this time, the locator for the area covering the entire PDF Viewer may include a random name attribute value that changes each time the test is run. Therefore, please select a locator that does not include such a value, such as css=embed.
Using this method, you can display up to page 4, which is visible in the sidebar.
How to display page 5 and beyond
To display pages beyond page 4, use the Keyboard Input command with the down arrow key.
However, you must first set focus on the left sidebar.
Therefore, the steps are as follows:
- Click the left sidebar using the Click specified position command (to set focus)
- Input the down arrow key using the Input keyboard key command
First, click the left sidebar using the Click specified position command.
As with the steps for displaying pages 2 to 4, specify the area covering the entire PDF Viewer as the target UI element, and use coordinates to click on the left sidebar area.
As mentioned above, the locator for the area covering the entire PDF Viewer may include a random name attribute value that changes each time the test is executed. Therefore, please select a locator that does not include such values, such as css=embed.
Then, input the down arrow key using the Input keyboard key command.
Each press of the down arrow key moves to the next page, so press it (number of pages - 1) times.
If many key inputs are required, you can use the Repeat Until command as shown below. (However, the execution speed may be slightly slower.)
2-5. Navigating Away from the PDF Viewer Page
If PDF Viewer is opened in a separate tab or window, you can close it using the Close tab/window command and the Select previous tab/window command.
This allows you to close the PDF Viewer tab/window and return to the previous one.
If PDF Viewer is not opened in a separate tab or window, please navigate to another page using the Navigate to URL command.
3. Limitations in Chrome 148 and Later
Starting with Chrome 148, changes on the Chrome side have made it impossible to detect the <embed> element used by Chrome PDF Viewer.
As a result, the methods described in "2-4. How to Display Pages Beyond the First Page" that rely on interacting with the element covering the entire PDF Viewer area (such as css=embed) can no longer be used with commands such as Click at Position or other UI operations.
Therefore, it is no longer possible to use the element covering the entire PDF Viewer to specify coordinates for a page in the left sidebar or to set focus on the left sidebar.
Workaround
Even in Chrome 148 and later, AI Locators can still detect text elements displayed within the PDF Viewer, such as page numbers.
Therefore, you can display pages beyond the first page by following the steps below:
Use an AI Locator to click a page number displayed in the left sidebar and set focus on the sidebar.
(image)
Use the Keyboard Key Input command to press the Down Arrow key the required number of times.
(image)
By using this method, you can display pages beyond the first page even in environments running Chrome 148 or later.