当前位置: 首页 > 知识库问答 >
问题:

spring-boot应用程序中的硒-自动连接问题

申屠无尘
2023-03-14

我试图在一个spring-boot应用程序中运行一个selenium测试(通过GalenFramework完成)。我面临的问题是在自动驾驶部分。由于NULLPOINTER异常,我无法将AppDetails类自动连接到测试类中。

在尝试单独运行测试时(直接从IntelliJmvn test-dtest=testclassname方法),我得到了nullpointer异常。
但我能够运行(mvn spring-boot:run)应用程序,这不是必需的,即使我试图运行应用程序以确保正确读取yaml文件(shirtuserurl)中的值。

这是课程。

application.java类
[d:\workspace\galen-tester\galen-tester\src\main\java\com\shirt\library\galen\application.java]

package com.shirt.library.galen;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public String getTestName() {
        return "some name";
    }
}

测试类
[D:\workspace\galen-tester\galen-tester\src\Test\java\com\shirt\library\galen\user\usertestui.java]

package com.shirt.library.galen.user;

import com.shirt.library.galen.Application;
import com.shirt.library.galen.components.GalenTestConfig;
import com.shirt.library.galen.components.TestDevice;
import com.shirt.library.galen.models.AppDetails;
import com.galenframework.config.GalenConfig;
import com.galenframework.config.GalenProperty;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.testng.annotations.Test;

import java.io.IOException;

//@ActiveProfiles("test")
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration(classes = Application.class)
public class UserTestUI extends GalenTestConfig {

    @Autowired
    private AppDetails appDetails; <-- This comes as NULL 

    @Autowired
    String getTestName;

    @Test (dataProvider = "devices")
    public void test_user_onDevice(TestDevice devices) throws IOException {
        GalenConfig.getConfig().setProperty(GalenProperty.GALEN_RANGE_APPROXIMATION,"5");
        System.out.println("Full URL : " + appDetails.getFullURL());  <----- NULLPOINTER exception here 
        loadAppInBrowser("user");
        loginAuthWithCredentials();
        CheckLayout(devices);


    }
package com.shirt.library.galen.models;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class AppDetails {

    @Value("${shirtuserurl}")
    private String fullURL;


    //@Bean
    public String getFullURL() {
        return fullURL;
    }
}

如果有人对此有任何想法,请告诉我。

注意:
我使用的是spring-boot版本1.5.10.release

共有1个答案

杜鸿彩
2023-03-14

试着使用这些注释:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
@WebAppConfiguration
 类似资料:
  • 我正在尝试将现有的传统spring应用程序转换为Spring Boot程序。我已经用@ImportResource和运行应用程序时导入了XML配置。即使这个bean是在XML配置中配置的,它的抛出注入也失败了。我不知道这里出了什么问题 >Application.java

  • 在Spring Boot应用程序中,我有一个类如下: 我想在其他类ABC中使用上述内容,如: 它抛出找不到XYZ的错误。在编写主方法的类中,我已经有@SpringBootApplication。因此,这将自动在包上启用@ComponentScan。ABC在spring配置文件中创建为bean。我的理解是,由于XYZ是用@service注释的,所以spring会扫描、创建并注册该bean。如何在不使

  • 未能配置数据源:未指定“url”属性,无法配置任何嵌入的数据源。 原因:未能确定合适的驱动程序类 行动:

  • 我正在编写一个Spring Boot应用程序,它与Snowflake数据仓库连接,并对其执行SQL查询。我编写了一个配置类,用于配置数据源以连接到Snowflake数据仓库,如下所示: 我的pom.xml如下: 在我的Spring boot应用程序中,我必须为这个数据源使用一个连接池。 如何在我的应用程序中使用HikariCP连接池,它可以与我的定制数据源完美配合? ------编辑---感谢您提

  • 我在登录表单中使用这段代码发布来自电子邮件和密码字段的数据。我正面临一个错误,但没有得到任何响应。错误为: 2017-05-01 10:58:06.236 PK.Estate[13412:4023436]应用程序传输安全已阻止明文HTTP(HTTP://)资源加载,因为它不安全。可以通过应用程序的info.plist文件配置临时异常。2017-05-01 10:58:06.397 PK.Estat