我正在使用dropwizard版本0.7.1。它被配置为使用“随机”(ephemeral?)端口(server.applicationConnectors.port = 0)。我想在启动后获得真正使用的端口,但我找不到任何有关如何执行此操作的信息。
答案 0 :(得分:7)
您可以从生命周期监听器获取serverStarted
回调来解决这个问题。
@Override
public void run(ExampleConfiguration configuration, Environment environment) throws Exception {
environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() {
@Override
public void serverStarted(Server server) {
for (Connector connector : server.getConnectors()) {
if (connector instanceof ServerConnector) {
ServerConnector serverConnector = (ServerConnector) connector;
System.out.println(serverConnector.getName() + " " + serverConnector.getLocalPort());
// Do something useful with serverConnector.getLocalPort()
}
}
}
});
}
答案 1 :(得分:3)
我发现使用Dropwizard中的简单和默认服务器配置,这种方法对我来说效果很好。
module.exports = {
'Log into system - create order': function (client) {
client
.url('XXXX')
.waitForElementVisible('body', 1000)
.assert.title('Reach - Log in')
.assert.visible('#UserName')
.setValue('#UserName', 'XXXX')
.assert.visible('#Password')
.setValue('#Password', 'XXXX')
.assert.visible('input[value="Login"]')
.click('input[value="Login"]')
.waitForElementVisible('img.test', 1000)
.assert.visible('li[title="XXXX"] a[tabindex="5"]')
.click('li[title="Sales"]')
.assert.cssClassPresent('li[title="XXXX"]', 'active')
.click('a[href="/Quotes/Add"]')
.waitForElementVisible('#s2id_CustomerId_Remote', 1000)
.click('#s2id_CustomerId_Remote')
.assert.visible('#s2id_autogen2_search')
.setValue('#s2id_autogen2_search', 'bik')
.waitForElementVisible('.select2-highlighted', 1000)
.click('.select2-highlighted')
.waitForElementVisible('#customerNotes', 1000)
.click('#s2id_ProductId_Remote')
.assert.visible('#s2id_autogen3_search')
.setValue('#s2id_autogen3_search', '123XP')
.pause(5000)
.assert.visible('.select2-highlighted')
.click('.select2-highlighted')
.pause(5000)
.assert.visible('.ui-sortable > tr')
.setValue('#Quote_PONumber', 'abc123')
.click('input[value="Create Order"]')
.waitForElementVisible('.ac-order-number', 1000)
.assert.visible('a[data-value="abc123"]')
.pause(5000)
.end()
}
}