Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

As the question clearly states, I used the screenshot coding in my catch block but it doesn't work.

try {
        LoginPage lp = new LoginPage(driver);
        lp.userName.sendKeys("administrator");
        lp.password.sendKeys("welcome");
        lp.id.click();

    } catch (Exception er) {
        File scrFile = ((TakesScreenshot) driver)
                .getScreenshotAs(OutputType.FILE);
        FileUtils
                .copyFile(
                        scrFile,
                        new File(
                                "/home/likewise-open/GLOBAL/xxx/Pictures/failure.png"));
    }

How to rectify and overcome the problem?

share|improve this question

put on hold as too broad by user246, Niels van Reijmersdal, Helping Hands, Kate Paulk, corsiKa 5 hours ago

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs. If this question can be reworded to fit the rules in the help center, please edit the question.

    
How doesn't it work? Where is the failure (in the code) that is happening? Are you trying to take a screenshot of if the login page doesn't happen or if the login fails? Also, build a function for your screenshots to avoid repetitive coding. –  PaulDonny Apr 4 '14 at 13:34
    
yea when it fails or throws some exception i dint get any screenshots at this point even i placed it in catch block. –  Emmanuel Angelo.R Apr 4 '14 at 13:35
1  
Well, this failure would occur as you are logging in. For example, if the page doesn't contain a place to input the username or password, of if id doesn't exist, you would get an exception. Set up a simple System.out.println in your catch to ensure you are actually throwing an error. –  PaulDonny Apr 4 '14 at 13:38
    
Have you debugged to see what srcFile is to ensure you're looking in the right place? –  Sam Woods Apr 12 '14 at 7:10
    
how you mention to use debugging as to use debugger or sysout in that line? –  Emmanuel Angelo.R Apr 14 '14 at 4:33