Extract text from a specific row in the table with Capybara - capybara

Friends for me to finish my test and I just need to extract the text of the tooltip from the specific line of the table. Thomas Walpole has helped me a lot. Now I can read the excel spreadsheet and I will validate with each line of the application.
****** I read excel and get the first line *************
Spreadsheet.client_encoding = 'UTF-8'
book = Spreadsheet.open('c:/temp/Pasta1.xls', "r")
sheet = book.worksheet 0
#sheet.each do |row|
pp hydrometer = sheet.row(1)
****** reading the specific row of the table *************
I just need to extract this text save in a variable and validate with the hydrometer variable that stores the row of my excel sheet
expect(page).to have_css('tr.tvRow:nth-child(2) .tvCell:nth-child(6) img[tooltip="Invisível"]')
see the code
<tr oncontextmenu="if(!this.cancelEvent) {sendEvent(0,event,this,true,0,'TVXWFMTGINSTATOCE','bdb','BtnDropDownRow#',1,'','','');return false;} delete this.cancelEvent;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'TVXWFMTGINSTATOCE','bdb','Select#',1,'','','');" onmousedown="if(event.ctrlKey) this.cancelEvent=true;" class="tvRow tvRowEven tvRoll tvRowSelected" style="cursor:pointer;">
<td valign="center" align="left" class="tvCell">XWFMSLETMATRICOLA_E</td>
<td valign="center" align="left" class="tvCell"> Nº Hidrômetro</td>
<td align="left" class="tvCell" valign="center" nowrap=""></td>
<td valign="center" align="left" class="tvCell"></td>
<td align="left" width="1" class="tvCell" valign="center" tooltip="[AIMPMATRICOLA]">
<button onclick="event.cancelBubble=true;sendEvent(0,event,this,searchImage(this),0,'','bdb','AUTOFILLBTN#',1,'','','','');" class="but butAct" tabindex="0" tooltip="Preenchimento automático ativado" type="BUTTON">
<div><img src="r/std/icons/checkboxselected64.png" class="icon" draggable="false" align="absmiddle"></div>
</button>
</td>
<td valign="center" align="center" class="tvCell"><img tooltip="Invisível" src="r/std/static/minus16.gif"></td>
<td align="center" width="30" style="line-height:1px;padding:0px;" class="tvCell" valign="center">
<div onclick="event.cancelBubble=true;sendEvent(0,event,this,searchImage(this),0,'','bdb','BtnDropDownRow#',1,'','','','');" class="but">
<div><img src="r/std/icons/menu64.png" class="icon" draggable="false" align="absmiddle"></div>
</div>
</td>
</tr>
<tr oncontextmenu="if(!this.cancelEvent) {sendEvent(0,event,this,true,0,'TVXWFMTGINSTATOCE','bdb','BtnDropDownRow#',2,'','','');return false;} delete this.cancelEvent;" onclick="if(notSelecting()) sendEvent(0,event,this,true,0,'TVXWFMTGINSTATOCE','bdb','Select#',2,'','','');" onmousedown="if(event.ctrlKey) this.cancelEvent=true;" class="tvRow tvRowOdd tvRoll" style="cursor:pointer;">
<td valign="center" align="left" class="tvCell">XWFMSLETLETTURA_E</td>
<td valign="center" align="left" class="tvCell"> Leitura</td>
<td align="left" class="tvCell" valign="center" nowrap=""></td>
<td valign="center" align="left" class="tvCell"></td>
<td align="left" width="1" class="tvCell" valign="center" tooltip=""></td>
<td valign="center" align="center" class="tvCell"><img tooltip="Invisível" src="r/std/static/minus16.gif"></td>
<td align="center" width="30" style="line-height:1px;padding:0px;" class="tvCell" valign="center">
<div onclick="event.cancelBubble=true;sendEvent(0,event,this,searchImage(this),0,'','bdb','BtnDropDownRow#',2,'','','','');" class="but">
<div><img src="r/std/icons/menu64.png" class="icon" draggable="false" align="absmiddle"></div>
</div>
</td>
</tr>

