TEStNG:无法使用testng xml运行包进行跨浏览器测试

问题描述 投票:0回答:1

下面是Smoke.xml,我想用它来运行一组用于跨浏览器测试的包。但是在运行下面的xml时,我的测试用例都没有被执行。也没有抛出错误。请建议我哪里出错了。我已经坚持了很长一段时间了。

<?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>

这是我的浏览器基类。

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>

xml selenium selenium-webdriver testng testng-eclipse
1个回答
0
投票

您的包裹名称错误。它不应该以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>
© www.soinside.com 2019 - 2024. All rights reserved.