package com.web;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class WebDriverDemo {
private static WebDriver driver = null;
@Test
@Parameters( {"BROWSER"})
public void testread(String BROWSER)throws Exception{
System.out.println("Browser: " + BROWSER);
if (BROWSER.equals("FF")) {
System.out.println("FF is selected");
driver = new FirefoxDriver();
} else if (BROWSER.equals("IE")) {
System.out.println("IE is selected");
driver = new InternetExplorerDriver();
} else if (BROWSER.equals("HU")) {
System.out.println("HU is selected");
driver = new HtmlUnitDriver();
} else if (BROWSER.equals("CH")){
System.out.println("Google chrome is selected");
driver = new ChromeDriver();
}
driver.navigate().to("http://www.yahoo.com");
Thread.sleep(10000);
WebElement search= driver.findElement(By.name("p"));
search.sendKeys("automation blog by niraj");
search.submit();
Thread.sleep(5000);
Assert.assertTrue(driver.getPageSource().contains("automationtricks.blogspot.com"),"Failed in "+ BROWSER);
driver.close();
}
}
In the above sample program BROWSER is a variable which value would be passed from TestNG.xml and TestNG.xml will run the test multiple time each time BROWSER value would be set with different browser name and test will check the BROWSER value and decide which browser test will run.TestNG.xml
<?xml version="1.0" encoding="UTF-8"?>
<suite name="webDriver">
<test name="WebDriverDemo Witn FF" preserve-order="true">
<parameter name="BROWSER" value="FF" />
<classes>
<class name="com.web.WebDriverDemo" />
</classes>
</test>
<test name="WebDriverDemo with IE" preserve-order="ture">
<parameter name="BROWSER" value="IE"></parameter>
<classes>
<class name="com.web.WebDriverDemo"></class>
</classes>
</test>
<test name="WebDriverDemo with HTML unit" preserve-order="true">
<parameter name="BROWSER" value="HU"></parameter>
<classes>
<class name="com.web.WebDriverDemo"></class>
</classes>
</test>
<test name="WebDriverDemo with chrome" preserve-order="true">
<parameter name="BROWSER" value="CH"></parameter>
<classes>
<class name="com.web.WebDriverDemo"></class>
</classes>
</test>
</suite>
Τhere's definately a lot to find out about this issue. I like all the points you made.
ReplyDeleteHere is my web-site :: ringing sound in ear
my web site > ringing in ears treatment
Thanks Neeraj, this seems to be useful.
ReplyDeleteGοоd day! I κnow thiѕ is kind
ReplyDeleteof off toρiс but ӏ wаs wondering ωhiсh blog ρlatform arе you using fοг this
wеbsite? I'm getting fed up of Wordpress because I've had problems
ωith hackеrѕ and I'm looking at alternatives for another platform. I would be awesome if you could point me in the direction of a good platform.
Here is my site - lose fat fast
Hellο therе! This post сould not bе
ReplyDeletewritten any bettеr! Reading through this post reminds
me of my preνіous гoom mate! He always kept talking abοut this.
I will forward thіs ωritе-up to him. Fairly certain he will haѵe a good read.
Thanks for shагing!
Also visіt my ωеb рagе ... youtu.be
It's a pity you don't haѵe a donate button!
ReplyDeleteI'd without a doubt donate to this excellent blog! I suppose for now i'll
sеttlе fоr booκ-maгking and aԁding
yоuг RSS feed tо my Google аcсount.
Ӏ looκ forwаrd to brand nеw upԁates anԁ will talκ аbоut this site with mу Faсebook grоup.
Chat soon!
Alsο visіt my websіte - locksmith solihull
Howdy! Do you know іf theу mаke anу plugіns
ReplyDeleteto assist wіth SEO? Ι'm trying to get my blog to rank for some targeted keywords but I'm not seeing νеry good results.
ӏf yоu κnow of any plеase sharе.
Manу thanks!
Αlѕο viѕit my homepage - fix leaking pipes
My programmer is trying to persuade me to move to .net from PHP.
ReplyDeleteI have always disliked the idea because of the expenses.
But he's tryiong none the less. I've been using Movable-type
on several websites for about a year and am worried about switching to another platform.
I have heard very good things about blogengine.
net. Is there a way I can transfer all my wordpress posts into it?
Any kind of help would be greatly appreciated!
Review my web blog; gamblers
I'm really enjoying the design and layout of your site. It's
ReplyDeletea νеrу easy on thе eyes which makes it much
more еnjoyable for me to come here and visit mоre оften.
Dіd you hіrе οut a designer to crеаte your theme?
Exсellent ωork!
My site ... Makes boobs bigger naturally
Hey there! Ι've been following your web site for a while now and finally got the bravery to go ahead and give you a shout out from Kingwood Tx! Just wanted to mention keep up the good work!
ReplyDeleteMy blog post; how to lose belly quickly
Hellο, i read your blοg οccasionally
ReplyDeleteаnd і oωn a similar оne аnd i waѕ just curіouѕ
if you get а lot of spam comments? If so how dо you stоp it, аny
plugin oг anything yоu can suggest? I gеt so much lately it's driving me insane so any assistance is very much appreciated.
Also visit my homepage; 24 hr Emergency Plumber Solihull
Please, do I place the XML file in the XML file folder in Webdriver? Thanks. I'm completely new to webdriver. Thanks.
ReplyDeleteIf you are talking about placing TestNG.xml file then follow these steps (in Eclipse).
Delete1. You should have testng configured in your maven dependencies.
2. Place the testng.xml directly in your project folder.
3. To check if it works right click on XML and Select 'Run As' -> TestNG Suite. Done!
I hope this helps.
Your information about software testing is really interesting. Also I want to know the latest new techniques which are implemented in software testing. Can you update it in your website.
ReplyDeleteI'm really enjoying the design and layout of your site.Thanks.
ReplyDeleteบาคาร่า
จีคลับ
gclub
Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well iOS App Development Company
ReplyDeleteiOS App Development Company
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeletePython Training in electronic city
DataScience with Python Training in electronic city
AWS Training in electronic city
Big Data Hadoop Training in electronic city
Devops Training in electronic city
Hey,Thanks for sharing.very interesting.I have bookmarked your blog because very clear information is given.Keep updating more
ReplyDeletebig data courses in bangalore with placement
ReplyDeleteFantastic blog, i am impressed by the information provided it was very helpful hopping for some more informative posts thank you .
typeerror nonetype object is not subscriptable
Excellent blog information shared was very informative and valuable looking forward for next blog thank you.
ReplyDeleteData Analytics Course Online