<NME> test.py
<BEF> import time
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from nw_util import *

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common import utils

test_dir = os.path.dirname(os.path.abspath(__file__))
chrome_options = Options()
chrome_options.add_argument("nwapp=" + test_dir)

port = str(utils.free_port())

pkgjson = '''
{
  "name": "cookie-lost-devtools-close",
  "main": "index.html",
  "bg-script": "bg.js",
  "port": "%s"
}
''' % port

with open(os.path.join(test_dir, 'package.json'), 'w') as bg:
  bg.write(pkgjson)

idx = 1
def click_expect(expected):
    global idx
    driver.find_element_by_id('get-cookie').click()
    result = driver.find_element_by_id('result-%s' % idx).get_attribute('innerHTML')
    idx += 1
    print result
    assert(expected in result)

driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
driver.implicitly_wait(2)
try:
    switch_to_app(driver)
    print driver.current_url
    click_expect('undefined')
    click_expect('sid=1')
    driver.find_element_by_id('open-devtools').click()
    print 'wait for devtools open'
    wait_window_handles(driver, 2)
    click_expect('sid=1')
    print 'close devtools'
    switch_to_devtools(driver)
    driver.close()
    driver.switch_to_window(driver.window_handles[0])
    wait_window_handles(driver, 1)
    print 'devtools closed'
    click_expect('sid=1')
    click_expect('sid=1')
finally:
    #time.sleep(50)
    driver.quit()

<MSG> [test] fix race condition in cookie-lost-devtools-close

<DFF> @@ -30,7 +30,7 @@ idx = 1
 def click_expect(expected):
     global idx
     driver.find_element_by_id('get-cookie').click()
-    result = driver.find_element_by_id('result-%s' % idx).get_attribute('innerHTML')
+    result = wait_for_element_id(driver, 'result-%s' % idx)
     idx += 1
     print result
     assert(expected in result)

{'commit': "diff --git a/test/sanity/cookie-lost-devtools-close/test.py b/test/sanity/cookie-lost-devtools-close/test.py\nindex 62c7db93..6e0dbb12 100644\n--- a/test/sanity/cookie-lost-devtools-close/test.py\n+++ b/test/sanity/cookie-lost-devtools-close/test.py\n@@ -30,7 +30,7 @@ idx = 1\n def click_expect(expected):\n     global idx\n     driver.find_element_by_id('get-cookie').click()\n-    result = driver.find_element_by_id('result-%s' % idx).get_attribute('innerHTML')\n+    result = wait_for_element_id(driver, 'result-%s' % idx)\n     idx += 1\n     print result\n     assert(expected in result)\n", 'commit_subject': '[test] fix race condition in cookie-lost-devtools-close', 'repo_name': 'nwjs/nw.js', 'committer': {'name': 'Roger Wang', 'email': '19290c2e9c631c2c6e97803ebebf300809f89a21@intel.com', 'time_sec': '1483842148', 'tz_offset': '480', 'date': {'seconds': '1483842148'}}, 'commit_tree': '6cce48900592d6cf30d09d3667d4073e5824a70a', 'commit_message': '[test] fix race condition in cookie-lost-devtools-close\n', 'language_name': 'Python', 'license': 'mit', 'hunks': "@@ -30,7 +30,7 @@ idx = 1\n def click_expect(expected):\n     global idx\n     driver.find_element_by_id('get-cookie').click()\n-    result = driver.find_element_by_id('result-%s' % idx).get_attribute('innerHTML')\n+    result = wait_for_element_id(driver, 'result-%s' % idx)\n     idx += 1\n     print result\n     assert(expected in result)\n", 'addition_count': 1, 'deletion_count': 1, 'src_file': 'a/test/sanity/cookie-lost-devtools-close/test.py', 'tgt_file': 'b/test/sanity/cookie-lost-devtools-close/test.py', 'file_extension': '.py', 'before_file': 'import time\nimport os\nimport sys\nsys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))\nfrom nw_util import *\n\nfrom selenium import webdriver\nfrom selenium.webdriver.chrome.options import Options\nfrom selenium.webdriver.common import utils\n\ntest_dir = os.path.dirname(os.path.abspath(__file__))\nchrome_options = Options()\nchrome_options.add_argument("nwapp=" + test_dir)\n\nport = str(utils.free_port())\n\npkgjson = \'\'\'\n{\n  "name": "cookie-lost-devtools-close",\n  "main": "index.html",\n  "bg-script": "bg.js",\n  "port": "%s"\n}\n\'\'\' % port\n\nwith open(os.path.join(test_dir, \'package.json\'), \'w\') as bg:\n  bg.write(pkgjson)\n\nidx = 1\ndef click_expect(expected):\n    global idx\n    driver.find_element_by_id(\'get-cookie\').click()\n    result = driver.find_element_by_id(\'result-%s\' % idx).get_attribute(\'innerHTML\')\n    idx += 1\n    print result\n    assert(expected in result)\n\ndriver = webdriver.Chrome(executable_path=os.environ[\'CHROMEDRIVER\'], chrome_options=chrome_options)\ndriver.implicitly_wait(2)\ntry:\n    switch_to_app(driver)\n    print driver.current_url\n    click_expect(\'undefined\')\n    click_expect(\'sid=1\')\n    driver.find_element_by_id(\'open-devtools\').click()\n    print \'wait for devtools open\'\n    wait_window_handles(driver, 2)\n    click_expect(\'sid=1\')\n    print \'close devtools\'\n    switch_to_devtools(driver)\n    driver.close()\n    driver.switch_to_window(driver.window_handles[0])\n    wait_window_handles(driver, 1)\n    print \'devtools closed\'\n    click_expect(\'sid=1\')\n    click_expect(\'sid=1\')\nfinally:\n    #time.sleep(50)\n    driver.quit()\n', 'message': '[test] fix race condition in cookie-lost-devtools-close\n', 'author_name': 'Roger Wang', 'lang': 'py'}