If hydrometer contains the text you're checking for just interpolate it in the CSS selector you're using
expect(page).to have_css("tr.tvRow:nth-child(2) .tvCell:nth-child(6) img[tooltip='#{hydrometer}']")
Since your going through a loop you'd probably also want to interpolate the row number but I don't know what variable you have that in
expect(page).to have_css("tr.tvRow:nth-child(#{row_number}) .tvCell:nth-child(6) img[tooltip='#{hydrometer}']")
If you really want to get the tooltip text for a specific row you would do
text = find("tr.tvRow:nth-child(2) .tvCell:nth-child(6) img[tooltip]")[:tooltip] # get the tooltip attribute value from the 2nd row
but doing that and then comparing it to some other string is bad practice and will lead to flaky tests. It is much better to do the have_css shown above

Related

Table dropdown with bootstrap 5 not working

I am trying to show product items when button order detail is pressed, but its not working in any way I tried, it's possible to make it work with bootstrap 5 or I have to do it with javascript ?
Useless information for "It looks like your post is mostly code; please add some more details." : In the first foreach I am displaying information from the order, then the second foreach is retrieving product id and quantity from a different table that contain order id and the third foreach is getting product where id from the second foreach in order to display product details
<table class="table border">
<thead>
<tr>
<th class="h4" style="width: 18%">Order Number</th>
<th class="h4">Date</th>
<th class="h4">Total</th>
<th class="h4">Status</th>
<th class="h4"></th>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<?php
foreach ($order as $row_order) {
$order_status = intval($row_order->status);
?>
<td class="fw-bold">{{ $row_order->id }}</td>
<td class="fw-bold">{{ $row_order->added_on }}</td>
<td class="fw-bold">{{ $row_order->order_total }} $</td>
<td class="fw-bold"><?php if($order_status == 0){ ?>
Not Paid
<?php }elseif ($order_status == 1) { ?>
Paid
<?php }elseif ($order_status == 2) { ?>
Shipped
<?php }elseif ($order_status == 3) { ?>
Delivered
<?php } ?>
</td>
<td></td>
{{-- <td><a class="btn btn-primary" href="">Order Detail</a></td> --}}
<div class="btn-group">
<td>
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false">
Order Detail
</button>
</td>
#foreach (\App\Models\Order_product_size_color::where('order_id', '=', $row_order->id)->get() as $order_variant)
#foreach (\App\Models\Product_size_color::where('id', '=', $order_variant->product_size_color_id)->get() as $variant)
<div class="dropdown-menu">
<td class="border-0 p-0 dropdown-item">
<tr>
<td class="border-0"><img class="rounded" src="{{ asset('storage/'. $variant->image1->product_image) }}" alt="" style="width: 80px; height: 90px;"></td>
<td class="fw-bold border-0">{{ $variant->product->product_name }}</td>
<td class="border-0">{{ $order_variant->count }} products</td>
<td class="fw-bold border-0">Size: {{ $variant->size->size_name }}</td>
<td class="fw-bold border-0">Color: {{ $variant->color->color_name }}</td>
<td class="fw-bold border-0">${{ $variant->product->price }}</td>
</tr>
</td>
</div>
#endforeach
#endforeach
</div>
<tr>
<td class="fw-bold">Delivery Address:</td>
<td class="fw-bold">{{ $row_order->address }}</td>
</tr>
</tr>
<?php }//end foreach ?>
</tbody>
</table>

error when sending jelly template using email ext plugin with jenkins

