After successfully executing scripts, every one want to write results to excel sheet..here is the way to write results to excel sheet....
Below is the sample script to write results to excel sheet...
package test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
import org.testng.annotations.*;
public class Importexport1 {
public Selenium selenium;
public SeleniumServer seleniumserver;
@BeforeClass
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://");
seleniumserver.start();
selenium.start();
}
@Test
public void testImportexport1() throws Exception {
// Read data from excel sheet
FileInputStream fi = new FileInputStream(
"F:\\Framework\\testdata\\Login1_Credentials.xls");
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
String a[][] = new String[s.getRows()][s.getColumns()];
// Write the input data into another excel file
FileOutputStream fo = new FileOutputStream(
"F:\\Framework\\Results\\LoginResult1.xls");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("loginresult1", 0);
selenium.open("http://www.gmail.com");
selenium.windowMaximize();
System.out.println("s.getRows() = " + s.getRows());
for (int i = 0; i < s.getRows(); i++) {
System.out.println("s.getColumns = " + s.getColumns());
for (int j = 0; j < s.getColumns(); j++) {
a[i][j] = s.getCell(j, i).getContents();
Label l = new Label(j, i, a[i][j]);
Label l1 = new Label(2, 0, "Result");
ws.addCell(l);
ws.addCell(l1);
}
}
for (int i = 1; i < s.getRows(); i++) {
selenium.type("Email", s.getCell(0, i).getContents());
selenium.type("Passwd", s.getCell(1, i).getContents());
selenium.click("signIn");
selenium.waitForPageToLoad("30000");
boolean aa = selenium.isTextPresent("The username or password you entered is incorrect. [?]");
System.out.println("the value of aa is::" + aa);
if (aa)
{
Label l3 = new Label(2, i, "fail");
ws.addCell(l3);
System.out.println("Login Failure");
Thread.sleep(10000);
} else {
Label l2 = new Label(2, i, "pass");
ws.addCell(l2);
selenium.click("link=Sign out");
Thread.sleep(10000);
}
}
wwb.write();
wwb.close();
}
@AfterClass
public void tearDown() throws Exception {
selenium.stop();
seleniumserver.stop();
}
}
Your input data should be like this....
Your out put excel should be like this
Hope this post is helpful....
Below is the sample script to write results to excel sheet...
package test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.*;
import org.testng.annotations.*;
public class Importexport1 {
public Selenium selenium;
public SeleniumServer seleniumserver;
@BeforeClass
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://");
seleniumserver.start();
selenium.start();
}
@Test
public void testImportexport1() throws Exception {
// Read data from excel sheet
FileInputStream fi = new FileInputStream(
"F:\\Framework\\testdata\\Login1_Credentials.xls");
Workbook w = Workbook.getWorkbook(fi);
Sheet s = w.getSheet(0);
String a[][] = new String[s.getRows()][s.getColumns()];
// Write the input data into another excel file
FileOutputStream fo = new FileOutputStream(
"F:\\Framework\\Results\\LoginResult1.xls");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("loginresult1", 0);
selenium.open("http://www.gmail.com");
selenium.windowMaximize();
System.out.println("s.getRows() = " + s.getRows());
for (int i = 0; i < s.getRows(); i++) {
System.out.println("s.getColumns = " + s.getColumns());
for (int j = 0; j < s.getColumns(); j++) {
a[i][j] = s.getCell(j, i).getContents();
Label l = new Label(j, i, a[i][j]);
Label l1 = new Label(2, 0, "Result");
ws.addCell(l);
ws.addCell(l1);
}
}
for (int i = 1; i < s.getRows(); i++) {
selenium.type("Email", s.getCell(0, i).getContents());
selenium.type("Passwd", s.getCell(1, i).getContents());
selenium.click("signIn");
selenium.waitForPageToLoad("30000");
boolean aa = selenium.isTextPresent("The username or password you entered is incorrect. [?]");
System.out.println("the value of aa is::" + aa);
if (aa)
{
Label l3 = new Label(2, i, "fail");
ws.addCell(l3);
System.out.println("Login Failure");
Thread.sleep(10000);
} else {
Label l2 = new Label(2, i, "pass");
ws.addCell(l2);
selenium.click("link=Sign out");
Thread.sleep(10000);
}
}
wwb.write();
wwb.close();
}
@AfterClass
public void tearDown() throws Exception {
selenium.stop();
seleniumserver.stop();
}
}
Your input data should be like this....
Your out put excel should be like this
Hope this post is helpful....
Thanks this was helpful
ReplyDeletePS: if the code is with proper comments it will be of more help.
Thanks this code is very useful.
ReplyDeleteThanks....It is helpful for my data driven approach
ReplyDeleteHi Naga,
ReplyDeleteI am trying to perform a similar thing & have been running into issues..
My input to the script: “N” number of urls through an excel sheet.
Desired output: I need to get some string from page source info for all those urls & write the same into Excel.
Actual output: I am getting data written in excel sheet for the last test/url I have run… For instance if we have 100urls in the excel, in my output sheet excel, I see results from 100th url. Not the 1 to 99 urls…
My problem: when I run this test for 100 different urls. I get the results for the last url I had run the test for… How do I grab the values for other 99 urls & how do I store it in the excel sheet.
did you find the solution for your problem ?
DeleteHi any solution to this problem
Deletewwb.write();
ReplyDeletewwb.close();
keep these lines at the end of the loop
I am trying to run scripts through Selenium IDE-HTML commands. Is there any way to extract the results to excel with HTML commands?
ReplyDeletesuperb...it helped me lot...
ReplyDeletecan u pls let me know...how can i write the results also in same excel where we getting inputs.
im using Web driver how can i use that code?
ReplyDeletethanks
Hi All,
ReplyDeleteI'm using selenium IDE to record & replay some testcase.
During this, i stored some values in variables.Now i've to load/write these variable's value into new file.How can i do it ? is it possible ?
This copy of Office is not genuine :P
ReplyDeleteThanks for the code anyways \m/
Above is find with one test but if we have multiple tests in single junit then how to handle?
ReplyDeleteIt is appropriate time to make a few plans for the longer term and it is time to be happy.
ReplyDeleteI've read this publish and if I may just I wish to recommend you few fascinating things or advice. Maybe you can write next articles relating to this article. I desire to read even more issues about it! chcesz wiedzieć więcej - kliknij, https://www.barmen.nu/mediawiki/index.php/Bruker:JulietNho
Great blog! Is your theme custom made or did you download it from somewhere?
ReplyDeleteA theme like yours with a few simple tweeks would really make my blog stand out.
Please let me know where you got your theme. With thanks
Take a look at my web page: Crack Passwords like a Boss With GPU-Based Cluster
When getting a discount rowing machine, you desire to look at it out thoroughly.
ReplyDeleteFeel free to visit my weblog dumbbells for sale
Good day very nice web site!! Guy .. Excellent .. Superb .
ReplyDelete. I will bookmark your blog and take the feeds additionally�I'm happy to find a lot of useful information here in the publish, we'd like work out more techniques on this regard, thank you for sharing.
my weblog ... premium minecraft
Will you be pondering if it is best to use a Bowflex as portion
ReplyDeleteof your house gymnasium gear?
Visit my homepage; please click the next site
Informative article, exactly what I needed.
ReplyDeleteHere is my web page ... earn while earn unemployed
The folded footprint is fifty-two inches lengthy by thirty-eight inches broad.
ReplyDeleteFeel free to surf to my web page :: Check This Out
These sites will assist you to decide which treadmill or another exercise devices
ReplyDeleteyou want to get.
Have a look at my web blog: dumbbell sets
Link exchange is nothing else but it is only placing the other person's weblog link on your page at proper place and other person will also do same for you.
ReplyDeleteMy site - dragon on dragonvale
Do not think that you just want a gym membership to receive into shape.
ReplyDeletemy website: http://www.getfitnstrong.com/bowflex-dumbbells/bowflex-selecttech-552-adjustable-dumbbells/
The process is created of a tough polymer and integrates the most up-to-date personal computer application, to deliver an incredibly eye-catching
ReplyDeleteand helpful bit of work out equipment.
my web page Read Full Report
You are able to conduct much more than 140 wellbeing
ReplyDeleteclub superior workouts.
Check out my webpage: Suggested Webpage
I have found that the lack of financial worry certainly sales opportunities to success.
ReplyDeletemy web site :: Personal Site
I do agree with all of the concepts you have introduced for your
ReplyDeletepost. They are really convincing and can certainly
work. Nonetheless, the posts are too quick for beginners.
May you please lengthen them a bit from next time? Thanks for the post.
Here is my site; psn cards
I have been surfing on-line greater than 3 hours lately, but
ReplyDeleteI by no means found any fascinating article like yours. It's beautiful worth sufficient for me. In my opinion, if all site owners and bloggers made good content material as you probably did, the net will likely be a lot more useful than ever before. "Perfection of moral virtue does not wholly take away the passions, but regulates them." by Saint Thomas Aquinas.
My webpage ... PSN Code Generator
Arguably the three most acknowledged home gyms are
ReplyDeleteclassified as the Bodylastics resistance bands procedure,
and the Bowflex as well as the Overall Gym cable
pulley units.
Here is my website - http://www.getfitnstrong.com/bowflex-dumbbells/bowflex-selecttech-dumbbells-ultimate-home-exercising/
Thanks for finally writing about > "Write results to excel sheet" < Liked it!
ReplyDeleteFeel free to surf to my page virtapay
This paragraph provides clear idea for the new viewers of blogging, that
ReplyDeletein fact how to do blogging and site-building.
Here is my website - virta pay
Simply desire to say your article is as astonishing.
ReplyDeleteThe clearness in your post is just great and i could assume
you are an expert on this subject. Well with your permission allow me to grab your RSS feed to keep up to date
with forthcoming post. Thanks a million and please keep up
the gratifying work.
My blog: Minecraft Beta
I visited several websites however the audio quality for audio songs current at this website is genuinely excellent.
ReplyDeleteTake a look at my page ... hack twitter account
It truly is the ideal way for professional runners to take care
ReplyDeleteof and increase their physical issue.
My web-site ... adjustable weights
This is really interesting, You are a very skilled blogger.
ReplyDeleteI've joined your feed and look forward to seeking more of your wonderful post. Also, I have shared your website in my social networks!
Here is my site ... virtapay exchange
Hi i am kavin, its my first time to commenting anywhere, when i read
ReplyDeletethis paragraph i thought i could also create comment due to this sensible post.
Feel free to visit my web-site - Hot young girls
I am regular visitor, how are you everybody? This post posted at this site is in
ReplyDeletefact fastidious.
my page :: free sex games
hey there and thank you for your info – I have certainly picked up anything new
ReplyDeletefrom right here. I did however expertise several technical points using this site, as I
experienced to reload the web site many times previous to I could get it to load properly.
I had been wondering if your hosting is OK? Not that I am complaining, but sluggish loading instances times will
sometimes affect your placement in google and can damage your quality
score if advertising and marketing with Adwords. Well I'm adding this RSS to my email and can look out for much more of your respective intriguing content. Make sure you update this again very soon.
Check out my blog: download miscrits
Somebody necessarily lend a hand to make significantly posts I'd state. This is the very first time I frequented your website page and to this point? I surprised with the research you made to create this particular post extraordinary. Wonderful job!
ReplyDeleteCheck out my webpage: pc sex games
These foodstuff groups also are prosperous in fiber that can help your belly digest the foodstuff within your intestines faster.
ReplyDeleteHere is my web-site: simply click the following page
Many well being and conditioning experts concur that manual machines are essentially superior for taking off more lbs all-around your hips
ReplyDeletethan motorized equipment.
Also visit my site; http://www.getfitnstrong.com
Using weights is the way you are likely to make muscle.
ReplyDeleteCheck out my page; View Results
Nonetheless, every person would not need to have the high power
ReplyDeletefor their workout.
Also visit my webpage just click the up coming article
You should take part in a contest for one of the finest websites on the internet.
ReplyDeleteI'm going to highly recommend this site!
my site - virtapay to lr
The biggest advantage of dumbbell shrugs in excess of most other shrug exercise routines
ReplyDeleteis definitely the arm positioning.
Feel free to surf to my web page ... bowflex selecttech 552 dumbbells sale
The strength rod technology with the Bowflex Activity residence gymnasium is really preferred by numerous exercise enthusiasts as opposed to
ReplyDeletefree weights or stacks.
my page :: http://www.getfitnstrong.com/bowflex-dumbbells/bowflex-selecttech-dumbbells-ultimate-home-exercising/
This could maintain adequate fuel and energy to elevate the heavy weights and build muscle mass.
ReplyDeleteAlso visit my web page; Recommended Internet site
Becoming a work-out person, I've constantly tried out several machines, and so forth to stay in shape.
ReplyDeletemy weblog: relevant resource site
The solar heating energy venture amalgamating high-performing
ReplyDeletesolar-thermal systems with fossil fuels, we only need to build more solar heating energy.
20 of the food we throw away the opportunity to become stewards of our environment and learn about sustainable energy
strategies here in Wisconsin. We're starting to see stocks tighten up in certain small markets already, and some final things around those.
Feel free to visit my web site; Photovoltaic Uk Association
According to RWDSU, gig bag guitar Center Holdings, is
ReplyDeletenow carrying a heavy debt load of $1. She even laughed at one of those guys who knows I put in enough time
learning an instrument and get on stage.
Here is my page :: www.phantomwithdrawals.com
The exercise sessions you offer you you should not must be really extreme.
ReplyDeletemy page - adjustable dumbbells
Thanks to my father who stated to me concerning this
ReplyDeleteweblog, this webpage is in fact amazing.
my weblog How To Hack Twitter
My brother suggested I might like this website. He was totally right.
ReplyDeleteThis post truly made my day. You cann't imagine just how much time I had spent for this information! Thanks!
Feel free to surf to my web page :: miscrits hack
Do you have any video of that? I'd care to find out some additional information.
ReplyDeletemy web-site - http://julio.Estudiosuma.cl/
Having said that, your products will never retain with
ReplyDeletethe exact stage for your extended period of time.
Feel free to surf to my webpage bowflex 552
Way cool! Some extremely valid points! I appreciate you writing this post plus the rest of the site is really good.
ReplyDeleteAlso visit my page ... Adfoc.Us
Cool blog! Is your theme custom made or did you download
ReplyDeleteit from somewhere? A theme like yours with a few simple
adjustements would really make my blog jump out. Please let me know where you got your theme.
Thank you
Here is my site :: übersetzung online kostenlos ()
PSN Cards 50$ free
ReplyDeleteFeel free to visit my blog post: Free PSN Cards
nike outlet store
ReplyDeletepandora outlet
michael kors outlet online
cheap nike shoes
pandora
michael kors outlet clearance
michael kors outlet
polo ralph lauren
canada goose jackets
ray ban sunglasses
goyard bags
ReplyDeleteyeezy shoes
golden goose shoes
golden goose outlet
goyard bags
goyard tote
moncler jackets
goyard handbags
yeezy supply
golden goose sneakers