如何运行 https中的geb功能测试?
how to run geb functional test in https?
我的应用程序要求应用程序在 https 中 运行,因为浏览器通过 javascript 库将支付数据发送到支付网关。
如果应用程序在 http 中 运行,则支付网关会抛出此错误。
我创建了一个简单的 hello world 应用程序并编写了一个简单的 geb 规范。
我似乎找不到以 https 模式 运行 服务器的方法。我也没有在网上找到任何有用的资源。
现在 运行在 运行dom 端口
中处于 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 运行 配置中设置 https 端口,如下所示。
我已经在github中发布了应用程序代码以供参考。
https://github.com/learningcscience/gebhttps
感谢您的帮助。谢谢!
更新:
今天我觉得我进步了一点。
我现在可以 运行 固定端口中的应用程序。我 运行 8443 中的 app 是 https.
我使用 spring 启动测试注释
@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.
https://docs.grails.org/latest/guide/testing.html
现在我只需要使用 https 而不是 http 制作应用 运行。
我已经更新了 github 仓库中的代码。
https://github.com/learningcscience/gebhttps
感谢您的帮助!谢谢!
好的。问题终于解决了
最后的帮助来自 https://grails.slack.com/
的 grails 社区
感谢 Mattias Reichel 的帮助。
我现在将逐步进行,这样其他人就不会遇到这个问题。
为了 运行 在 https 中进行功能性 geb 测试,您首先需要按照上面的更新:部分所述添加 SpringBootTest 注释。
我又来贴了
@Integration
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class EventCreationSpec extends GebSpec {
然后在 src/integration-test/resources/GebConfig.groovy.
中设置 baseurl
我把 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/integration-test/resources/
中创建一个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/2017-06-28.html
在上面的配置中
我的证书在路径 c:/Users/user/selfsigned.jks
中的 selfsigned.jks 密钥库中
之后功能测试将在 https 模式下触发
就我而言
http://localhost:8443/roadrace
这是 gebspec 的样子
注意顶部的 SpringBootTest 注释。
@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 的方法,您可以点击 Advanced 然后 Proceed to localhost (unsafe) 链接
我只是点击这样的链接
去'/roadrace/'
$("#details-button").click()
$("#proceed-link").click()
就是这样!现在 https 中的 geb 功能测试 运行s。由于它是 https,您现在也可以与测试支付网关通信。
我的应用程序要求应用程序在 https 中 运行,因为浏览器通过 javascript 库将支付数据发送到支付网关。
如果应用程序在 http 中 运行,则支付网关会抛出此错误。
我创建了一个简单的 hello world 应用程序并编写了一个简单的 geb 规范。
我似乎找不到以 https 模式 运行 服务器的方法。我也没有在网上找到任何有用的资源。
现在 运行在 运行dom 端口
中处于 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 运行 配置中设置 https 端口,如下所示。
我已经在github中发布了应用程序代码以供参考。
https://github.com/learningcscience/gebhttps
感谢您的帮助。谢谢!
更新:
今天我觉得我进步了一点。
我现在可以 运行 固定端口中的应用程序。我 运行 8443 中的 app 是 https.
我使用 spring 启动测试注释
@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.
https://docs.grails.org/latest/guide/testing.html
现在我只需要使用 https 而不是 http 制作应用 运行。
我已经更新了 github 仓库中的代码。
https://github.com/learningcscience/gebhttps
感谢您的帮助!谢谢!
好的。问题终于解决了
最后的帮助来自 https://grails.slack.com/
的 grails 社区感谢 Mattias Reichel 的帮助。
我现在将逐步进行,这样其他人就不会遇到这个问题。
为了 运行 在 https 中进行功能性 geb 测试,您首先需要按照上面的更新:部分所述添加 SpringBootTest 注释。
我又来贴了
@Integration
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class EventCreationSpec extends GebSpec {
然后在 src/integration-test/resources/GebConfig.groovy.
中设置 baseurl我把 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/integration-test/resources/
中创建一个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/2017-06-28.html
在上面的配置中
我的证书在路径 c:/Users/user/selfsigned.jks
中的 selfsigned.jks 密钥库中之后功能测试将在 https 模式下触发
就我而言
http://localhost:8443/roadrace
这是 gebspec 的样子
注意顶部的 SpringBootTest 注释。
@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 的方法,您可以点击 Advanced 然后 Proceed to localhost (unsafe) 链接
我只是点击这样的链接
去'/roadrace/'
$("#details-button").click()
$("#proceed-link").click()
就是这样!现在 https 中的 geb 功能测试 运行s。由于它是 https,您现在也可以与测试支付网关通信。