Capturing a screenshot - ruby

I'm unable to figure out how to capture a screenshot when a test fails in watir. Please any help/examples?
Here is an exaample of my code
testName = "Entered 000000 - Invalid Unit Number"
browser.text_field(:name => 'unitNumber').set '000000'
browser.button(:name => "OpRetrieve").click
message=browser.text_field(:id => 'messages').text
if message == "Invalid Unit Number"
f1.puts "PASSED #" + testId.to_s + ": " + testName
else
f1.puts "FAILED #" + testId.to_s + ": " + testName + ". Message: " + message
"Capturd screenshot"
end
testId=testId+1

This should do it:
browser.screenshot.save 'screenshot.png'
For more information see http://watir.github.io/docs/screenshots/

This works for phantomjs, I guess it should work for any driver.
browser.driver.screenshot.save 'wtf.png'
Here's a working example I made before. It does something like:
page.driver.render 'test.pdf'

You can achieve like this also.
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("C:\\screenShot1.png"));
for using these you need to import below classes
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.TakesScreenshot;

Related

ODI - Call SQLLDR via Jython on Windows Shell

I'm testing some interfaces with Oracle Data Integrator 11g on Windows 7.
All the interfaces use the LKM MSSQL to Oracle (BCP/SQLLDR), while running them I got an error on the "Call SQLLDR via Jython" command. After some invesetigation I found that the root of the problem was the following line of code:
exitCode = os.system(sqlldr + " control=" + tempSessionFilePrefix + ".ctl log=" + tempSessionFilePrefix + ".log " + "userid=" + "<% out.print(odiRef.getInfo("DEST_USER_NAME")); %>" + "/" + "<% out.print(odiRef.getInfo("DEST_PASS")); %>" + tnsnameOption + " > " + tempSessionFilePrefix +".out" );
It should run on the Windows Shell a string in the form of:
sqlldr control=control_file.ctl log=log_file.log userid=ODI_STAGE/ODI_STAGE > shell_output.out
I did run the string generated directly on the command prompt and it worked without any problem.
So after playing a bit with the code, I couldn't make the os.system working so I replaced it with subprocess.call. I also have to remove the last part of the string where it attempts to save the ouput of the command prompt (> shell_output.out) to make the whole thing work:
exitCode = subprocess.call([sqlldr, "control=" + tempSessionFilePrefix + ".ctl", "log=" + tempSessionFilePrefix + ".log", "userid=" + "<% out.print(odiRef.getInfo("DEST_USER_NAME")); %>" + "/" + "<% out.print(odiRef.getInfo("DEST_PASS")); %>" + tnsnameOption], shell=True);
This one works smoothly.
Regarding the shell output, I suspect that the problem is the string part that starts with the '>' charcater that is parsed as part of the arguments of SQLLDR instead of a command to the prompt.
Now, while I can live without it, I would like to ask if someone knows any simple workaround to get also the shell output.
Ok I was finally able to get also the shell output.
I edited the "Call SQLLDR via Jython" command with the following:
from __future__ import with_statement
import subprocess
...
with open(tempSessionFilePrefix + ".out", "w") as fout:
exitCode = subprocess.call([sqlldr, "control=" + tempSessionFilePrefix + ".ctl", "log=" + tempSessionFilePrefix + ".log", "userid=" + "ODI_STAGE" + "/" + "<#=snpRef.getInfo("DEST_PASS") #>" + tnsnameOption], stdout=fout, shell=True);
Now everything work as intended.

Page Loads but Uninitialized Constant in Controller

