Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Galen无公共静态参数法_Java_Selenium_Screenshot_Galen - Fatal编程技术网

Java Galen无公共静态参数法

Java Galen无公共静态参数法,java,selenium,screenshot,galen,Java,Selenium,Screenshot,Galen,在我正在工作的一个项目中,我试图在不使用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;

在我正在工作的一个项目中,我试图在不使用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文档中Java用法的代码非常相似。 我在运行此代码时遇到问题,因为它指出:

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

我一直试图搞乱我添加的一些方法(比如调用super()的构造函数),但它仍然会给出相同的错误。即使使用原始的固定代码,它也会返回相同的错误。

当您使用基于JUnit的
框架时,我建议您进行以下两种快速更改:

  • @Override
    注释更改为
    @Test
    注释或有效注释
  • 在“webdriver.crome.driver”中将
    crome
    更改为
    chrome

您缺少测试用例的参数,请参阅以下完整示例:

@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
    });
}
@参数
公共静态可写设备(){
返回Arrays.asList(新对象[][]{/@formatter:off
{新的测试设备(“小型电话”,新尺寸(280800),asList(“小型电话”,“电话”,“手机”)},
{新的测试设备(“普通电话”,新尺寸(320800),asList(“普通电话”,“电话”,“手机”)},
{新的测试设备(“大电话”,新尺寸(380800),asList(“大电话”,“电话”,“手机”)},
{新的测试设备(“小型平板电脑”、新尺寸(450800)、asList(“小型平板电脑”、“平板电脑”、“手机”)},
{新的测试设备(“普通平板电脑”、新尺寸(450800)、asList(“普通平板电脑”、“平板电脑”、“手机”)},
{newtestdevice(“桌面”,新维度(1024800),asList(“普通”,“桌面”)},
{newtestdevice(“fullhd”,新维度(19201080),asList(“fullhd”,“desktop”)},//@formatter:on
});
}

感谢您伸出援手!1) @Override表示法是强制性的,因为我用一个抽象方法扩展一个类(或者,即使我用其他方法修改它,它也不能解决这个问题);2) 谢谢:我没有注意到这个拼写错误,但它没有解决评论的问题!它现在说“java.lang.Exception:找不到任何参数匹配createDriver的测试”,您可以再次发布测试类吗?我想你已经在createDriver方法上进行了@Test@hypery2k,刚刚添加了!请删除createDriverVoid处的测试批注如果我尝试删除createDriverVoid处的@test,则出现相同错误
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
@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
    });
}