Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

WebDriver Screenshots don't work if an alert is present. #4412

Closed
lukeis opened this issue Mar 4, 2016 · 9 comments
Closed

WebDriver Screenshots don't work if an alert is present. #4412

lukeis opened this issue Mar 4, 2016 · 9 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 4, 2016

Originally reported on Google Code with ID 4412

What steps will reproduce the problem?
1. Trigger an alert (do not dismiss)
2. use webdriver to take a screenshot

What is the expected output? What do you see instead?
I would expect the WebDriver to be able to take a screenshot that includes the alert.
Instead an UnhandledAlertException is thrown and no screenshot is taken.

Selenium version: 2.25.0
OS: Windows 7 64-bit
Browser: Firefox
Browser version: 14.0.1

Reported by mafus101 on 2012-08-14 00:57:19

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Reported by barancev on 2012-08-14 08:40:46

  • Labels added: Component-WebDriver, Browser-Firefox

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Screenshots are of the DOM content.  The alert belongs to a separate window and won't
be included. And yes, you must handle the alert before you can take a screenshot.

Reported by jmleyba on 2012-08-14 17:53:23

  • Status changed: WorkingAsIntended
  • Labels removed: Status-Untriaged

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

When the possition is ON the alert, I cannot take a screenshot or report a failevent.
Here is the piece of code i'm currently using:

loadAccountBtn.click();
    report.reportDoneEvent("ClickOnLoadAccount", "Click on Load Account");
        try {
            new WebDriverWait(browser, 30).
            until(ExpectedConditions.alertIsPresent());
        } catch (Exception UnreachableBrowserException) {
            report.reportFailEvent("Capture Pop up ", "Popup not displayed after clicking on
Load Account Button");
        }

        //verification of account information loaded alert box
        Alert javascriptAlert = browser.switchTo().alert();
        String loadaccmsg = javascriptAlert.getText();
        if (loadaccmsg.equals("Account data is loaded.")){
            report.updateTestLog("Check account data loaded message ", "Message correct: "+loadaccmsg,
Status.PASS);
            javascriptAlert.accept();
        }
        else {
            try {
                report.reportFailEvent("Check Error Message", "ErrorMsg: "+loadaccmsg);
                javascriptAlert.accept();
            } catch (Exception UnreachableBrowserException) {
                report.reportFailEvent("Check Error Message", "ErrorMsg: "+loadaccmsg);

            }

Inside the IF, if it goes from TRUE, the report is updated with the message and the
test continues, If it goes from the FALSE, the reportFailEvent throws an error message.
I've already tried with report.reportFailEvent("",""), report.updateTestLog("","",
Status.FAIL), and report.updateTestLog("","", Status.SCREENSHOT), in all three cases
I have the same response, the fail event is not displayed on the report, and the screenshot
is not taken.
Using the try - catch I was able to create a fail event on the report (it goes trough
the catch), however the screenshot didn't catch the alert, and yes, i've tried removing
the javascriptAlert.accept() from the try.

I understand that this defect is closed, but I wanted to provide more data on the issue.
Do you know what could be the problem? or is there is any other defect that is open?

Reported by Faku.iron on 2013-08-09 18:56:09

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Once try with below code

BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
            ImageIO.write(image, "png", new File("C:\\Users\\Public\\Pictures\\fail1.png"));

Reported by teja.vallu on 2015-03-05 12:06:59

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I tried the Buuffer code but getting the below error..


java.lang.Error: Unresolved compilation problems: 
    The method createScreenCapture(java.awt.Rectangle) in the type Robot is not applicable
for the arguments (com.itextpdf.text.Rectangle)
    The constructor Rectangle(Dimension) is undefined


Reported by arnika.jain02 on 2015-04-17 09:24:25

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

i am not getting any error in console, but screenshot is taken as attached.

Reported by arjunbm13 on 2015-06-04 05:42:09


- _Attachment: _firefox_TimeBarDeparture_JA_04_Jun_2015__10_01_48.png
![_firefox_TimeBarDeparture_JA_04_Jun_2015__10_01_48.png](https://storage.googleapis.com/google-code-attachments/selenium/issue-4412/comment-6/_firefox_TimeBarDeparture_JA_04_Jun_2015__10_01_48.png)_

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I agree with jmle...@gmail.com this screenshot is in dom level. but I support this capability.
as one that fully utilizing GRID capabilities the Robot solution will not work for
me.

Reported by KobiGana on 2015-06-09 11:47:40

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

also facing the exactly same issue.and as per my requirement i should not handle the
popup/modal before taking the SS.please suggest some solution

Reported by arnabpatra143 on 2015-07-13 20:30:58

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Reported by luke.semerau on 2015-09-17 18:16:00

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 4, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant