selenium.captureEntirePageScreenshot does not work but selenium.captureScreenshot works - selenium

I'm running Selenium with TestNG using Eclipse and Selenium RC. I used the command:
selenium.captureEntirePageScreenshot("\\test.png","");
but got the following error:
com.thoughtworks.selenium.SeleniumException: ERROR: Command execution failure. Please search the forum at http://clearspace.openqa.org for error details from the log window. The error message is: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath]
Can someone please suggest why this error is occuring? I have already tried the following:
1)Replaced "" (String kwargs parameter) with "background=#CCFFDD"
2)Running in Firefox in chrome mode
3)Changed the path to the following values and I'm still getting the error:
"\test.jpg",
"c:\test.jpg",
"c:\test.png",
"c:\folder1\test.png", (folder1 exists)
"c:\folder1\test.jpg",
4)Tried with - selenium.captureScreenshot("\test.png"); and it works fine but it does not solve my purpose and I dont want to use awt.
Can someone please suggest what could be wrong?
Thanks,
Mugen

Better yet...
I ran into a similar issue, where I only had access to a relative path instead of an absolute one. Here is the solution I came up with:
public void saveScreenshot(String methodName) {
if (methodName == null) {
methodName = String.valueOf(System.currentTimeMillis());
}
File f = new File("reports" + File.separator + methodName + ".jpg");
selenium.captureEntirePageScreenshot(f.getAbsolutePath(), "");
}
Which will put a screen shot of the entire page into the reports directory that is relative to the project. I am using the method name as the file name, or the current time if null is sent to the method.

Try this:
String path = System.getProperty("user.dir");
selenium.captureEntirePageScreenshot(path + "\\test.png", "");

To whomsoever it may concern,. the problem was solved after I kept fiddling with the code for a while and restarted my system. I came to know that captureEntirePageScreenshot works only on absolute paths so I made sure I kept trying with just that.

I got it working after looking at this page.
http://ashishbhatt.wordpress.com/2010/02/03/using-captureentirepagescreenshot-with-selenium/

Related

How to solve runing error in Groovy Script

I have tried to get the property value, where I have saved in the project-properties.
This is the code which I have tried out.log.info wasn't working fine ,but when I run the code separately(that means only first line..), It shows the valid answer in a popup.
def ProjectProp = testRunner.testCase.testSuite.project.getPropertyValue("Name")
log.info {"Project Property = "+ProjectProp}
I am new to SoapUI.I would be really grateful, If you will be able to help me out to find a solution for the error which i received as follows,
INFO:Script13$_run_closure1#1d32637
Your problem is unrelated to SoapUI. You obviously have difficulty with basic Groovy syntax. Seek some tutorial on Groovy.
Your specific case, should read:
def projectProp = testRunner.testCase.testSuite.project.getPropertyValue("Name")
log.info("Project Property = " + $projectProp)

Casperjs "casper.test property is only available using the `casperjs test` command" but not calling casper test

The error:
casper.test property is only available using the `casperjs test` command
Searched my entire codebase for "casper.test", "this.test", "#test", etc, and none are present. Looking at the casper code, one of these needs to be triggered for this error to be raised.
The error is intermittent and only occurs on some casper runs. Has anyone else gotten this bug? I'm running 1.1.0-beta3.
You can add
phantom.casperTest = true;
at the top of the test file.
Have you launch your script like this ?
casperjs test yourScript.js
It has nothing to do with launching it. Not sure why, but I also received this error on my code before writing to file. It went away after removing...
JSON.stringify(obj);
Again, I dont know what caused the issue. And it may be something else causing it for you. But if you find which piece of code is causing it, I have a solution.
My solution:
Use a handler for errors with a basic variable switch and turn off the error log for that portion of the step.
casper.on("error", function(err) {
if(custLog) {console.log(err);} //log the error
});
and in the step...
casper.then(function() {
custLog = false;
fs.write(fileName, JSON.stringify(content), 'w');
custLog = true;
});
You may or may not need to order the reorder the inner stack there.

