-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to switch to new tab using chromedriver #346
Comments
Thanks for the extensive error report. You've been very thorough. I can't immediately think of a reason for the behaviour you observe. Are you running with exactly the same browser configuration in all cases (i.e. not headless in one, but not the other, same platform, remote vs local, etc)? Am I correct in assuming that you did not add What exactly is on the tab that is opened? Is it indeed an HTML page with a PDF object embedded, or is it maybe just a PDF shown in a 'preview'. What does the URL look like? Given the fact that the error seems to start on Can you try to change If the PDF is generated via a POST or Ajax call I'm afraid I don't know a way to check it via Selenium. In the cases I've had of that issue I tended to use one of 2 approaches to test the PDF. Test document generation directly via a REST call (e.g. via JsonHttpTest) or change the application to actually offer PDFs that are accessible via GET (i.e. where one would just have a To be able the check PDF content you could take a look at my, poorly documented I'm afraid, PDF fixture. But to really test document generation (for many possible variations) I recommend using unit tests where various combinations of input parameters are fed into the document generation and the resulting PDFs content checked. Such tests allow you to test all code paths in the document generation and usually allow "dynamic" elements (e.g. current date/time or a generated sequence number) to be stubbed/mocked/fixed so result can be checked comprehensively. From the browser I would just test that a PDF is available and one or two data elements to ensure supplied parameters are fed correctly into the generation process. |
Thanks for your extensive response.
Yes, all runs use the same browser configuration.
Thanks for the hint: This actually solved the timeouts and stacktrace problem.
The URL of the new tab is quite normal, identical to the one from the calling URL:
The content of the new tab is New PDF-tab<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>Vertragsvorschau</title>
</head><body>
<iframe src="data:application/pdf;base64, JVBERi0xLjQNCiXi48%2FTCjYgMCBvYmoKPDwKL0xlbmd0aCA3IDAgUgovRmlsdGVyIC9GbGF0ZURlY29kZQo%2BPgpzdHJlYW0KeJzdXN1z2ziSf%2FdfoaetTFWGQ4DgV%2B7JHnucbGZn7xLPzFXOW1tUBEmMJSrLj7jKf%2F01SH
...
IKJSVFT0YK" width="100%" height="100%"></iframe></body>
</html>
PDF-Generation-Angular-Snippet const pfdWindow = window.open("");
const pdfDocument = pfdWindow.document;
pdfDocument.write('<title>Vertragsvorschau</title>');
pdfDocument.write("Please wait for document ...");
this.contractcreationService.showForm(getCurrentProcessId()).subscribe(response => {
const iframeStart = "<\iframe width='100%' height='100%' src='data:application/pdf;base64, ";
const content = encodeURIComponent(response.data);
const iframeEnd = "'><\/iframe>";
pdfDocument.title = response.filename;
pdfDocument.body.innerHTML = "";
pdfDocument.write(iframeStart + content + iframeEnd);
}); The text "Please wait for document" is shown in the new tab for about 30s. Then it disappears and is replaced by the PDF view (this is why
I wasn't aware of his fixture. It looks quite promising 👍🏻 I'll use it probably after I can access the PDF from FitNesse ...
The document generation is external to our team and dependent on a more complex outer process.
Yes, that's my intention: Testing a few elements of the PDF would be great. But for now a download of the PDF would suffice. |
So the This PDF page is a new one to me. It is a HTML page with the PDF previewer of the browser embedded as an iframe. The PDF content is actually only present in browser memory (and encoded into the URL), so indeed 'download' will not work. The only thing we can achieve is to extract the iframe's I expect the |
This gives an improvement, but leads to a new error:
Console log output on "show | page title"
This comment led me to the idea to try firefox for the test. So it's clear that we have a problem with chromedriver. Are we sure if this problem is something special to the pdf preview page, or could it be a general problem? (I cannot test the latter)
How would you do that? How could the src attribute of the HTML get extracted, e.g.?
BTW: The answer to the GET looks very similar to the HTML page: GET response{"filename":"Vertragsvorschau",
"mimeType":"application/pdf",
"data":"JVBERi0x ...Rgo="
} |
I believe the issue in chromedriver will be related to the pdf preview. You could try to make a static page with such an iframe (and PDF base64 encoded in src) and create a sample plain-Java-selenium program that tries to access that (in a tab) and see what results you get. I suspect you will get the same timeouts and you could submit that sample as bug to chromedriver project. That REST call still seems the best way forward the GET response could easily be converted to a PDF file, without any need to mess with screenshots etc. Is that |
I tried using HSAC's
I found it actually in the "session storage" of the browser's web storage as a key-value-pair assigned to the base URL of the web page. |
Getting the value of the attribute probably needs a 'technical selector', maybe something like:
"session storage" should be no problem, you can just execute a bit of JavaScript to get it. Try: Using JsonHttpTest you should be able to save the PDF based on the response doing something like:
|
Oh, and you may need to add |
Good to hear you were able to get to the Decoding the content you extracted is certainly possible, but I hadn't seen the need before to expose that as a fixture method. JsonHttpTest can do it when such a value is present in a json response (see hsac-fitnesse-fixtures/src/main/java/nl/hsac/fitnesse/fixture/slim/JsonHttpTest.java Line 82 in e09c970
DataUrlHelper strips the prefix and then Base64Fixture can save it to disk. At the moment I fear you have to write your own custom fixture to get this to work directly from a string.
Calling another fixture from a scenario requires some 'wiki script magic'. Something I advice to do with caution as it makes the tests scenarios harder to understand and maintain. You have to 'push' the current fixture, start a new fixture, do what you need to do with the new fixture and then 'pop' back to the old one. In the documentation the call this changing the script's actor. You get something like:
|
Downloading content from a 'data-url' instead of 'normal' link is actually quite a nice feature. I created an issue to add support for that. (Maybe someone can implement a PR for it before I'll get around to it.) |
I switched to use firefox.
Before I try this I want to give the "fixture chaining" approach a try:
This works perfectly for me! Thank you very much for providing the snippets (didn't find this push/pop in my searches ...). Thanks again for your support! |
Unfortunately did the JsonHttpTest-version work only in one of our test environments, but in not the others.
It was roughly a copy'n'pasting of existing code. I'll provide my solution here. It's probably not as elegant as proposed in #347, but it works for me: protected Base64Fixture getBase64Fixture() {
return new Base64Fixture();
}
public String createFileFromUrlEncoded(final String baseName, final String urlEncodedContent) {
String base64Content = java.net.URLDecoder.decode(urlEncodedContent, StandardCharsets.UTF_8);
if (DataUrlHelper.isDataUrl(base64Content)) {
base64Content = DataUrlHelper.getData(base64Content);
}
Base64Fixture base64Fixture = getBase64Fixture();
return base64Fixture.createFrom(baseName, base64Content);
} Calling this from a scenario:
|
The application that I'm testing using HSAC library opens a new tab when clicking on a certain button.
The test script is supposed to take a screenshot of that new tab and save its content (it's a PDF embedded in html, so its content is not easily testable).
The test script uses fixture
switch to next tab
, but this does not work: The script still stays on the the same tab.I added some high level debugging with a scenario
which confirms my observation: Before clicking the button the output is (1, 1), Tab count increases after clicking the button which leads to a (2, 1). But
switch to next tab
still shows (2, 1):In order to analyse this I copied the java-code of
switchToNextTab()
and added some logging:Custom switchToNextTab
To my surprise the value of
current tab index
changes (2nd pic in attachments), but I run into timeouts forswitchToMyNextTab()
and every fixture method that is called afterwards.FitNesse output on calling custom switchToNextTab
Execution log
So my questions are:
switchToNextTab()
?Versions:
HSAC 4.19.0
FitNesse 20200501
Many thanks in advance,
reators
The text was updated successfully, but these errors were encountered: