- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Maven 项目,其中我正在从 pom.xml 文件运行 testng.xml。
我的 testng.xml 文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests">
<test name="FirefoxTest">
<parameter name="browser" value="firefox"/>
<classes>
<class name="tests.PM_User_Test"/>
</classes>
</test> <!-- Test -->
<test name="ChromeTest">
<parameter name="browser" value="chrome"/>
<classes>
<class name="tests.PM_User_Test"/>
<class name="tests.PM_Extension_Test"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
下面是我的类(class):
package base;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import utilities.ExcelReadAndWrite;
import utilities.Take_Screenshot;
public class ConfigClass
{
public WebDriver driver = null;
public static String excelPath = null;
public static ExcelReadAndWrite loginData;
public static ExcelReadAndWrite pmTests;
public static ExcelReadAndWrite snmTests;
public static ExcelReadAndWrite ipData;
@BeforeSuite
public void beforeSuite()
{
excelPath = "C://Users//mallikar//git//PM//PM//src//main//java//myTestData//TestData.xlsx";
loginData = new ExcelReadAndWrite("logindata", excelPath);
pmTests = new ExcelReadAndWrite("PMTestData", excelPath);
snmTests = new ExcelReadAndWrite("SNMTestData", excelPath);
ipData = new ExcelReadAndWrite("IP", excelPath);
}
@AfterSuite
public void afterSuite()
{
}
@Parameters({"browser"})
@BeforeClass
public void beforeClass(String browser)
{
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
if(browser.equalsIgnoreCase("firefox"))
{
driver = new FirefoxDriver(dc);
}
else if(browser.equalsIgnoreCase("chrome"))
{
driver = new ChromeDriver();
}
}
/*@Parameters("browser")
@BeforeClass
public void beforeClass()
{
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
driver = new FirefoxDriver(dc);
}*/
@AfterClass
public void afterClass()
{
driver.close();
}
@BeforeMethod
public void beforeMethod()
{
// driver.get("https://sqa.stackexchange.com/questions/36253/taking-screenshot-on-test-failure-selenium-webdriver-testng");
// System.out.println(driver);
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
@AfterMethod
public void afterMethod(ITestResult result) throws IOException
{
if(result.getStatus() == 2)
{
String methodName = result.getMethod().getMethodName();
new Take_Screenshot().get_Screenshot(driver, methodName);
}
}
}
But I am getting the "Parameter 'browser' is required by BeforeClass on method beforeClass but has not been marked @Optional or defined" error in maven project.
However when I run only testng.xml file it is absolutely working fine. The pro
当我从 pom.xml 文件运行 testng.xml 时出现问题。
下面是我定义了 testng.xml 的 POM.xml 文件的内容:
<profiles>
<profile>
<id>Regression</id>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
我在互联网上浏览了很多有关此问题的帖子,但没有找到任何解决方案。请有人帮我解决这个问题。
下面是我运行 mvn clean install 命令时的控制台日志
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@ba4d54
Tests run: 10, Failures: 2, Errors: 0, Skipped: 8, Time elapsed: 2.368 sec <<< FAILURE!
beforeClass(tests.PM_Extension_Test) Time elapsed: 2.098 sec <<< FAILURE!
org.testng.TestNGException:
Parameter 'browser' is required by BeforeClass on method beforeClass but has not been marked @Optional or defined
at org.testng.internal.Parameters.createParams(Parameters.java:289)
at org.testng.internal.Parameters.createParametersForMethod(Parameters.java:377)
at org.testng.internal.Parameters.createParameters(Parameters.java:721)
at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:164)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:275)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:176)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:122)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.testng.TestRunner.privateRun(TestRunner.java:770)
at org.testng.TestRunner.run(TestRunner.java:591)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at org.testng.SuiteRunner.run(SuiteRunner.java:304)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at org.testng.TestNG.runSuites(TestNG.java:1032)
at org.testng.TestNG.run(TestNG.java:1000)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:77)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:159)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:99)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
beforeClass(tests.PM_User_Test) Time elapsed: 0.002 sec <<< FAILURE!
org.testng.TestNGException:
Parameter 'browser' is required by BeforeClass on method beforeClass but has not been marked @Optional or defined
at org.testng.internal.Parameters.createParams(Parameters.java:289)
at org.testng.internal.Parameters.createParametersForMethod(Parameters.java:377)
at org.testng.internal.Parameters.createParameters(Parameters.java:721)
at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:164)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:275)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:176)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:122)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.testng.TestRunner.privateRun(TestRunner.java:770)
at org.testng.TestRunner.run(TestRunner.java:591)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
at org.testng.SuiteRunner.run(SuiteRunner.java:304)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
at org.testng.TestNG.runSuites(TestNG.java:1032)
at org.testng.TestNG.run(TestNG.java:1000)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:77)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:159)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:99)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Results :
Failed tests: beforeClass(tests.PM_Extension_Test): (..)
beforeClass(tests.PM_User_Test): (..)
Tests run: 10, Failures: 2, Errors: 0, Skipped: 8
[WARNING] Could not delete temp direcotry C:\Users\mallikar\git\PM\PM\target\surefire because Directory C:\Users\mallikar\git\PM\PM\target\surefire unable to be deleted.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.374 s
[INFO] Finished at: 2019-09-26T16:39:22+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project PM: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\mallikar\git\PM\PM\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
最佳答案
请尝试执行以下操作之一(应该可以解决您的问题)
@Parameters
是从包org.testng.annotations
导入的作为 TestNG 测试运行
,然后确保编辑运行配置并提供 JVM 参数-Dbrowser=火狐
mvn clean test -P Regression
(这将确保配置文件 Regression
被激活通过此,测试执行通过套件文件进行)关于java - maven项目中"Parameter '浏览器' is required by BeforeClass on method beforeClass but has not been marked @Optional or defined"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58109338/
我经常使用 var options = options || {} 作为默认为空对象的方式。它通常用于初始化选项对象,以防它未在函数调用的参数中传递。 问题是我在几个地方(博客文章、源代码)读到opt
我是Python中Rust的新手。这是我学习Rust的第四天。 在第一个问题Type casting for Option type之后,我有一个跟语法match和所有权概念有关的后续问题。 首先,我
我正在学习 Ray Wenderlich。我遇到了闭包语法错误。我想知道 Xcode 提示是什么意思? Xcode 报告如下: /Users/.../FlickrPhotosViewControlle
使用 Python 编写命令行界面 (CLI) 时 click library , 是否可以定义例如三个选项,其中仅当第一个(可选)未设置时才需要第二个和第三个选项? 我的用例是一个登录系统,它允许我
我有一个这样的 JPA 查询。 PersonRepository.java public Optional> findByStatus(int status); 人员服务.java System.ou
我遇到了很多地方,我有类似的东西 def f(s: String): Option[Long] = ... def g(l: Long): IO[Option[Wibble]] = ... val a
我有一个results: List[Future[Option[T]]]其中包含(并行)计算。 我想获得第一个非None尽快出结果,或者返回None如果所有计算都返回 None . 目前,我正在这样做
我正在尝试加载一个简单的 Listbox组件来自 @headlessui/react . 选择.tsx type Option = { id: number name: string
如何将Future[Option[Future[Option[X]]]]转换为Future[Option[X]]? 如果它是 TraversableOnce 而不是 Option 我会使用 Futur
Haskell、Rust 等语言提供了一个 Maybe 或 Option 类型。即使在 Java 中,也有一个 Optional 现在打字。 为简单起见,我将在剩下的问题中将此类型称为“选项类型”。
当我尝试在 SQL 中存储一个 XML 而不是一个空元素时,SQL 只是更改它并仅使用一个元素标签来存储它。例如,要存储的 XML 是: ROGER 然后Sql存起来就好了
使用这个非常好的命令行解析器 Argo(仅 header C++ 库)我遇到了一个小问题。请参阅:https://github.com/phforest/Argo Argo 返回:'Error: Un
我是来自 Java 背景的 Scala 新手,目前对考虑 Option[T] 的最佳实践感到困惑. 我觉得用 Option.map只是更实用和美观,但这不是说服其他人的好理由。有时, isEmpty
这个问题在这里已经有了答案: Chaining Optionals in Java 8 (9 个回答) Optional orElse Optional in Java (6 个回答) Functio
Optional::stream如果存在,则返回一个包含该值的 Stream,否则返回一个空流。所以对于 Stream> optionals , optionals.flatMap(Optional:
我使用箭头键作为输入,在 printf 菜单中上下移动 printf 箭头(“==>”)。 我正在使用一个函数来计算箭头应该在的位置,并使用 switch case 和 printf("\n==>")
这个问题在这里已经有了答案: What does the construct x = x || y mean? (12 个答案) 关闭 9 年前。 如我的问题标题所述,我最近偶然发现了这个变量声明:
这个问题在这里已经有了答案: BackboneJS: What is options || (options = {}); in Backbone source code (1 个回答) 关闭 8
我有这个简单的语法: word = Word(alphanums + '_') with_stmt = Suppress('with') + OneOrMore(Group(word('key') +
使用 Cucumber 和 SitePrism 编写测试,我在页面上有以下 HTML... Select a Status Active Product Inactive Prod
我是一名优秀的程序员,十分优秀!