I am trying to run some basic test on different browsers but the test are failing once after the launching the first browser (in this case Firefox) and fails to execute the Chrome and IE browsers.
Java code using TestNG annotations -
package com.Selenium_Practice;
import java.util.concurrent.TimeUnit;
import junit.framework.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.opera.OperaDriver;
import org.openqa.selenium.safari.SafariDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.LogStatus;
public class CrossBrowserTestingUsingTestNG {
WebDriver driver;
ExtentReports report = ExtentReports.get(CrossBrowserTestingUsingTestNG.class);
@SuppressWarnings("deprecation")
@Test
@Parameters("browser")
public void CrossBrowserCodeBrowser(String browserName){
report.init("E:\\Report\\CrossBrowserTestingUsingTestNG.html", true);
report.startTest("Starting the test for CrossBrowserTestingUsingTestNG class");
if(browserName.equalsIgnoreCase("firefox")){
driver = new FirefoxDriver();
report.log(LogStatus.INFO, "Firefox browser is up and running");
}//if
else if(browserName.equalsIgnoreCase("chrome")){
System.setProperty("webDriver.chrome.driver", "E:\\Driver\\chromedriver.exe");
driver = new ChromeDriver();
report.log(LogStatus.INFO, "Chrome browser is up and runnning");
}//else if
else if(browserName.equalsIgnoreCase("ie")){
System.setProperty("webDriver.chrome.driver", "E:\\Driver\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
report.log(LogStatus.INFO, "IE is up and running");
}//else if
driver.manage().window().maximize();
driver.get("http://stackoverflow.com/questions/31747315/getting-nullpointerexception-when-trying-to-generate-test-reports-using-extentre/31752389#31752389");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='question-header']/h1/a")).getAttribute("href");
driver.findElement(By.xpath(".//*[@id='question-header']/h1/a")).getTagName();
System.out.println("Link : "+driver.findElement(By.xpath(".//*[@id='question-header']/h1/a")).getAttribute("href"));
System.out.println("Question : "+driver.findElement(By.xpath(".//*[@id='question-header']/h1/a")).getTagName());
Assert.assertEquals("a", driver.findElement(By.xpath(".//*[@id='question-header']/h1/a")).getTagName());
report.log(LogStatus.PASS, "Both are equal");
report.endTest();
driver.quit();
}//CrossBrowserCodeBrowser
}//CrossBrowserTestingUsingTestNG
Test Suit -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="CrossBrowserTesting" parallel="none">
<test name="FirefoxTestSuit">
<classes>
<parameter name="browser" value="firefox"/>
<class name="com.Selenium_Practice.CrossBrowserTestingUsingTestNG"/>
</classes>
</test> <!-- CrossBrowser -->
<test name="ChromeTestSuit">
<classes>
<parameter name="browser" value="chrome"/>
<class name="com.Selenium_Practice.CrossBrowserTestingUsingTestNG"/>
</classes>
</test> <!-- CrossBrowser -->
<test name="IETestSuit">
<classes>
<parameter name="browser" value="ie"/>
<class name="com.Selenium_Practice.CrossBrowserTestingUsingTestNG"/>
</classes>
</test> <!-- CrossBrowser -->
</suite> <!-- Suite -->
After running the XML file using TestNG i am getting the following results -
[TestNG] Running:
D:\Java Programs and files\com.Selenium_Practice\CrossBrowsertestng.xml
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Link : http://stackoverflow.com/questions/31747315/getting-nullpointerexception-when-trying-to-generate-test-reports-using-extentre
Question : a
Aug 01, 2015 6:28:10 AM org.openqa.selenium.os.UnixProcess$SeleniumWatchDog destroyHarder
INFO: Command failed to close cleanly. Destroying forcefully (v2). org.openqa.selenium.os.UnixProcess$SeleniumWatchDog@1503f6b
===============================================
CrossBrowserTesting
Total tests run: 3, Failures: 2, Skips: 0
===============================================
Updated XML file - In the below XML file i put the parameters outside the classes.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="CrossBrowserTesting" parallel="none">
<test name="FirefoxTestSuit">
<parameter name="browser" value="firefox"/>
<classes>
<class name="com.Selenium_Practice.CrossBrowserTestingUsingTestNG"/>
</classes>
</test> <!-- CrossBrowser -->
<test name="ChromeTestSuit">
<parameter name="browser" value="chrome"/>
<classes>
<class name="com.Selenium_Practice.CrossBrowserTestingUsingTestNG"/>
</classes>
</test> <!-- CrossBrowser -->
<test name="IETestSuit">
<parameter name="browser" value="ie"/>
<classes>
<class name="com.Selenium_Practice.CrossBrowserTestingUsingTestNG"/>
</classes>
</test> <!-- CrossBrowser -->
</suite> <!-- Suite -->
Output - After running the changed xmfile i am getting same result.
[TestNG] Running:
D:\Java Programs and files\com.Selenium_Practice\CrossBrowsertestng.xml
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Link : http://stackoverflow.com/questions/31747315/getting-nullpointerexception-when-trying-to-generate-test-reports-using-extentre
Question : a
Aug 02, 2015 12:29:54 PM org.openqa.selenium.os.UnixProcess$SeleniumWatchDog destroyHarder
INFO: Command failed to close cleanly. Destroying forcefully (v2). org.openqa.selenium.os.UnixProcess$SeleniumWatchDog@1be3395
===============================================
CrossBrowserTesting
Total tests run: 3, Failures: 2, Skips: 0
===============================================