ok I have this class; the page loads and everything.
class HumanResources::AttendancePerformance::AttendancesController < HumanResources::AttendancePerformanceController
def index
query = generic_table_aggregated_queries('attendances','attendances.created_at')
begin
#attendances = Attendance
.includes(employee: [:actor])
.joins(employee: [:actor])
.where("actors.name LIKE ? OR " +
"attendances.id LIKE ? OR " +
"attendances.timein LIKE ? OR " +
"attendances.timeout LIKE ? OR " +
"attendances.remark LIKE ? OR " +
"attendances.updated_at LIKE ? OR " +
"attendances.created_at LIKE ?",
"%#{query[:search_field]}%",
"%#{query[:search_field]}%",
"%#{query[:search_field]}%",
"%#{query[:search_field]}%",
"%#{query[:search_field]}%",
"%#{query[:search_field]}%",
"%#{query[:search_field]}%")
.order(query[:order_parameter] + ' ' + query[:order_orientation])
#attendances = Kaminari.paginate_array(#attendances).page(params[:page]).per(query[:current_limit])
rescue => ex
flash[:general_flash_notification] = "Error has Occured" + ex.to_s
end
render 'human_resources/attendance_performance/attendances/index'
end
Yep I know its a bit long; just to make sure I did not miss everything, I am certain error is around here but I cannot find so. The page loads. I just dont know where and why is it saying
uninitialized constant HumanResources::AttendancePerformance::AttendancesController::Attendance
I presume its the "Attendance" model but it has always worked before... Where is the error? Does it have something to do with the naming of the model and the controller being similar?

How to insert line break in a return statement for D3

I have the following code d3 code:
tooltip.select("#popupCount").text(function(){
if (varToGraph == "rough_top_cost"){
return " " + textValue + ": $" + addCommas(allCountyData[countyName][varToGraph]) + "\n" +
"Count:"
}})
I want the word count to appear on a new line. However, the above code results in everything being on one line. How can I get the output to be on two lines?
Thanks,
AH
Untested answer, but FWIW this may get close;
tooltip.select("#popupCount").html(function(){
if (varToGraph == "rough_top_cost"){
return " " + textValue + ": <br/>$" + addCommas(allCountyData[countyName][varToGraph]) + "\n" +
"Count:"
}})
Working from the example provided on page 80 of D3 Tips and Tricks which includes tooltips with line breaks.
Uses html element instead of text which allows line breaks. Check out the document for more detail.

Carrying an ID with strings to a next page

I'm trying to carry the ID to the next page, but all i manage to get is review.php?ID= without the ID.
Here is the code:
html = html + "Name:" + name + "Type : " + type + "Location : " + location + '<input type="button" value="Write a review!" onclick=parent.location="review.php?ID=" ('+ ID +') />' + "<br/>";
Thanks in advance for any help.
There's a couple things wrong here. You have mismatched quotes (single and double), and I'm pretty sure the id shouldnt have spaces round it with parens. The embeded quotes need to be escaped, too
something like this:
html = html + "Name:" + name + "Type : " + type + "Location : " + location +
"<input type='button' value='Write a review!' onclick='parent.location=\"review.php?ID=("+ID+")\" />" + "<br/>";

Issue using Oracle date function with Spring's NamedParamenterJdbcTemplate

I'm having an issue trying to get my SQL query which works fine in SQL Developer (Oracles free database tool) to also work using Spring's NamedParameterJdbcTemplate class.
My query is:
String sql = " SELECT COUNT(*) FROM ( " +
" SELECT FE.USR_ID, MAX(FE.DATE_FIRST_SUB) AS SUB_DATE " +
" FROM FC, FE " +
" WHERE FC_STATUS = 'MEMBER' " +
" AND FC.FC_SPC_ID = :spcId " +
" AND FE.FE_USR_ID = FC.FC_USR_ID " +
" AND FE.DATE_FIRST_SUB IS NOT NULL " +
" GROUP BY FE_USR_ID " +
" ) " +
" WHERE SUB_DATE BETWEEN TO_DATE('01-JUN-2011', 'DD-MON-YYYY') AND TO_DATE('01-JUL-2011', 'DD-MON-YYYY') ";
It has something to do with my dates, formatting perhaps? When I don't use the WHERE clause in the outer select it works, when it's included 0 is returned from the count - as I mentioned running the SQL directly returns expected results.
Any advice?
Thanks.
Oh my, I was in fact looking at the wrong database!!

Resources