如何在HTTPS中运行GEB功能测试?

发布于 2025-01-21 16:23:52 字数 1800 浏览 3 评论 0原文

我的应用程序要求该应用程序在HTTPS中运行,因为浏览器将付款数据通过JavaScript库发送到付款网关。

如果该应用程序是在HTTP中运行的,则该错误将由付款网关丢弃。

我创建了一个简单的Hello World应用程序,并编写了一个简单的GEB规范。

我似乎找不到在HTTPS模式下运行服务器的方法。我也没有在网络中找到任何有用的资源。

目前,它正在以随机端口的http模式运行:

Grails application running at http://localhost:54461 in environment: test

我尝试在build.gradle中添加https端口,

integrationTest {
    systemProperty "webdriver.chrome.driver", "C:\\webdrivers\\chromedriver.exe"

    jvmArgs(
            '-Dgrails.server.port.https=8443'
    )


}

但这似乎被忽略了。

我还尝试在Intellij Run配置中设置HTTPS端口,如下所示。

我已经在Github中发布了应用程序代码以供参考。

https://github.com/learningcscience/gebhttps

今天我想更新了我的更新

我现在可以在固定端口中运行该应用程序。我在8443中运行了该应用程序,该应用程序适用于HTTPS。

Spring Boot测试注释进行了此操作

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)

我使用控制台中的

