在我工作的项目中,我试图在没有TestNG的情况下使用Galen(所以,基于JUnit的版本)。
这是我为我所做的示例课程编写的代码:
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import com.galenframework.support.GalenJavaTestBase;
import com.galenframework.testng.GalenTestNgTestBase;
import org.apache.xmlbeans.impl.tool.Extension;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.galenframework.junit.GalenJUnitTestBase;
public class GalenTesting extends GalenJUnitTestBase {
@Override
public WebDriver createDriver() {
System.setProperty("webdriver.chrome.driver","C:/Drivers/chromedriver.exe");
WebDriver driver = new ChromeDriver();
return driver;
}
@Test
public void welcomePage_shouldLookGood_onDesktopDevice() throws IOException {
super.load("http://www.google.com", 1024, 768);
super.checkLayout("/specs/welcomePage.spec", Arrays.asList("mobile"));
}
这几乎可以在Galen doc for Java usage中找到。 我遇到运行此代码的问题,因为它声明:
java.lang.Exception: No public static parameters method on class it.automationTest.GalenTesting
at org.junit.runners.Parameterized.getParametersMethod(Parameterized.java:299)
at org.junit.runners.Parameterized.<init>(Parameterized.java:246)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
Process finished with exit code -1
起初,我认为这是指方法&#39;调用&#34; welcomePage_shouldLookGood_onDesktopDevice()&#34;方法,所以我插入了一个super.methodName()来尝试修复它,但它没有工作。 我还试图阅读所有超类的源代码,但我找不到任何有用的东西可以帮助我防止这种异常。 有人能指出我正确的方向吗?
根据要求,这是代码的更新版本。 它现在包含一个可测试设备的可迭代方法(正如指出hypery2k)。 原始问题已解决,因为createDriver()方法仅使用@Overriden注释,而它应该仅使用@Test注释。现在我面临以下问题,首先我将更新新代码,然后是堆栈错误。
import java.io.IOException;
import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import com.galenframework.junit.GalenJUnitTestBase;
public class GalenTesting extends GalenJUnitTestBase {
WebDriver driver;
public GalenTesting() {
super();
}
@Override
public WebDriver createDriver() {
createDriverVoid();
return driver;
}
@Test
public void createDriverVoid() {
System.setProperty("webdriver.chrome.driver","C:/Drivers/chromedriver.exe");
driver = new ChromeDriver();
}
@Test
public void welcomePage_shouldLookGood_onDesktopDevice() throws IOException {
super.load("http://www.google.com", 1024, 768);
super.checkLayout("/specs/welcomePage.spec", Arrays.asList("mobile"));
}
@Parameterized.Parameters
public static Iterable<Object[]> devices() {
return Arrays.asList(new Object[][]{// @formatter:off
{new TestDevice("desktop", new Dimension(1024, 800), Arrays.asList("normal", "desktop"))},
{new TestDevice("fullhd", new Dimension(1920, 1080), Arrays.asList("fullhd", "desktop"))},// @formatter:on
});
}
}
该类现在给出以下错误:
java.lang.Exception: No tests found matching createDriver with any parameter from org.junit.runner.Request$1@2d6a9952
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
Process finished with exit code -1
我一直在尝试使用我添加的一些方法(比如调用super()的构造函数),但它仍然会出现相同的错误。即使使用原始固定代码,它也会返回相同的错误。
答案 0 :(得分:0)
当您使用基于 JUnit
的 Galen
框架时,我建议如下进行2次快速更改:
@Override
注释更改为 @Test
注释或有效注释。crome
chrome
更改为 "webdriver.crome.driver"
答案 1 :(得分:0)
您缺少测试用例的参数,请参阅here以获取完整示例:
@Parameters
public static Iterable<Object[]> devices() {
return Arrays.asList(new Object[][]{// @formatter:off
{new TestDevice("small-phone", new Dimension(280, 800), asList("small-phone", "phone", "mobile"))},
{new TestDevice("normal-phone", new Dimension(320, 800), asList("normal-phone", "phone", "mobile"))},
{new TestDevice("big-phone", new Dimension(380, 800), asList("big-phone", "phone", "mobile"))},
{new TestDevice("small-tablet", new Dimension(450, 800), asList("small-tablet", "tablet", "mobile"))},
{new TestDevice("normal-tablet", new Dimension(450, 800), asList("normal-tablet", "tablet", "mobile"))},
{new TestDevice("desktop", new Dimension(1024, 800), asList("normal", "desktop"))},
{new TestDevice("fullhd", new Dimension(1920, 1080), asList("fullhd", "desktop"))},// @formatter:on
});
}