I want to send the cppcheck report through email but I had never used the email ext plugin before, so I found this Sending Cppcheck result/report on email from Jenkins using email-ext plugin with a nice jelly template to do so, I have also followed the steps in the documentation, to send my own templates in a pipeline job, I have created my template with a .jelly extension and set it into my $JENKINS_HOME\email-templates although the email-templates folder did not exist, so I am not sure if it should be created beforehand just by installing the plugin or what I am missing. This is my stage
stage('Mail cppcheck report') {
steps{
script{
def mailRecipients = "email#email.net"
def jobName = currentBuild.fullDisplayName
mimeType: 'text/html'
emailext body: '''${JELLY_SCRIPT, template="custom"}''',
subject: "[Jenkins] ${jobName}",
to: "${mailRecipients}"
}
}
}
And this is the template I want to use but I keep getting the following error JellyException: Could not parse Jelly script : null even though the email is sent the email body is just the error mentioned above.
<j:set var="cppcheckAction" value="${it.getAction('org.jenkinsci.plugins.cppcheck.CppcheckBuildAction')}" />
<j:if test="${cppcheckAction!=null}">
<j:set var="cppcheckResult" value="${cppcheckAction.getResult()}" />
<j:if test="${cppcheckResult!=null}">
<TABLE width="100%">
<TR><TD class="bg1" colspan="2"><B>CPPCHECK RESULT</B></TD></TR>
<TR bgcolor="white"><TD class="test_failed" colspan="2"><B><li>Found: ${cppcheckResult.report.getNumberTotal()}</li></B></TD></TR>
</TABLE>
<BR/>
</j:if>
</j:if>
I have also tried with some other templates and I get no error but I receive an empty email instead, like with this one.
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
<html>
<j:set var="cppcheckAction" value="${it.getAction('org.jenkinsci.plugins.cppcheck.CppcheckBuildAction')}" />
<j:if test="${cppcheckAction!=null}">
<j:set var="cppcheckResult" value="${cppcheckAction.getResult()}" />
<j:if test="${cppcheckResult!=null}">
<h2>Summary</h2>
<style type="text/css">
#cppcheckStatistics { width: auto; }
#cppcheckStatistics .number { text-align: right; }
</style>
<table class="pane sortable" id="cppcheckStatistics">
<thead>
<tr>
<td class="pane-header">Severity</td>
<td class="pane-header">Count</td>
<td class="pane-header">Delta</td>
</tr>
</thead>
<tbody>
<tr>
<td class="pane">Error</td>
<td class="pane number">${cppcheckResult.statistics.getNumberErrorSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberErrorSeverity()}</td>
</tr>
<tr>
<td class="pane">Warning</td>
<td class="pane number">${cppcheckResult.statistics.getNumberWarningSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberWarningSeverity()}</td>
</tr>
<tr>
<td class="pane">Style</td>
<td class="pane number">${cppcheckResult.statistics.getNumberStyleSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberStyleSeverity()}</td>
</tr>
<tr>
<td class="pane">Performance</td>
<td class="pane number">${cppcheckResult.statistics.getNumberPerformanceSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberPerformanceSeverity()}</td>
</tr>
<tr>
<td class="pane">Portability</td>
<td class="pane number">${cppcheckResult.statistics.getNumberPortabilitySeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberPortabilitySeverity()}</td>
</tr>
<tr>
<td class="pane">Information</td>
<td class="pane number">${cppcheckResult.statistics.getNumberInformationSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberInformationSeverity()}</td>
</tr>
<tr>
<td class="pane">No category</td>
<td class="pane number">${cppcheckResult.statistics.getNumberNoCategorySeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberNoCategorySeverity()}</td>
</tr>
</tbody>
<tfoot>
<tr class="sortbottom">
<td class="pane-header">Total</td>
<td class="pane-header number"><B>${cppcheckResult.report.getNumberTotal()}</B></td>
<td class="pane-header number"><B>${cppcheckResult.getDiff().getNumberTotal()}</B></td>
</tr>
</tfoot>
</table>
</j:if>
</j:if>
</html>
</j:jelly>
However if I use the default template emailext body: '''${JELLY_SCRIPT, template="html"}''' it works fine

How to retrieve column that is dynamically displayed in a table form

