- open a list of report links
- foreach report, click a button or a link to launch a new browser to run the report
- maximize the new window
- capture the browser in an image
My method is:
[CodedStep(@
"Click 'ContentPlaceHolder1RgPRgRBtnRunButton'"
)]
public
void
getClientReports_CodedStep1()
{
List<HtmlTableRow> advancedReports =
new
List<HtmlTableRow>();
List<HtmlTableRow> classicReports =
new
List<HtmlTableRow>();
ReadOnlyCollection<HtmlInputButton> expandButtons = Pages.TargetPage.Find.AllByAttributes<HtmlInputButton>(
"class=rgExpand"
);
foreach
(HtmlInputButton expandBtn
in
expandButtons)
{
expandBtn.Click(
false
);
}
ReadOnlyCollection<HtmlTableRow> reportRow = Pages.VergeSolutionsLLC86.Find.AllByXPath<HtmlTableRow>(
"//table[@class='rgMasterTable']/tbody/tr[contains(@id,'ContentPlaceHolder1')]"
);
system = Pages.TargetPage.Find.ById(
"ctl00_ucHeader_lblSystem"
).InnerText;
org = Pages.TargetPage.Find.ById(
"ctl00_ucHeader_l_hco"
).InnerText;
foreach
(HtmlTableRow row
in
reportRow)
{
ReadOnlyCollection<HtmlTableCell> cells = row.Find.AllByTagName<HtmlTableCell>(
"td"
);
if
(cells.Count > 5)
{
if
(cells[5].InnerText ==
"Advanced"
)
{
reportName = cells[1].InnerText;
HtmlInputButton btnRun = cells[6].Find.AllByTagName<HtmlInputButton>(
"input"
)[0];
btnRun.Click(
false
);
System.Threading.Thread.Sleep(5000);
Manager.ActiveBrowser.Window.Maximize();
Manager.Log.CaptureBrowser(Manager.ActiveBrowser, system +
"."
+ org +
"."
+ reportName);
Manager.Browsers[1].Close();
}
if
(cells[5].InnerText ==
"Classic"
)
{
reportName = cells[1].InnerText;
HtmlAnchor btnRun = cells[6].Find.ByContent<HtmlAnchor>(
"Run"
);
btnRun.Click();
System.Threading.Thread.Sleep(5000);
Manager.ActiveBrowser.Window.Maximize();
Manager.Log.CaptureBrowser(Manager.ActiveBrowser, system +
"."
+ org +
"."
+ reportName);
Manager.Browsers[1].Close();
}
}
}
}
I want to capture all report outputs as images. This runs fine the first time through. The second time this runs, I get the error: "A generic error occurred in GDI+". The folder to which I am writing has write permissions (it wrote the file the first time through).
Any help with this error would be most helpful.
Thanks.
7 Answers, 1 is accepted
The error "A generic error occurred in GDI+" means the framework experienced an unknown problem grabbing a screen capture of the browser window (not that it had a problem creating/writing the file). I tried to reproduce this problem but was unable to.
One thing I do see your code is missing is the equivalent of "Connect to popup" that we normally have in a recorded test immediately following the click that opens the popup window. In code the equivalent are these two lines of code:
Manager.WaitForNewBrowserConnect("http://www.google.com/index.html", true, 5000);
Manager.ActiveBrowser.WaitUntilReady();
Cody
the Telerik team
See the code below.
[CodedStep(@"Capture Image of Report")]
public void getClientReports_CodedStep1()
{
List<
HtmlTableRow
> advancedReports = new List<
HtmlTableRow
>();
List<
HtmlTableRow
> classicReports = new List<
HtmlTableRow
>();
ReadOnlyCollection<
HtmlInputButton
> expandButtons = Pages.VergeSolutionsLLC86.Find.AllByAttributes<
HtmlInputButton
>("class=rgExpand");
foreach (HtmlInputButton expandBtn in expandButtons)
{
expandBtn.Click(false);
}
System.Threading.Thread.Sleep(3000);
ReadOnlyCollection<
HtmlTableRow
> reportRow = Pages.VergeSolutionsLLC86.Find.AllByXPath<
HtmlTableRow
>("//table[@class='rgMasterTable']/tbody/tr[contains(@id,'ContentPlaceHolder1')]");
system = Pages.VergeSolutionsLLC86.Find.ById("ctl00_ucHeader_lblSystem").InnerText;
org = Pages.VergeSolutionsLLC86.Find.ById("ctl00_ucHeader_l_hco").InnerText;
foreach(HtmlTableRow row in reportRow)
{
ReadOnlyCollection<
HtmlTableCell
> cells = row.Find.AllByTagName<
HtmlTableCell
>("td");
if (cells.Count > 5)
{
if (cells[5].InnerText == "Advanced")
{
reportName = cells[1].InnerText;
ReadOnlyCollection<
HtmlInputButton
> btnRun = row.Find.AllByTagName<
HtmlInputButton
>("input");
btnRun[0].Click();
Manager.WaitForNewBrowserConnect("/vstandard/reporting/QuestionReport/QuestionReportLoader.aspx", true, 15000);
Manager.ActiveBrowser.WaitUntilReady();
System.Threading.Thread.Sleep(5000);
Manager.ActiveBrowser.Window.Maximize();
Manager.Log.CaptureBrowser(Manager.ActiveBrowser, system + "." + org + "." + reportName);
Manager.Browsers[1].Close();
}
if (cells[5].InnerText == "Classic")
{
reportName = cells[1].InnerText;
ReadOnlyCollection<
HtmlAnchor
> btnRun = row.Find.AllByContent<
HtmlAnchor
>("Run");
btnRun[0].Click(false);
Manager.WaitForNewBrowserConnect("/vstandard/reporting/reports/questionreports/viewthreshold.aspx", true, 15000);
Manager.ActiveBrowser.WaitUntilReady();
System.Threading.Thread.Sleep(5000);
Manager.ActiveBrowser.Window.Maximize();
Manager.Log.CaptureBrowser(Manager.ActiveBrowser, system + "." + org + "." + reportName);
Manager.Browsers[1].Close();
}
}
}
}
// Add your test methods here...
}
Since I haven't seen your application I don't really know what you mean by "I do run in to this same GDI+ issue when I can actually get the HtmlInputButton to launch.". Can you elaborate on this?
I took the liberty of optimizing your code a bit. It should work just as well as what you have now. Here's the improved code:
[CodedStep(@
"Capture Image of Report"
)]
public
void
getClientReports_CodedStep1()
{
List<HtmlTableRow> advancedReports =
new
List<HtmlTableRow>();
List<HtmlTableRow> classicReports =
new
List<HtmlTableRow>();
ReadOnlyCollection<HtmlInputButton> expandButtons = Pages.VergeSolutionsLLC86.Find.AllByAttributes<HtmlInputButton>(
"class=rgExpand"
);
foreach
(HtmlInputButton expandBtn
in
expandButtons)
{
expandBtn.Click(
false
);
}
System.Threading.Thread.Sleep(3000);
ReadOnlyCollection<HtmlTableRow> reportRows = Pages.VergeSolutionsLLC86.Find.AllByXPath<HtmlTableRow>(
"//table[@class='rgMasterTable']/tbody/tr[contains(@id,'ContentPlaceHolder1')]"
);
system = Pages.VergeSolutionsLLC86.Find.ById(
"ctl00_ucHeader_lblSystem"
).InnerText;
org = Pages.VergeSolutionsLLC86.Find.ById(
"ctl00_ucHeader_l_hco"
).InnerText;
foreach
(HtmlTableRow row
in
reportRows)
{
if
(row.Cells.Count > 5)
{
if
(row.Cells[5].InnerText ==
"Advanced"
||
row.Cells[5].InnerText ==
"Classic"
)
{
reportName = row.Cells[1].InnerText;
if
(row.Cells[5].InnerText ==
"Advanced"
)
{
ReadOnlyCollection<HtmlInputButton> btnRun = row.Find.AllByTagName<HtmlInputButton>(
"input"
);
btnRun[0].Click();
Manager.WaitForNewBrowserConnect(
"/vstandard/reporting/QuestionReport/QuestionReportLoader.aspx"
,
true
, 15000);
}
if
(row.Cells[5].InnerText ==
"Classic"
)
{
ReadOnlyCollection<HtmlAnchor> btnRun = row.Find.AllByContent<HtmlAnchor>(
"Run"
);
btnRun[0].Click(
false
);
Manager.WaitForNewBrowserConnect(
"/vstandard/reporting/reports/questionreports/viewthreshold.aspx"
,
true
, 15000);
}
ActiveBrowser.WaitUntilReady();
System.Threading.Thread.Sleep(5000);
ActiveBrowser.Window.Maximize();
Log.CaptureBrowser(Manager.ActiveBrowser, system +
"."
+ org +
"."
+ reportName);
ActiveBrowser.Close();
}
}
}
}
Cody
the Telerik team
This code (even before optimization) is not working for me. There is a serious issue that will require connecting with someone from support on a 1-1 basis and is preventing this test from executing correctly. How do I do about doing that?
I will admit I did not expect the latest code sample I sent you to fix the problem you are running into. To assist you further I need to be able to reproduce this problem on my machine. Can I access your application directly or can you put together a test I can run here that shows this problem? Once I can reproduce it (and I have tried with no success so far) I will be able to get to the root cause and determine what it will take to fix it.
Greetings,Cody
the Telerik team
I can get you that information in a more private exchange. What is the best method to do that?
All of our paying and trial customers may file support tickets which are only viewable by you and us in technical support. However looking at your account, I don't see any active licenses. If your license holder can add you as a licensed user for Test Studio then you can file support tickets on your own.
The alternative we use for our free Telerik Testing Framework users is to send an email to support@telerik.com. I have access to the incoming emails and can grab the confidential information out of it.
Cody
the Telerik team