Grails application running at http://localhost:8443 in environment: test
Starting ChromeDriver 100.0.4896.20 (f9d71f93d32a6487809d6f35a9670c879fe97dfe-refs/branch-heads/4896@{#203}) on port 31898
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.

。 。

我已经在GitHub Repo中更新了代码。

My application requires the app to run in https since the browser sends payment data to payment gateway through JavaScript library.

If the app is run in http then this error is thrown by the payment gateway.

enter image description here

I have created a simple hello world app and wrote a simple geb spec.

I don't seem to find a way to run the server in https mode. I don't find any helpful resource in the web as well.

Right now it is running in http mode in random port:

Grails application running at http://localhost:54461 in environment: test

I have tried adding https port in build.gradle as

integrationTest {
    systemProperty "webdriver.chrome.driver", "C:\\webdrivers\\chromedriver.exe"

    jvmArgs(
            '-Dgrails.server.port.https=8443'
    )


}

But that seems to get ignored.

I have also tried setting the https port in IntelliJ run configuration as shown below.

enter image description here

I have published the app code in GitHub for reference.

https://github.com/learningcscience/gebhttps

Update

Today I think I made a little more progress.

I could now run the app in a fixed port. I ran the app in 8443 which is for https.

I did this using the spring boot test annotation

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)

In the console now it shows

Grails application running at http://localhost:8443 in environment: test
Starting ChromeDriver 100.0.4896.20 (f9d71f93d32a6487809d6f35a9670c879fe97dfe-refs/branch-heads/4896@{#203}) on port 31898
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.

https://docs.grails.org/latest/guide/testing.html

Now I just need to make the app run using the https rather than http.

I have updated the code in GitHub repo.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谷夏 2025-01-28 16:23:52

好的。问题最终解决了。

最后的帮助来自 https://grails.slack.com/

感谢Mattias Reichel的 https://grails.slack.com/

我现在要逐步进行一步,以便其他人可能不会遇到这个问题。

为了在HTTPS中运行功能性GEB测试,您首先需要将Springboott注释放置如上所述:部分。

我再次将

@Integration
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class EventCreationSpec extends GebSpec {

之后,

其粘贴在SRC/Integration-Test/resources/gebconfig.groovy中。我将baseurl =“ https:// localhost:8443/”

我的gebconfig看起来像这样

import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.firefox.FirefoxDriver

environments {




    // run via “./gradlew -Dgeb.env=chrome iT”
    chrome {
        driver = {

            System.setProperty('webdriver.chrome.driver', 'C:\\webdrivers\\chromedriver.exe')
            new ChromeDriver()

        }
    }

    // run via “./gradlew -Dgeb.env=chromeHeadless iT”
    chromeHeadless {
        driver = {
            ChromeOptions o = new ChromeOptions()
            o.addArguments('headless')
            new ChromeDriver(o)
        }
    }

    // run via “./gradlew -Dgeb.env=firefox iT”
    firefox {
        driver = { new FirefoxDriver() }
    }
}

baseUrl = "https://localhost:8443/"

,您需要在src/intementation-test/resources/application-

resative/ application-test.yml文件中创建一个application-test.yml文件看起来像 。

server:
    port: 8443
    ssl:
        enabled: true
        keyStore: c:/Users/user/selfsigned.jks
        keyStorePassword: pepsicola
        keyAlias: tomcat

您需要创建自签名的证书

您可以通过此过程来创建证书

https://grails.org/blog/blog/ 2017-06-28.html

上方的配置

证书

我的 :// localhost:8443/Roadrace

这是GEBSPEC应该看起来像是

在顶部注意的Springboott最新注释。

@Integration
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@Stepwise
class EventCreationSpec extends GebSpec {


    def grailsApplication
    def springSecurityService
    def timeService



    def setup() {

    }

    def cleanup() {
    }

    void "Create and publish event"() {
        when:"The home page is visited"
        go '/roadrace/'

        $("#details-button").click()
        $("#proceed-link").click()


          ... rest of gebspock test steps....



        then:"The title is correct"
            title == "Homepage"
    }


}

请注意,我必须去 / RoadRace /,因为RoadRace是应用程序上下文路径。

如果您没有上下文路径,则可以去'/'

最终障碍可能是当浏览器在https中启动时,它可能显示

“在此处输入映像”

为此,您可以使用GEB单击高级对于Localhost(不安全)链接,

我只需单击这样的链接,

请访问'/Roadrace/'

$("#details-button").click()
$("#proceed-link").click()

就是这样!现在,GEB功能测试在HTTPS中运行。由于是HTTPS,您现在也可以通信测试付款网关。

ok. The problem is finally solved.

The last help came from the grails community at https://grails.slack.com/

Thanks Mattias Reichel for the help.

I am now going to put step by step process so that others might not get stuck with this issue.

In order to run functional geb test in https you first need to put SpringBootTest annotation as mentioned in above UPDATE: section.

I am pasting here again

@Integration
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class EventCreationSpec extends GebSpec {

After that you set baseurl in src/integration-test/resources/GebConfig.groovy.

I put baseUrl = "https://localhost:8443/"

My GebConfig looks like this

import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.firefox.FirefoxDriver

environments {




    // run via “./gradlew -Dgeb.env=chrome iT”
    chrome {
        driver = {

            System.setProperty('webdriver.chrome.driver', 'C:\\webdrivers\\chromedriver.exe')
            new ChromeDriver()

        }
    }

    // run via “./gradlew -Dgeb.env=chromeHeadless iT”
    chromeHeadless {
        driver = {
            ChromeOptions o = new ChromeOptions()
            o.addArguments('headless')
            new ChromeDriver(o)
        }
    }

    // run via “./gradlew -Dgeb.env=firefox iT”
    firefox {
        driver = { new FirefoxDriver() }
    }
}

baseUrl = "https://localhost:8443/"

After that you need to create a application-test.yml file in src/integration-test/resources/

The application-test.yml file looks like this

server:
    port: 8443
    ssl:
        enabled: true
        keyStore: c:/Users/user/selfsigned.jks
        keyStorePassword: pepsicola
        keyAlias: tomcat

you need to create self signed certificate.

You can go through this process to create the certificate

https://grails.org/blog/2017-06-28.html

In the configuration above

my certificate was in selfsigned.jks keystore in the path c:/Users/user/selfsigned.jks

After that the functional test will fire in https mode

In my case

http://localhost:8443/roadrace

here is what the gebspec should look like

Note the SpringBootTest annotation at the top.

@Integration
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@Stepwise
class EventCreationSpec extends GebSpec {


    def grailsApplication
    def springSecurityService
    def timeService



    def setup() {

    }

    def cleanup() {
    }

    void "Create and publish event"() {
        when:"The home page is visited"
        go '/roadrace/'

        $("#details-button").click()
        $("#proceed-link").click()


          ... rest of gebspock test steps....



        then:"The title is correct"
            title == "Homepage"
    }


}

Please note that i had to go to /roadrace/ because the roadrace is the app context path.

If you dont have context path you can go to go '/'

The final hurdle can be when the browser fires up in https it might show

enter image description here

For this using geb you can click on the Advanced and then Proceed to localhost (unsafe) links

I just click the links like this

go '/roadrace/'

$("#details-button").click()
$("#proceed-link").click()

That's all! Now the geb functional test runs in https. Since it is https you can also now communicate to test payment gateway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文