I would like to retrieve each row of a datatable that is dynamically created. I created a form with the post method to get these rows but I don't how what to write in my view function to have these in a panda DataFrame.
<form action="{%url 'livedb_model:validation' property.id roomtype.id %}?normal_price={{normal_price}}&week_day_multi={{week_day_multi}}&week_end_multi={{week_end_multi}}&max_discount={{max_discount}}&max_markup={{max_markup}}&coccCategory={{coccCategory}}&agressiveness={{agressiveness}}" method="post">
{% csrf_token %}
<input class='btn btn-primary btn-large btn-block align-self-center'type='submit' value='submit'>
<div id="datatable" class="table-editable align-self-stretch">
<table class="table table-bordered table-responsive-md table-striped text-center">
<tr>
<th class="text-center">Date</th>
<th class="text-center">Availability</th>
<th class="text-center">Current Price</th>
<th class="text-center">Current Occupancy</th>
<th class="text-center">Advised Price</th>
</tr>
{% for day in invdf.itertuples %}
<tr>
{% if day.availability.room %}
<td class="pt-3-half" id='date'>{{day.date|date:'M d,Y'}}</td>
<td class="pt-3-half">{{day.allotment}}</td>
<td class="pt-3-half">{{day.price|floatformat:2}}</td>
<td class="pt-3-half">{{day.occupancy|floatformat:2}}</td>
<td class="pt-3-half" id='price_advised' contenteditable="true">{{day.price_advised|floatformat:2}}</td>
{% else %}
<td class="pt-3-half" id='date'>{{day.date|date:'M d,Y'}}</td>
<td class="pt-3-half">{{day.allotment}}</td>
<td class="pt-3-half">{{day.price|floatformat:2}}</td>
<td class="pt-3-half">{{day.occupancy|floatformat:2}}</td>
<td class="pt-3-half" id='price_advised' contenteditable="true">{{day.price_advised|floatformat:2}}</td>
{% endif %}
</tr>
{% endfor%}
</div>
</form>
For instance I would like to write something like in my view:
def validation(request,id,rt_id):
if request.method=='POST':
price_advised=request.POST.get(ADVISED PRICE COLUMN)
Could you help me on this?
Thank you
you can use javascript add parameter before submitting form

jQuery UI dialog - cannot insert table in dialog contents

