Send parsed console output in email - email

I am working with two Jenkins plugins, Email-Ext and Log Parser. I have the regular expressions for the Log Parser plugin how I want them, and I would like to include the output of the Log Parser plugin in the email that is sent out to users after a build.
The Email-Ext plugin has access to the console output, and I could rewrite my regular expressions for the console output in the email, but since the Log Parser plugin has already done the hard work I was hoping there was some way I could just pull its output into the email.
Does anyone know of any way (like a Jenkins environment variable) this can be done?

A co-worker told me that every build in Jenkins has "actions" associated with it and that Jenkins plugins do their magic via actions. I was able to find all actions of my actions with build.getActions(). I then looped through the actions until I got LogParserAction which is the action supplied by the Jenkins Log Parser plugin.
I then looked through the source code of LogParserAction.class to find the method getErrorLinksFile(). With this method I was able to get the text of the parsed log. A similar method called getWarningLinksFile() is available for the warnings and another is available for info.
I then looped through the text on \n character and applied some regexs to make it look how I wanted. Important parts of the code are below. Looks better if you view it as HTML in Notepad++
%>
<TABLE width="100%">
<TR>
<TD class="bg1" colspan="2">ERRORS</TD>
</TR>
<%
def publisher = null
for(iter in project.getPublishersList()){
if(iter.getDescriptor().getDisplayName().equals("Editable Email Notification")){
publisher = iter
break
}
}
if(publisher != null){
def logParserResult
//Get the LogParserAction from Jenkins
for(action in build.getActions()){
if(action.toString().contains("LogParserAction")){
//Get the LogParserResult from the LogParserAction
logParserResult = action.getResult()
break
}
}
//Get the ErrorLinksFile from the LogParserResult
def errorLinksFile = new File(logParserResult.getErrorLinksFile())
//Rewrite the URL so it directs to something useful
pattern = ~/<a.*?><font.*?>/
def errorList = []
for(line in errorLinksFile.getText().split("\n")){
//All errors have a link, so this makes sure no superfluous text is displayed
if(!line.contains("href")){
continue
}
errorList.add(line.replaceAll(pattern, "<a href="+ rooturl + build.url + "parsed_console/?\">").minus("</font>"))
}
%>
<TR>
<TD class="bg2" colspan="2">Total : ${errorList.count{it}} error(s)</TD>
</TR>
<%
for(error in errorList){
%>
<TR>
<TD class="errors" colspan="2">${error}</TD>
</TR>
<%
}
%>
</TABLE>

If you are able to pull the logs and write into a file.
You can attach that file as an attachment to your email using Email-Ext.

Related

How can we read excelsheet data in selenium IDE

I am very new to selenium ide,How can we read excelsheet data in selenium IDE. I have searched in google but not found particular links which I wanted .I got one link where they are reading excelsheet using eclipse, junit,testNG etc. Is it possible to read data of excelsheet in selenium ide and use that data in selenium ide test cases and also i want to export my test suit result in excelsheet.
Please reply
Thank you
Though I'm late to the show, I hope the following instructions will at least be of some use to anyone looking to automate part of their workflow. The method detailed below will allow automated web form entry from data in a CSV file using only Selenium IDE.
What you'll need: 1.) Selenium IDE 2.) CSV File Reader plugin // This can be acquired at seleniumhq.org/download then proceed to download at Github 3.) Selblocks // a language extension which permits use of conditonals & looping
Now that you have the necessary tools, fire up Firefox and navigate to your Selenium IDE options. You'll want to copy the path of the File Reader (.js) to Selenium Core Extensions to enable use. With that out of the way, verify that Selblocks installed without issue by typing in "while"; if this command is recognized (i.e. auto-completes/has a reference description) then all went well. Now verify that the File reader plugin commands are accessible by typing in "readCSV"; again if it auto-completes the command that means you're good to go.
Your target for the readCSV command is the path to your file (ex: file:\C:/Test.csv). To read the entire contents of the csv file, you'll need a simple while loop. Here's a sample framework:
...
<tr>
<td>store</td>
<td>4</td>
<td>loop</td>
</tr>
<tr>
<td>store</td>
<td>1</td>
<td>p</td>
</tr>
<tr>
<td>while</td>
<td>${p}<${loop}</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>https://automatestuff.com/go </td>
<td></td>
</tr>
<tr>
<td>readCSV</td>
<td>file:\C:/Test.csv</td>
<td></td>
</tr>
<tr>
<td>storeCellValue</td>
<td>SomeData</td>
<td>${p},1</td>
</tr>
<tr>
<td>storeCellValue</td>
<td>MoreData</td>
<td>${p},2</td>
</tr>
<tr>
<td>echo</td>
<td>${SomeData}</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${MoreData}</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>${p}+1</td>
<td>p</td>
</tr>
....
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
...
Your target value (in this example, 4) for the first store command will vary given the size of your dataset. The while expression will run through your data until it evaluates to false. In this example, I have data being read from column 1, row 1 (and so on) and column 2, but it's possible to configure more or less.
Anyway, I hope that's clear and gets you on your way to automating the mundane bits of your workflow.
You can probably hack together something for this that uses javascript to read in files, but I think you should question WHY you want to do it this way instead. Why do you need excel files or why are you limited to IDE testing?
But maybe some help on excel files & javascript: How to read an excel file contents on client side?

Jquery: Can I refer to a selector not present in the default HTML?

Sorry, this is probably a noob question. Could'nt find the source of my problem, or helpful info in SO (or elsewhere!).
I'm practising my newly acquired Jquery skills (?) on a small contact list demo project, which basically includes a table and a simple form to populate it. The project includes an HTML file, a CSS stylesheet, and some Javascript and Jquery magic in a .JS file.
EDIT: Here's a jsFiddle I've created for this.
By default, when the page first loads, the table is empty and a placeholder text is shown:
<table>
<thead>
<tr>
<th id="col_lastName">Last Name</th>
<th id="col_firstName">First Name</th>
<th id="col_email">E-Mail</th>
<th id="col_mobile">Mobile</th>
<th id="col_actions">Actions</th>
</tr>
</thead>
<tbody>
<tr id="placeholder">
<td colspan="5">No contacts yet. Feel free to add your friends!</td>
</tr>
</tbody>
</table>
Upon submittion of the form, using Jquery I set the placeholder to disappear and a new table row is appended:
$("tbody").append(
"<tr><td>" + $("#last_name").val() +
"</td><td>" + $("#first_name").val() +
"</td><td><a href='mailto:" + $("#email").val() + "'>" + $("#email").val() + "</a>" +
"</td><td>" + $("#mobile").val() +
"</td><td><p class='remove_link'>Remove</p></td></tr>");
I would like it to include a link to remove the current row, so I wrote a function that's triggered by clicking the <p class="remove_link">"Remove"</p> text that was part of the string appended upon form submittion. However I can't seem to be able to make it clickable with Jquery. I wrote this:
$(".remove_link").click(function(){
// just for chaecking the selector is ok
console.log("remove clicked");
});
But on the actual page the "Remove" isn't clickable at all.
Does it have anything to do with the fact that the class doesn't appear in the default HTML and is only declared in the appended code?
Of course, it could also mean my syntax is wrong, but I can't figure this out!
Since the element you are trying to bind the event to does not exist yet when you perform the binding you need to set up a future delgate using .on()
$("table").on('click',".remove_link",function () {
console.log("remove clicked");
});
Note that the important trick is to start the binding from an existing element (in this case the table)
I updated your fiddle here: http://jsfiddle.net/Abxzx/4/
well, I think I have a lead for an answer for this. In the page dealing with The .on() method on W3Schools there's a reference (down belew) to the fact that this method can also "work for elements not yet created". From this I deduct that the simple .click() just won't do. I'll try again with .on() tomorrow and will report my findings.
Meanwhile, if there's someone here more experienced in Jquery, I'd appreciate your opinion/advice.

Trouble pinpointing child elements while using Mojo::DOM

I'm trying to extract text from an old vBulletin forum using WWW::Mechanize and Mojo::DOM.
vBulletin doesn't use HTML and CSS for semantic markup, and I'm having trouble using Mojo::DOM->children to get at certain elements.
These vBulletin posts are structured differently depending on their content.
Single message:
<div id="postid_12345">The quick brown fox jumps over the lazy dog.<div>
Single message quoting another user:
<div id="postid_12345">
<div>
<table>
<tr>
<td>
<div>Quote originally posted by Bob</div>
<div>Everyone knows the sky is blue.</div>
</td>
</tr>
</table>
</div>
I disagree with you, Bob. It's obviously green.
</div>
Single message with spoilers:
<div id="postid_12345">
<div class="spoiler">Yoda is Luke's father!</div>
</div>
Single message quoting another user, with spoilers:
<div id="postid_12345">
<div>
<table>
<tr>
<td>
<div>Quote originally posted by Fred</div>
<div class="spoiler">Yoda is Luke's father!</div>
</td>
</tr>
</table>
</div>
<div class="spoiler">No waaaaay!</div>
</div>
Assuming the above HTML and an array packed with the necessary post IDs:
for (#post_ids) {
$mech->get($full_url_of_specific_forum_post);
my $dom = Mojo::DOM->new($mech->content);
my $div_id = 'postid_' . $_;
say $dom->at($div_id)->children('div')->first;
say $dom->at($div_id)->text;
}
Using $dom->at($div_id)->all_text gives me everything in an unbroken line, which makes it difficult to tell what's quoted and what's original in the post.
Using $dom->at($div_id)->text skips all of the child elements, so quoted text and spoilers are not picked up.
I've tried variations of $dom->at($div_id)->children('div')->first, but this gives me everything, including the HTML.
Ideally, I'd like to be able to pick up all the text in each post, with each child element on its own line, e.g.
POSTID12345:
+ Quote originally posted by Bob
+ Everyone knows the sky is blue.
I disagree with you, Bob. It's obviously green.
I'm new to Mojo and rusty with Perl. I wanted to solve this on my own, but after looking over the documentation and fiddling with it for a few hours, my brain is mush and I'm at a loss. I'm just not getting how Mojo::DOM and Mojo::Collections work.
Any help will be greatly appreciated.
Looking at the source of Mojo::DOM, basically the all_text method recursively walks the DOM and extracts all text. Use that source to write your own walking the DOM function. Its recursive function depends on returning a single string, in yours you might have it return an array with whatever context you need.
EDIT:
After some discussion on IRC, the web scraping example has been updated, it might help you guide you. http://mojolicio.us/perldoc/Mojolicious/Guides/Cookbook#Web_scraping
There is a module to flattern HTML tree, HTML::Linear.
The explanation of purpose for flatterning HTML tree is a bit long and boring, so here's a picture showing the output of the xpathify tool, bound with that module:
As you see, HTML tree nodes become single key/value list, where the key is the XPath for that node, and the value is the node's text attribute.
In a few keystrokes, this is how you use HTML::Linear:
#!/usr/bin/env perl
use strict;
use utf8;
use warnings;
use Data::Printer;
use HTML::Linear;
my $hl = HTML::Linear->new;
$hl->parse_file(q(vboard.html));
for my $el ($hl->as_list) {
my $hash = $el->as_hash;
next unless keys %{$hash};
p $hash;
}

How to parse a URL from string in selenium IDE

I am using SIDE 1.3.0 along with FF 6.0.2.
I stored a string using store text command which contains a "URL" by using the following command.
storeText
which results as
MyCode = "<iframe src="http://myportal.com/mysales/Agent/index/4eb29642ce24e8.22143850/embedded" height="650" width="605" frameBorder="0"></iframe>"
I need to have only the URL part in another variable from the string above "http://myportal.com/mysales/Agent/index/4eb29642ce24e8.22334455/embedded"
in order to proceed with the remaining test case. Thanks in advance.
Something like:
<tr>
<td>storeEval</td>
<td>'${MyCode}'.replace(/.*src="(.*?)".*/, $1)</td>
<td>url</td>
</tr>
This will use JavaScript to set a variable called url to the value of the src attribute within your MyCode variable.
The first command below stores the href attribute of any element, you can modify it to your needs.
The third command uses javascript to get the pathname attribute of the DOM object.
Hope this answers your question.
If you open the IDE click on the source tab in the main window and copy and paste the code below between the tags, you'll be able to run the test on this page, or any other stack overflow page.
<tr>
<td>storeAttribute</td>
<td>css=.profile-link#href</td>
<td>href</td>
</tr>
<tr>
<td>echo</td>
<td>${href}</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>this.browserbot.getUserWindow().document.getElementsByClassName('profile-link')[0].pathname</td>
<td>pathname</td>
</tr>
<tr>
<td>echo</td>
<td>${pathname}</td>
<td></td>
</tr>

php - splitting a string with HTML by the first instance of a table cell

I am checking on HTML content on my page, and I've got the split down to have the variable left with this content:
">
<td>Oklahoma City</td>
<td>Oklahoma</td>
<td>OK</td>
<td>405</td>
<td>CST</td>
</tr>
</table>
<div id="
Those are dynamic pages I'm checking, so the data will always be different, but the layout the same...
How can I get the value out of the second <td> if that html is in 1 variable(string)?
It was a full page, I've used explode twice to remove everything above a div field and everything below the last dive field id... so it has some open html tags left because I did not know how to get rid of that along the way to be left with just this:
<td>Oklahoma City</td>
<td>Oklahoma</td>
<td>OK</td>
<td>405</td>
<td>CST</td>
</tr>
</table>
Can you tell me how to get that out? I just need the second one because it is the county and that is what I'm checking on...