Skip to content

Commit

Permalink
web wip, using floating log window from wicket
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrthomas committed May 1, 2017
1 parent 3450222 commit 1ff1d8d
Show file tree
Hide file tree
Showing 18 changed files with 337 additions and 215 deletions.
1 change: 1 addition & 0 deletions karate-web/src/main/java/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
spring.jackson.default-property-inclusion=NON_NULL
wicket.configuration=deployment


Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<div class="container-fluid">
<div wicket:id="sticky-header"></div>
<div class="container-fluid">
<div class="row">
<div class="col-xs-2">
<div class="kt-leftnav">
Expand All @@ -21,13 +22,11 @@
</div>
</div>
</div>
<div class="col-xs-10">
<div wicket:id="sticky-header"></div>
<div class="col-xs-10">
<div wicket:id="header"></div>
<div wicket:id="content"></div>
<div wicket:id="sticky-footer"></div>
<div wicket:id="content"></div>
</div>
</div>
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ public class BasePage extends WebPage {
public static final String HEADER_ID = "header";
public static final String CONTENT_ID = "content";
public static final String STICKY_HEADER_ID = "sticky-header";
public static final String STICKY_FOOTER_ID = "sticky-footer";

public BasePage() {
public BasePage() {
add(new LeftNavPanel(LEFT_NAV_ID));
add(new Label(STICKY_HEADER_ID, "").setOutputMarkupId(true));
add(new HeaderPanel(HEADER_ID));
add(new Label(CONTENT_ID, ""));
add(new Label(STICKY_FOOTER_ID, "").setOutputMarkupId(true));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,23 @@
*/
package com.intuit.karate.web.wicket;

import com.intuit.karate.web.config.LogAppenderTarget;
import com.intuit.karate.web.config.WebSocketLogAppender;
import com.intuit.karate.web.service.KarateService;
import com.intuit.karate.web.service.KarateSession;
import com.jayway.jsonpath.JsonPath;
import java.util.HashMap;
import java.util.Map;
import org.apache.wicket.Application;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.protocol.ws.WebSocketSettings;
import org.apache.wicket.protocol.ws.api.IWebSocketConnection;
import org.apache.wicket.protocol.ws.api.WebSocketBehavior;
import org.apache.wicket.protocol.ws.api.message.ConnectedMessage;
import org.apache.wicket.protocol.ws.api.registry.IKey;
import org.apache.wicket.protocol.ws.api.registry.IWebSocketConnectionRegistry;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -38,45 +48,66 @@
*
* @author pthomas3
*/
public class FeaturePage extends BasePage {
public class FeaturePage extends BasePage implements LogAppenderTarget {

private static final Logger logger = LoggerFactory.getLogger(FeaturePage.class);

@SpringBean(required = true)
private KarateService service;

private final LogPanel logPanel;

public LogPanel getLogPanel() {
return logPanel;
}
private String webSocketSessionId;
private IKey webSocketClientKey;

public FeaturePage(String sessionId) {
replace(new Label(HEADER_ID, ""));
replace(new FeaturePanel(CONTENT_ID, sessionId));
replace(new VarsPanel(LEFT_NAV_ID, sessionId));
logPanel = new LogPanel(STICKY_FOOTER_ID, sessionId);
add(new WebSocketBehavior() {
@Override
protected void onConnect(ConnectedMessage message) {
KarateSession session = service.getSession(sessionId);
webSocketSessionId = message.getSessionId();
webSocketClientKey = message.getKey();
WebSocketLogAppender appender = session.getAppender();
logPanel.onConnect(message);
appender.setTarget(logPanel);
appender.setTarget(FeaturePage.this);
logger.debug("websocket client connected, session: {}", message.getSessionId());
}
});
}

@Override
public void append(String text) {
Map<String, Object> map = new HashMap(1);
map.put("text", text);
String json = JsonPath.parse(map).jsonString();
pushJsonWebSocketMessage(json);
}

public void pushJsonWebSocketMessage(String json) {
Application application = Application.get();
WebSocketSettings settings = WebSocketSettings.Holder.get(application);
IWebSocketConnectionRegistry registry = settings.getConnectionRegistry();
IWebSocketConnection connection = registry.getConnection(application, webSocketSessionId, webSocketClientKey);
if (connection == null) {
logger.warn("websocket client lookup failed for web-socket session: {}", webSocketSessionId);
return;
}
try {
connection.sendMessage(json);
} catch (Exception e) {
logger.error("websocket push failed", e);
}
}

@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
String script = "Wicket.Event.subscribe(\"/websocket/message\", function(jqEvent, message) {\n"
+ " message = JSON.parse(message);\n"
+ " if (message.type == 'step') updateStep(message); else updateLog(message);\n"
+ " if (message.type == 'step') updateStep(message); else { Karate.Ajax.DebugWindow.logInfo(message.text); }\n"
+ "});\n"
+ "function updateStep(message){ var btn = jQuery('#' + message.buttonId); btn.addClass('btn-success'); }\n"
+ logPanel.getUpdateScript();
+ "function updateStep(message){ var btn = jQuery('#' + message.buttonId); btn.addClass('btn-success'); }";
response.render(JavaScriptHeaderItem.forScript(script, "karate-ws-js"));
response.render(JavaScriptHeaderItem.forReference(KarateJsResourceReference.INSTANCE));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="kt-section-header">
<button class="btn btn-primary btn-sm" wicket:id="run-all">Run All</button>
</div>
<div class="kt-section">
<div class="kt-section" style="height:35em; overflow: auto">
<div wicket:id="scenario.steps">
<div wicket:id="step"></div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ protected void populateItem(ListItem<StepWrapper> li) {
public void onClick(AjaxRequestTarget target) {
KarateSession session = service.getSession(model.getSessionId());
KarateBackend backend = session.getBackend();
LogPanel logPanel = ((FeaturePage) getPage()).getLogPanel();
FeaturePage featurePage = (FeaturePage) getPage();
for (ListItem<StepWrapper> li : listItems) {
StepWrapper step = li.getModelObject();
StepResult result = step.run(backend);
step.setPassed(result.isPass());
StepPanel stepPanel = (StepPanel) li.get("step");
String json = JsonUtils.toJsonString(
"{ type: 'step', buttonId: '" + stepPanel.getRunButton().getMarkupId() + "' }");
logPanel.pushJsonWebSocketMessage(json);
featurePage.pushJsonWebSocketMessage(json);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class HomePanel extends Panel {
@SpringBean(required = true)
private KarateService service;

private String text;
private final String text;

public HomePanel(String id) {
super(id);
Expand All @@ -57,6 +57,7 @@ protected void onSubmit() {
form.add(new TextArea("text"));
add(form);
add(new FeedbackPanel("feedback"));
text = "Feature:\n\nScenario:\n";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* The MIT License
*
* Copyright 2017 Intuit Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.intuit.karate.web.wicket;

import org.apache.wicket.request.resource.JavaScriptResourceReference;

/**
*
* @author pthomas3
*/
public class KarateJsResourceReference extends JavaScriptResourceReference {

public static final KarateJsResourceReference INSTANCE = new KarateJsResourceReference();

private KarateJsResourceReference() {
super(KarateJsResourceReference.class, "karate.js");
}

}

This file was deleted.

Loading

0 comments on commit 1ff1d8d

Please sign in to comment.