ソース:JUnit 5、Eclipse 4.8、Selenium
私は特別なテストフレームワークなしでSeleniumスクリプトを記述して実行できますが、他のツールと依存関係があるためJunit 5を使用したいと思いましたが、現在はJunit 5であり、何らかのアイデアを得るためにGoogleで検索しましたが、問題を解決できません。
テストスクリプト:
package login;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.Selenium.By;
import org.openqa.Selenium.WebDriver;
import org.openqa.Selenium.WebElement;
public class loginTest {
public WebDriver driver = null ;
public loginTest(WebDriver driver)
{
this.driver=driver;
}
@BeforeEach
public void setUp() throws Exception
{
driver.get("google.com");
System.out.println("Page title is: " + driver.getTitle());
}
@Test
public void test() {
// some action here I have in original script
System.out.println("Page title is: " + driver.getTitle());
}
@AfterEach
public void tearDown() throws Exception
{
driver.quit();
}
}
スタックトレース:
org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [org.openqa.Selenium.WebDriver arg0] in executable [public login.loginTest(org.openqa.Selenium.WebDriver)].
at org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameter(ExecutableInvoker.Java:191)
at org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameters(ExecutableInvoker.Java:174)
at org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameters(ExecutableInvoker.Java:135)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.Java:61)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateTestClass(ClassTestDescriptor.Java:208)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateAndPostProcessTestInstance(ClassTestDescriptor.Java:195)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$0(ClassTestDescriptor.Java:185)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$1(ClassTestDescriptor.Java:189)
at Java.util.Optional.orElseGet(Unknown Source)
at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$2(ClassTestDescriptor.Java:188)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.Java:81)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.Java:58)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.prepare(HierarchicalTestExecutor.Java:89)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.Java:74)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.Java:120)
at Java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source)
at Java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)
at Java.util.Iterator.forEachRemaining(Unknown Source)
at Java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source)
at Java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at Java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at Java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
at Java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
at Java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at Java.util.stream.ReferencePipeline.forEach(Unknown Source)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.Java:120)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.Java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.Java:108)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.Java:79)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.Java:120)
at Java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source)
at Java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)
at Java.util.Iterator.forEachRemaining(Unknown Source)
at Java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source)
at Java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at Java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at Java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
at Java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
at Java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at Java.util.stream.ReferencePipeline.forEach(Unknown Source)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.Java:120)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.Java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.Java:108)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.Java:79)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.Java:55)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.Java:43)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.Java:170)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.Java:154)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.Java:90)
at org.Eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.Java:86)
at org.Eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.Java:38)
at org.Eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.Java:538)
at org.Eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.Java:760)
at org.Eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.Java:460)
at org.Eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.Java:206)
Marc Philippがコメントで述べたように、JUnit Jupiterがテストクラスをインスタンス化できることを確認する必要があります。
特定のシナリオでは、WebDriver
を受け入れるカスタムコンストラクターを削除する必要があります。
次に、2つのオプションがあります。
WebDriver
を自分で作成します。たとえば、@BeforeAll
または@BeforeEach
方法。WebDriver
を管理しやすくします。JUnit 5でParameterResolutionException
も取得しました。
org.junit.jupiter.api.extension.ParameterResolutionException:
No ParameterResolver registered for parameter [int[] arg0] in constructor (public my_package.MyClass(int[]))
私は@Test
私がテストしていたクラス内のメソッド。
このエラーは、次の2つの方法で修正できます。
1)import org.junit.jupiter.api.Test
with import org.junit.Test
、または
2)別のTestClassでテストを作成します。
両方持っていた@Test
および@ParameterizedTest
同じメソッドに注釈を付けます。前者を削除しました。