Java – test the browser at the same time; Received error
•
Java
Now, I'm trying my first test, which will test browsers chrome, Firefox, ie and safari at the same time But I got the following error:
I am using selenium, TestNG, Maven and Java XML test suite files and java files are located in the same folder in the directory I can find the content of the test suite XML file online as follows (set the class name value to the correct package and class name):
<?xml version="1.0" encoding="UTF-8"?>
<DOCTYPE suite SYstem "http://testng.org/testng-1.0.dtd">
<suite name="TestSuite" thread-count="2" parallel="tests">
<test name="ChromeTest">
<parameter name="browser" value="chrome" />
<classes>
<class name="com.sqa.ts.multiBrowser.BrowserTest">
</class>
</classes>
</test>
<test name="FirefoxTest">
<parameter name="browser" value="firefox" />
<classes>
<class name="com.sqa.ts.multiBrowser.BrowserTest">
</class>
</classes>
</test>
<test name="IETest">
<parameter name="browser" value="ie" />
<classes>
<class name="com.sqa.ts.multiBrowser.BrowserTest">
</class>
</classes>
</test>
<test name="SafariTest">
<parameter name="browser" value="safari" />
<classes>
<class name="com.sqa.ts.multiBrowser.BrowserTest">
</class>
</classes>
</test>
</suite>
Here's my code. Just open the browser to make sure it will run and pass:
package com.sqa.ts.multiBrowser;
import java.net.MalformedURLException;
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.safari.SafariDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class BrowserTest {
private WebDriver driver;
@Test
public void testCaSEOne() {
driver.get("http://www.google.com");
driver.close();
}
@BeforeMethod
@Parameters("browser")
public void beforeMethod(String browser) throws MalformedURLException {
if (browser.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver","C:/Users/Trevor/workspace/BrowserTest/drivers/chromedriver.exe");
driver = new ChromeDriver();
} else if (browser.equalsIgnoreCase("firefox")) {
driver = new FirefoxDriver();
} else if (browser.equalsIgnoreCase("ie")) {
System.setProperty("webdriver.ie.driver","C:/Users/Trevor/workspace/BrowserTest/drivers/IEDriverServer.exe");
driver = new InternetExplorerDriver();
} else if (browser.equalsIgnoreCase("safari")) {
driver = new SafariDriver();
}
}
@AfterMethod
public void afterMethod() {
driver.quit();
}
}
I would appreciate it if someone could let me know the cause of this problem thank you.
Solution
Looks like you lack POM TestNG configuration in XML
<build>
<plugins>
<!-- Following plugin executes the testng tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<!-- Suite testng xml file to consider for test execution -->
<suiteXmlFiles>
<suiteXmlFile>src/test/java/com/sqa/ts/multiBrowser/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</build>
Running MVN clean install or MVN clean install should run test cases I hope it will help you
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
