TEStNG:无法 运行 使用 testng xml 的包进行跨浏览器测试
TEStNG : Unable to run the packages using testng xml for cross browser testing
下面是Smoke.xml我想运行使用的一套跨浏览器测试包。但是在 运行ning 我的测试用例的下面 xml none 被执行。也不会抛出任何错误。请建议我哪里出错了。我已经坚持了很长一段时间了。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="true">
<test name="Parallel test suite" preserve-order="true" thread-count="2">
<parameter name="Browser" value="Chrome"></parameter>
<packages>
<package name="src.test.java.*" />
<!-- <package name="src.test.java.comparison" />
<package name="src.test.java.mutualFundDetailPage" />
<package name="src.test.java.portfolio" />
<package name="src.test.java.reportCreator" />
<package name="src.test.java.searchAndSearchResults" /> -->
</packages>
</test>
</suite>
这是我的浏览器基础 class。
package com.gale.precision.FundVisualizer.core;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Base {
public static WebDriver driver = null;
public static String DriverPath = System.getProperty("user.dir") + "//" + "Drivers";
public static String DirectoryPath = System.getProperty("user.dir");
public static Properties prop = new Properties();
public static InputStream input = null;
public static void getBrowser()
{
try {
input = new FileInputStream(DirectoryPath + "//" + "config" + "//" + "app.properties");
prop.load(input);
try {
if (prop.getProperty("Browser").equalsIgnoreCase("IE")) {
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
System.setProperty("webdriver.ie.driver", DriverPath + "//" + "IEDriverServer_32.exe");
driver = new InternetExplorerDriver(capabilities);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Integer.parseInt(prop.getProperty("ImplicitWait")), TimeUnit.SECONDS);
driver.get(prop.getProperty("URL"));
} else if (prop.getProperty("Browser").equalsIgnoreCase("Chrome")) {
System.setProperty("webdriver.chrome.driver", DriverPath + "//" + "chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().fullscreen();
//driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Integer.parseInt(prop.getProperty("ImplicitWait")), TimeUnit.SECONDS);
driver.get(prop.getProperty("URL"));
} else if (prop.getProperty("Browser").equalsIgnoreCase("FF")) {
System.setProperty("webdriver.gecko.driver", DriverPath + "//" + "geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Integer.parseInt(prop.getProperty("ImplicitWait")), TimeUnit.SECONDS);
driver.get(prop.getProperty("URL"));
} else if (prop.getProperty("Browser").equalsIgnoreCase("Edge")) {
System.setProperty("webdriver.edge.driver", DriverPath + "//" + "MicrosoftWebDriverServer.exe");
driver = new EdgeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Integer.parseInt(prop.getProperty("ImplicitWait")), TimeUnit.SECONDS);
driver.get(prop.getProperty("URL"));
} else {
System.out.println("Not a valid browser!");
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static boolean clickingStaleElements(WebElement element) {
boolean result = false;
int attempts = 0;
while (attempts < 2) {
try {
element.click();
result = true;
break;
} catch (StaleElementReferenceException e) {
e.printStackTrace();
}
attempts++;
}
return result;
}
public static void closeBrowser() {
driver.quit();
}
}
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="true">
<test name="Parallel test suite" preserve-order="true" thread-count="2">
<parameter name="Browser" value="Chrome"></parameter>
<packages>
<package name="src.test.java.*" />
<!-- <package name="src.test.java.comparison" />
<package name="src.test.java.mutualFundDetailPage" />
<package name="src.test.java.portfolio" />
<package name="src.test.java.reportCreator" />
<package name="src.test.java.searchAndSearchResults" /> -->
</packages>
</test>
你的包名有误。它不应该以 src.test 开头。请尝试以下操作。
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="true">
<test name="Parallel test suite" preserve-order="true" thread-count="2">
<parameter name="Browser" value="Chrome"></parameter>
<packages>
<package name="comparison"/>
<package name="mutualFundDetailPage" />
<package name="portfolio" />
<package name="reportCreator" />
<package name="searchAndSearchResults" />
</packages>
</test>
</suite>
下面是Smoke.xml我想运行使用的一套跨浏览器测试包。但是在 运行ning 我的测试用例的下面 xml none 被执行。也不会抛出任何错误。请建议我哪里出错了。我已经坚持了很长一段时间了。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="true">
<test name="Parallel test suite" preserve-order="true" thread-count="2">
<parameter name="Browser" value="Chrome"></parameter>
<packages>
<package name="src.test.java.*" />
<!-- <package name="src.test.java.comparison" />
<package name="src.test.java.mutualFundDetailPage" />
<package name="src.test.java.portfolio" />
<package name="src.test.java.reportCreator" />
<package name="src.test.java.searchAndSearchResults" /> -->
</packages>
</test>
</suite>
这是我的浏览器基础 class。
package com.gale.precision.FundVisualizer.core;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Base {
public static WebDriver driver = null;
public static String DriverPath = System.getProperty("user.dir") + "//" + "Drivers";
public static String DirectoryPath = System.getProperty("user.dir");
public static Properties prop = new Properties();
public static InputStream input = null;
public static void getBrowser()
{
try {
input = new FileInputStream(DirectoryPath + "//" + "config" + "//" + "app.properties");
prop.load(input);
try {
if (prop.getProperty("Browser").equalsIgnoreCase("IE")) {
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
System.setProperty("webdriver.ie.driver", DriverPath + "//" + "IEDriverServer_32.exe");
driver = new InternetExplorerDriver(capabilities);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Integer.parseInt(prop.getProperty("ImplicitWait")), TimeUnit.SECONDS);
driver.get(prop.getProperty("URL"));
} else if (prop.getProperty("Browser").equalsIgnoreCase("Chrome")) {
System.setProperty("webdriver.chrome.driver", DriverPath + "//" + "chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().fullscreen();
//driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Integer.parseInt(prop.getProperty("ImplicitWait")), TimeUnit.SECONDS);
driver.get(prop.getProperty("URL"));
} else if (prop.getProperty("Browser").equalsIgnoreCase("FF")) {
System.setProperty("webdriver.gecko.driver", DriverPath + "//" + "geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Integer.parseInt(prop.getProperty("ImplicitWait")), TimeUnit.SECONDS);
driver.get(prop.getProperty("URL"));
} else if (prop.getProperty("Browser").equalsIgnoreCase("Edge")) {
System.setProperty("webdriver.edge.driver", DriverPath + "//" + "MicrosoftWebDriverServer.exe");
driver = new EdgeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Integer.parseInt(prop.getProperty("ImplicitWait")), TimeUnit.SECONDS);
driver.get(prop.getProperty("URL"));
} else {
System.out.println("Not a valid browser!");
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static boolean clickingStaleElements(WebElement element) {
boolean result = false;
int attempts = 0;
while (attempts < 2) {
try {
element.click();
result = true;
break;
} catch (StaleElementReferenceException e) {
e.printStackTrace();
}
attempts++;
}
return result;
}
public static void closeBrowser() {
driver.quit();
}
}
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="true">
<test name="Parallel test suite" preserve-order="true" thread-count="2">
<parameter name="Browser" value="Chrome"></parameter>
<packages>
<package name="src.test.java.*" />
<!-- <package name="src.test.java.comparison" />
<package name="src.test.java.mutualFundDetailPage" />
<package name="src.test.java.portfolio" />
<package name="src.test.java.reportCreator" />
<package name="src.test.java.searchAndSearchResults" /> -->
</packages>
</test>
你的包名有误。它不应该以 src.test 开头。请尝试以下操作。
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="true">
<test name="Parallel test suite" preserve-order="true" thread-count="2">
<parameter name="Browser" value="Chrome"></parameter>
<packages>
<package name="comparison"/>
<package name="mutualFundDetailPage" />
<package name="portfolio" />
<package name="reportCreator" />
<package name="searchAndSearchResults" />
</packages>
</test>
</suite>