Skip to content

Commit b6c13ae

Browse files
author
Vasyl Vavrychuk
committed
enable or disable source and screenshot buttons
1 parent 2b28383 commit b6c13ae

File tree

2 files changed

+66
-16
lines changed

2 files changed

+66
-16
lines changed

web/WebDriverJsDemo.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@
2222
<script src="hammer.min.js"></script>
2323
<script src="webdriver-app.js"></script>
2424
</head>
25-
<body onload="init()">
25+
<body>
2626
<table border="0">
2727
<tr>
2828
<td>WebDriver url and port</td>
2929
<td>
30-
<input name="webDriverUrlPort" type="text"/>
30+
<input name="webDriverUrlPort" type="text" onchange="wd.onWebDriverUrlPortChange()" onkeyup="wd.onWebDriverUrlPortChange()"/>
3131
</td>
3232
</tr>
3333
<tr>
3434
<td>Web page</td>
3535
<td>
36-
<input name="webPage" type="text"/>
36+
<input name="webPage" type="text" onchange="wd.onWebPageChange()" onkeyup="wd.onWebPageChange()"/>
3737
<input type="button" value="GET" onclick="wd.onGet()"/>
38-
<input type="button" value="Source" onclick="wd.onSource()"/>
39-
<input type="button" value="Screenshot" onclick="wd.onScreenshot()"/>
38+
<input id="sourceButton" type="button" value="Source" onclick="wd.onSource()"/>
39+
<input id="screenshotButton" type="button" value="Screenshot" onclick="wd.onScreenshot()"/>
4040
<select onmouseup="wd.onLogs(this.options[this.selectedIndex].value)">
4141
<option>Logs</option>
4242
<option>browser</option>

web/webdriver-app.js

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,59 @@ VisualizerController.prototype.showVisualizationWindow = function(source, size)
484484
this.visualizerAssignEventHandlers();
485485
};
486486

487+
function WebDriverJsView() {
488+
if (localStorage && localStorage.webDriverUrlPort) {
489+
this.setDriverUrlPort(localStorage.webDriverUrlPort);
490+
} else {
491+
this.setDriverUrlPort('');
492+
}
493+
494+
if (localStorage && localStorage.webPage) {
495+
this.setWebPage(localStorage.webPage);
496+
} else {
497+
this.setWebPage('');
498+
}
499+
}
500+
501+
WebDriverJsView.prototype.getDriverUrlPort = function() {
502+
var input = document.getElementsByName('webDriverUrlPort')[0];
503+
return input.value;
504+
};
505+
506+
WebDriverJsView.prototype.setDriverUrlPort = function(value) {
507+
var input = document.getElementsByName('webDriverUrlPort')[0];
508+
input.value = value;
509+
this.updateSessionDepControls();
510+
};
511+
512+
WebDriverJsView.prototype.getWebPage = function() {
513+
var input = document.getElementsByName('webPage')[0];
514+
return input.value;
515+
};
516+
517+
WebDriverJsView.prototype.setWebPage = function(value) {
518+
var input = document.getElementsByName('webPage')[0];
519+
input.value = value;
520+
this.updateSessionDepControls();
521+
};
522+
523+
WebDriverJsView.prototype.updateSessionDepControls = function() {
524+
var disable = this.getDriverUrlPort().trim() === '' ||
525+
this.getWebPage().trim() === '';
526+
527+
var sessionDepControls = [];
528+
sessionDepControls.push(document.getElementById('sourceButton'));
529+
sessionDepControls.push(document.getElementById('screenshotButton'));
530+
for (var controlIndex in sessionDepControls) {
531+
var control = sessionDepControls[controlIndex];
532+
control.disabled = disable;
533+
}
534+
}
535+
487536
function WebDriverJsController() {
488537
this.driver = new WebDriverProxy();
489538
this.visualizer = new VisualizerController(this.driver);
539+
this.view = new WebDriverJsView();
490540
}
491541

492542
WebDriverJsController.prototype.setServerUrl = function(serverUrl) {
@@ -612,16 +662,16 @@ WebDriverJsController.prototype.onQuit = function() {
612662
this.webPage = null;
613663
};
614664

615-
function init() {
616-
if (localStorage && localStorage.webDriverUrlPort) {
617-
var input = document.getElementsByName('webDriverUrlPort')[0];
618-
input.value = localStorage.webDriverUrlPort;
619-
}
665+
WebDriverJsController.prototype.onWebDriverUrlPortChange = function() {
666+
var input = document.getElementsByName('webDriverUrlPort')[0];
667+
this.view.setDriverUrlPort(input.value);
668+
};
620669

621-
if (localStorage && localStorage.webPage) {
622-
var input = document.getElementsByName('webPage')[0];
623-
input.value = localStorage.webPage;
624-
}
625-
}
670+
WebDriverJsController.prototype.onWebPageChange = function() {
671+
var input = document.getElementsByName('webPage')[0];
672+
this.view.setWebPage(input.value);
673+
};
626674

627-
var wd = new WebDriverJsController();
675+
document.addEventListener("DOMContentLoaded", function(event) {
676+
window.wd = new WebDriverJsController();
677+
});

0 commit comments

Comments
 (0)