-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<html> | ||
<head> | ||
<title>local file</title> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
<title>main window</title> | ||
</head> | ||
<body> | ||
<p id="result_local"></p> | ||
<p id="result_remote"></p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
function addButton(win) { | ||
let button = win.window.document.createElement("button"); | ||
button.id = "close"; | ||
button.innerHTML = "close NW.js"; | ||
|
||
button.onclick = function() { | ||
win.close(); | ||
}; | ||
|
||
win.window.document.getElementsByTagName("body")[0].appendChild(button); | ||
} | ||
|
||
var mainWindow; | ||
|
||
nw.Window.open("main.html", {}, function (win) { | ||
mainWindow = win; | ||
}); | ||
|
||
nw.Window.open("local.html", {}, function (win) { | ||
win.on("close", function () { | ||
mainWindow.window.document.getElementById("result_local").textContent = "local"; | ||
this.close(true); | ||
}); | ||
|
||
win.on("loaded", function () { | ||
addButton(win); | ||
}); | ||
}); | ||
|
||
nw.Window.open("http://example.org", {}, function (win) { | ||
win.on("close", function () { | ||
mainWindow.window.document.getElementById("result_remote").textContent = "remote"; | ||
this.close(true); | ||
}); | ||
|
||
win.on("loaded", function () { | ||
addButton(win); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "winonclose", | ||
"main": "main.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import time | ||
import os | ||
import sys | ||
|
||
from selenium import webdriver | ||
from selenium.webdriver.chrome.options import Options | ||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
from nw_util import * | ||
|
||
def close_window(title): | ||
for handle in driver.window_handles: | ||
driver.switch_to_window(handle) | ||
if title in driver.title: | ||
driver.find_element_by_id("close").click() | ||
break | ||
|
||
def switch_to_window(title): | ||
for handle in driver.window_handles: | ||
driver.switch_to_window(handle) | ||
if title == driver.title: | ||
break | ||
|
||
chrome_options = Options() | ||
chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__))) | ||
|
||
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options) | ||
driver.implicitly_wait(5) | ||
|
||
try: | ||
wait_window_handles(driver, 3) | ||
close_window("local file"); | ||
close_window("Example"); | ||
switch_to_window("main window") | ||
|
||
result_local = driver.find_element_by_id('result_local').get_attribute('innerHTML') | ||
result_remote = driver.find_element_by_id('result_remote').get_attribute('innerHTML') | ||
|
||
assert(result_local == "local") | ||
assert(result_remote == "remote") | ||
finally: | ||
driver.quit() |