FileUploadDialogHandler()

I am trying to automate a web app which involves selecting an existing file using a fileuploaddialoghandler() method and entering the full path in the file name dropdown then Open click.
However, when I attempt this using this code
FileUploadDialogHandler fileupload = new FileUploadDialogHandler(#"C:\TIFFiles\Testtif.TIF");
//browser.WaitForComplete();
using (new UseDialogOnce(browser.DialogWatcher, fileupload))
{
newIee.Button(Find.ById("ctl00_WebPartManager1_FileUpload_FileBrowse")).ClickNoWait();
browser.AddDialogHandler(fileupload);
browser.WaitForComplete();
browser.RemoveDialogHandler(fileupload);
}
It does not work.
What else should I be doing?
Thanks much!
W
I just have one question about your code... What is newIee? I can't tell by looking at the code if newIee is attached to browser. Other than that, your FileUpdateDialogHandler should be fine.
If you can provide the code where you declare newIee, it might add me in determining if it's a factor causing your code not to work properly.

SPWeb.GetListItem COMException on first call - second is ok

I'm trying to use SPWeb.GetListItem() to get an item by a known URL (MSDN).
So basically I'm doing the following:
using (SPSite spSite = SPContext.Current.Site)
{
using (SPWeb spWeb = spSite.RootWeb)
{
SPListItem spListItem = spWeb.GetListItem
("/sites/testSite/Lists/testList/Folder/Subfolder");
}
}
in case you are wondering, I'm trying to get the folder "Subfolder" to do stuff with it.
The problem is that the first time I call this, I get a COMExpeption:
Cannot complete this action.
Please try
again.<nativehr>0x80004005</nativehr><nativestack></nativestack>
Description: An unhandled exception
occurred during the execution of the
current web request. Please review the
stack trace for more information about
the error and where it originated in
the code.
Exception Details:
System.Runtime.InteropServices.COMException:
Cannot complete this action.
There are some reports about the COMException happening because you need to use the full relative site URL, so instead of /Lists/testList/Folder/SubFolder, you need to use /sites/testSite/Lists/... - I'm doing just that. I also tried using the absolute URL (http://sharepoint/sites/...). The problem remains: I get the COMException when trying to get the spListItem for the first time.
When I try to run the code again after the Exception, the SPListItem is received just fine. Also all subsequent calls work - only the first one fails.
AmI doing some initializing wrong or something like that?
Perhaps try SPWeb.GetFolder() instead... but again it depends on what exactly you want to do with the Folder. Seems strange though that you're using a method used for getting list items on a Folder.
http://msdn.microsoft.com/en-us/library/ms461547.aspx
Try to instantiate the web where the list item is located - _uiserWeb.
I tryed Site.RootWeb.GetListItem(item_url) - it gave me null first time after code redeployment and was fine second time.
_item = _userWeb.GetListItem(item_url)

Selenium - getBodyText() return empty string

I'm trying to save the whole html page with getBodyText into a String and then write it to a file (.txt). However when I check the file, it's empty. Here's my code:
String store_report = selenium.getBodyText();
File f = new File("C:/folder/" + "report" + ".txt");
FileWriter writer = new FileWriter(f);
writer.append(store_report);
System.out.println("Report Created is in Location : " + f.getAbsolutePath());
I think you just forgot to flush the FileWriter:
writer.flush()
This of course happens automatically if you properly close the FileWriter.
Well first, I'd strongly encourage you to consider a try/finally block which closes that FilreWriter :)
Can you confirm you see the getBodyText() command actually being sent to the Selenium server? Have you seen it run in the command log that is embedded inside the browser? Do you have a public URL that reproduces the problem?
Thanks everyone for your help. I think what happened was I didn't close the FileWriter correctly, now it's working.