locked
Coded UI Test Save Screenshot exception: A generic error occurred in GDI+. RRS feed

  • Question

  • I've been struggling with this for a long time - I'm trying to save a screenshot but it always gives me A generic error occurred in GDI+.
    Image image = uploadProgress.CaptureImage();
    image.Save(Path.Combine(TestContext.TestResultsDirectory, "error.jpg");

    The test is data driven and has two iterations; The error comes up for the first iteration but successfully saves the image at the second iteration.

    Coded ui test should have permission to write to the directory, because the second run succeeded. So it should not be a permission problem.

    What are the other possible reasons to cause this problem here?


    Tony

    Monday, December 10, 2012 6:54 PM

Answers

  • Hello Tony,

    Glad to receive your reply.

    Based on your description, I think your code should be normal since the second and third iteration can save the image successfully.

    I suggest that you can enable tracing for “UITest” components through How To: Enable Tracing for “UI Test” Components to find more useful error messages and provide it for us, so we can make sure whether it is related to the test we record.

    If you have other Environment, I suggest that you record the same Coded UI Test for the same application and check the result. Maybe the issue is related to your test environment.

    In addition, you can try the following steps to see if they help:

    a) Try to run devenv /ResetSettings (in command prompt) to eliminate the related potential settings problem.

    b) Try disabling Add-ins (e.g. “Tools” | “Add-in Manager”) or run “devenv.exe /SafeMode”.This can eliminate the possibility that third party Add-ins or packages are causing problems.

    c) Try creating a new project. Sometimes corrupted project settings can cause problems.

    d) Try to reboot the operating system to safe mode. This can help to isolate whether any other applications are interfering with Visual Studio. Note that some features (like IIS) are not available under safe mode. Please check whether this can be applied or not.

    I hope this will be helpful to you.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 13, 2012 2:12 AM
    Moderator

All replies

  • Hello Tony,

    Thank you for your post.

    According to your description, I think that your code should be normal since the image can be saved successfully at the second iteration.

    I suggest that you can only execute one data record (just only one iteration) to check if the image can be saved successfully.

    In addition, can you provide us more detailed error messages so that we can further look at this issue?

    Also you can try another method (give dynamic name to the file so that it does not get overwritten everytime) provided by TejasJ in the following thread to check if you can get the different result.

    http://social.msdn.microsoft.com/Forums/br/vsautotest/thread/25df7f1c-4175-4616-8499-07358ef09041

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, December 11, 2012 4:28 AM
    Moderator
  • Hello Tony,

    What about your issue now? Could you get useful information from our reply?

    Would you mind letting us know the result of the suggestion?

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 12, 2012 8:32 AM
    Moderator
  • Hello Amanda,

    Sorry for the late reply. 

    I tried running the test with only one row of data twice, filled either with the original first row and the second row. Both runs fails to save the image. However, if I run the test with three rows of data, the first row will fail to save, but the two rows after will succeed in saving the image. It seems that only the first test run fails.

    Sorry I couldn't provide you with any more details..the image class is being very unfriendly, which the only info it provides me with is just "generic error occurred in GDI+"

    Thanks,

    Tony


    Tony

    Wednesday, December 12, 2012 6:28 PM
  • Hello Tony,

    Glad to receive your reply.

    Based on your description, I think your code should be normal since the second and third iteration can save the image successfully.

    I suggest that you can enable tracing for “UITest” components through How To: Enable Tracing for “UI Test” Components to find more useful error messages and provide it for us, so we can make sure whether it is related to the test we record.

    If you have other Environment, I suggest that you record the same Coded UI Test for the same application and check the result. Maybe the issue is related to your test environment.

    In addition, you can try the following steps to see if they help:

    a) Try to run devenv /ResetSettings (in command prompt) to eliminate the related potential settings problem.

    b) Try disabling Add-ins (e.g. “Tools” | “Add-in Manager”) or run “devenv.exe /SafeMode”.This can eliminate the possibility that third party Add-ins or packages are causing problems.

    c) Try creating a new project. Sometimes corrupted project settings can cause problems.

    d) Try to reboot the operating system to safe mode. This can help to isolate whether any other applications are interfering with Visual Studio. Note that some features (like IIS) are not available under safe mode. Please check whether this can be applied or not.

    I hope this will be helpful to you.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 13, 2012 2:12 AM
    Moderator
  • Hello Tony,

    What about your issue now? Could you get useful information from our reply?

    Would you mind letting us know the result of the suggestion?

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 14, 2012 12:17 AM
    Moderator