I have a simple web page where for each row of data, I can pop up a jQuery UI dialog with the details of that row. Since there can be multiple rows in the sub-query a table is the best choice. The result is that I get an empty dialog box, and the table contained in that div (the one for the dialog) appears at the bottom of the page, whether the row is clicked to activate the dialog. Everything else works perfectly, the event for the click, the dialog popup, the passing of the right id for the div, all perfect.
But the dang table (the one inside the dialog, with the class of 'inner-table') appears at the bottom of the page, right off the bat.
The HTML is created in Groovy, with the HTMLMarkupBuilder, and the resulting HTML looks like the following:
<html>
<head>
<title>NAS Execution Groovy Servlet</title>
<script type='text/javascript' src='js/jquery.js'></script>
<script type='text/javascript' src='js/jquery-ui-1.8.23.custom.min.js'></script>
<script type='text/javascript' src='js/jquery.dataTables.min.js'></script>
<script type='text/javascript' src='js/executions.js'></script>
<link rel='stylesheet' type='text/css' href='css/jquery.dataTables_themeroller.css'></link>
<link rel='stylesheet' type='text/css' href='css/jquery-ui.css'></link>
<link rel='stylesheet' type='text/css' href='css/nas.css'></link>
</head>
<body>
<div id='results' class='execution-results'>
<p id='rpt-header'>
<span class='rpt-header-txt'>Backup Schedule Report for </span>
<span class='rpt-header-asset'>ret2w089n1t1</span>
</p>
<table id='nas-table'>
<thead>
<tr class='table-header'>
<th class='hidden'>Backup ID</th>
<th>Schedule Name</th>
<th>Backup Product</th>
<th>Size Mb</th>
<th>Start Time</th>
<th>Duration</th>
<th>Expiration Date</th>
<th>Mon 17</th>
</tr>
</thead>
<tbody>
<tr class='row'>
<td class='hidden'>12345678</td>
<td class='row-data'>null</td>
<td class='row-data'>Product One</td>
<td id='size-mb' class='row-data'>601.31</td>
<td class='row-data'>00:09:03</td>
<td class='row-data'>158 secs</td>
<td class='row-data'>2012-10-01</td>
<td class='row-center'>
<img id='success-fail' src='img/success.gif'></img>
</td>
</tr>
<tr class='row'>
<td class='hidden'>23456789</td>
<td class='row-data'>PolicyName</td>
<td class='row-data'>Product Two</td>
<td id='size-mb' class='row-data'>995.92</td>
<td class='row-data'>20:09:00</td>
<td class='row-data'>191 secs</td>
<td class='row-data'>2012-10-01</td>
<td class='row-center'>
<img id='success-fail' src='img/success.gif'></img>
</td>
</tr>
<div id='dialog-23456789' class='details-dialog'>
<table class='inner-table'>
<thead>
<tr>
<th>JOB_TYPE_NAME</th>
<th>VENDOR_STATUS_NAME</th>
<th>KILOBYTES</th>
</tr>
</thead>
<tbody>
<tr>
<td>Incr Backup</td>
<td>Successful</td>
<td>1019821</td>
</tr>
</tbody>
</table>
</div>
</tbody>
</table>
</div>
</body>
</html>
The jQuery for this is pretty simple; it uses the id from the row clicked on, and pops up a dialog window. That works fine, but the table that is contained in that div is actually at the bottom of the screen, even before anything is clicked:
$(document).ready(function() {
$('#nas-table').dataTable( {
"bJQueryUI": true,
"aaSorting": [[4, 'asc']]
} );
$('.row').live("click", function(){
var target = $(this);
var backupId = $(this).children(":first").html();
var thisId = '#dialog-' + backupId;
$(thisId).dialog(
{
title: "Backup Job Detail",
width: 800,
height: 450
}
);
$(thisId).dialog("open");
$(thisId).dialog("widget").position({
my: 'left top',
at: 'left bottom',
of: target
});
});
} );
At first, I thought the Groovy HTMLMarkupBuilder was outputting the DOM before everything happened, but when I do a view source, copy it to a file, and open the file in my browser, I get the same result.
I would appreciate any help with this. I asked this question earlier, in case you want to complain about that, but I had to follow up some other potential issues in the Groovy code, which I resolved. This example is more complete, and represents exactly what my code will do.
Brian
The problem is that you have a div nested within a table outside of a TR and TD, which will cause the rendering and DOM to be a bit wrong. If you adjust the html so that it resembles something like this it will work:
<div id='results' class='execution-results'>
<p id='rpt-header'>
<span class='rpt-header-txt'>Backup Schedule Report for </span>
<span class='rpt-header-asset'>ret2w089n1t1</span>
</p>
<table id='nas-table'>
<thead>
<tr class='table-header'>
<th class='hidden'>Backup ID</th>
<th>Schedule Name</th>
<th>Backup Product</th>
<th>Size Mb</th>
<th>Start Time</th>
<th>Duration</th>
<th>Expiration Date</th>
<th>Mon 17</th>
</tr>
</thead>
<tbody>
<tr class='row'>
<td class='hidden'>12345678</td>
<td class='row-data'>null</td>
<td class='row-data'>Product One</td>
<td id='size-mb' class='row-data'>601.31</td>
<td class='row-data'>00:09:03</td>
<td class='row-data'>158 secs</td>
<td class='row-data'>2012-10-01</td>
<td class='row-center'>
<img id='success-fail' src='img/success.gif'></img>
</td>
</tr>
<tr class='row'>
<td class='hidden'>23456789</td>
<td class='row-data'>PolicyName</td>
<td class='row-data'>Product Two</td>
<td id='size-mb' class='row-data'>995.92</td>
<td class='row-data'>20:09:00</td>
<td class='row-data'>191 secs</td>
<td class='row-data'>2012-10-01</td>
<td class='row-center'>
<img id='success-fail' src='img/success.gif'></img>
</td>
</tr>
</tbody>
</table>
<div id='dialog-23456789' class='details-dialog' style="display:none;">
<table class='inner-table'>
<thead>
<tr>
<th>JOB_TYPE_NAME</th>
<th>VENDOR_STATUS_NAME</th>
<th>KILOBYTES</th>
</tr>
</thead>
<tbody>
<tr>
<td>Incr Backup</td>
<td>Successful</td>
<td>1019821</td>
</tr>
</tbody>
</table>
</div>
</div>
The trick is to move the div outside of the parent table and also you need to set the display:none on the details table or it will be shown when the page is rendered.

