if platform.system() == 'Darwin': appdest = os.path.join(pkg1, 'nwjs.app', 'Contents', 'Resources', 'app.nw') else: appdest = pkg1 print "copying %s to %s" % (appdir, appdest) copytree(appdir, appdest) # change working directory to pkg1 # because in #5097, unexpected_file will be created in current working directory os.chdir(pkg1) # unexpected file should not exists before test unexpected_file = 'unexpected_file' assert not os.path.exists(unexpected_file), "'%s' should not be existed before testing" % unexpected_file chrome_options = Options() chrome_options.add_nw_argument(unexpected_file) driver_path=os.path.join(pkg1, 'chromedriver') driver = webdriver.Chrome(executable_path=driver_path, chrome_options=chrome_options) driver.implicitly_wait(5) try: print driver.current_url result = driver.find_element_by_id('result') print result.get_attribute('innerHTML') assert("success" in result.get_attribute('innerHTML')) finally: driver.quit() # unexpected file should not exists after test assert not os.path.exists(unexpected_file), "'%s' should not be existed after testing" % unexpected_file
import time import os import subprocess from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() testdir = os.path.dirname(os.path.abspath(__file__)) chrome_options.add_argument("nwapp=" + testdir) chrome_options.add_argument("user-data-dir=" + os.path.join(testdir, 'userdata')) chrome_options.add_nw_argument("success") try: driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options, service_log_path="log2", service_args=["--verbose", "--launch-timeout=5"]) except: pass
import time import os from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__))) chrome_options.add_nw_argument("--enable-node-worker") driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options) driver.implicitly_wait(5) time.sleep(1) try: print driver.current_url driver.find_element_by_id('start').click() result = driver.find_element_by_id('result').get_attribute('innerHTML') print result assert ('success' in result) finally: driver.quit()
import time import os from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() test_dir = os.path.dirname(os.path.abspath(__file__)) chrome_options.add_argument("nwapp=" + test_dir) chrome_options.add_nw_argument("--load-extension=" + os.path.join(test_dir, 'test_ext/')) driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options) driver.implicitly_wait(5) try: print driver.current_url result = driver.find_element_by_tag_name('h1').get_attribute('innerHTML') print result assert('Hello World' in result) res = driver.find_element_by_tag_name('iframe') assert(res is not None) finally: driver.quit()