TCPDF, php variable values do not appear on the saved pdf file

I created a pdf using TCPDF and I filled it with some php variables and the current date using heredoc syntax
Everything is fine when the pdf is generated and viewed in the browser, but on the saved pdf file the php variable values are not shown, only the date...
I declare my variables at the top like so:
$name = $_POST['name'];
$score = $_POST['percentage'];
$ku_number = $_POST['ku-number'];
$date = Date('d - m - Y');
Only $date is shown on the saved pdf.
Any suggestion?
Thank you
Edit: code to pass the variables to TCPDF
// Print a text
$html = <<<EOF
<!-- EXAMPLE OF CSS STYLE -->
<style>
table{
text-align:center;
color:#000;
}
</style>
<table id="name" cellpadding="0">
<tr>
<td width="10" height="80"> </td>
<td width="620"> </td>
<td width="10"> </td>
</tr>
<tr>
<td> </td>
<td width="620">$name</td>
<td> </td>
</tr>
<tr>
<td width="10"> </td>
<td> </td>
<td width="10"> </td>
</tr>
</table>
<table id="score" cellpadding="0" >
<tr>
<td width="10" height="180"> </td>
<td width="620"> </td>
<td width="10"> </td>
</tr>
<tr>
<td> </td>
<td width="620">$score</td>
<td> </td>
</tr>
<tr>
<td width="10" height="207"> </td>
<td> </td>
<td width="10"> </td>
</tr>
</table>
<table id="ku-number" cellpadding="0" >
<tr height="2">
<td width="50" height="2"></td>
<td width="620" height="2"></td>
<td width="10" height="2"></td>
</tr>
<tr>
<td> </td>
<td width="620" height="20"></td>
<td> </td>
</tr>
<tr>
<td width="50"> </td>
<td>$ku_number</td>
<td > </td>
</tr>
</table>
<table id="date" cellpadding="0" >
<tr height="2">
<td width="50" height="2"></td>
<td width="620" height="2"></td>
<td width="10" height="2"></td>
</tr>
<tr>
<td> </td>
<td width="420" height="20">$date</td>
<td> </td>
</tr>
<tr>
<td width="50"> </td>
<td></td>
<td > </td>
</tr>
</table>
EOF;
$pdf->writeHTML($html, true, false, true, false, '');
//Close and output PDF document
$pdf->Output('certificate.pdf', 'I');
I had the same problem. I found a solution by experimenting things myself mentioned as follows:
Please use concatenation to break $html string into parts. This will surely solve the problem. e.g. I used something like this:
$html = 'HTML CONTENT BREAKS HERE' . $variable_name . 'HTML CONTENT CONTINUES HERE' ;
Normally, most developers will use PHP variable within $html value,
$html = 'HTML CONTENT echo php variable HTML CONTENT' ;
I hope this will work.
Using $_SESSION to store the variables before outputting the PDF solved the problem
Credits go to Yuri Stuken
For more refined results:
Outputting the final PDF:
When you’ve finished creating all required cells, images, links, text etc. you have to call the Output() method to actually get your hands on your dynamically created PDF. This can take no parameters in which case the PDF is sent to the browser, more commonly though, developers specify the filename and the destination of the generated PDF. The destination can be one of four values, these are:
I: send the file inline to the browser.
D: send to the browser and force a file download with the name given by name.
F: save to a local file with the name given by name.
S: return the document as a string.
You can see my code sets the destination value as F:
$pdf->Output(”./pdfs/example.pdf”, “F”);
referenced from:this
Have a bAlaNCeD Life !

Resources