#!/usr/bin/env python
# coding=UTF-8

import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options

import time
import unittest


class BasicWebUiTest(unittest.TestCase):
    test_uri = "https://www.mnot.net/"

    def setUp(self):
        options = Options()
        options.add_argument('-headless')
        self.browser = webdriver.Firefox(options=options)
        self.browser.get(redbot_uri)
        self.uri = self.browser.find_element_by_id("uri")
        self.uri.send_keys(self.test_uri)
        self.uri.submit()
        time.sleep(3.0)
        self.check_complete()

    def test_multi(self):
        check = self.browser.find_element_by_css_selector('a[accesskey="a"]')
        check.click()
        time.sleep(10.0)
        self.check_complete()

    def check_complete(self):
        try:
            self.browser.find_element_by_css_selector("div.footer")
        except:
            self.browser.save_screenshot('dump.png')
            raise

    def tearDown(self):
        self.check_complete()
        self.browser.close()

class CnnWebUiTest(BasicWebUiTest):
    test_uri = 'https://edition.cnn.com/'


if __name__ == "__main__":
    test_host = "localhost"
    test_port = 8000
    redbot_uri = "http://%s:%s/" % (test_host, test_port)
    import sys
    sys.path.insert(0, "bin")
    def redbot_run():
        import redbot_daemon
        from configparser import ConfigParser
        conf = ConfigParser()
        conf.read("config.txt")
        redconf = conf['redbot']
        redbot_daemon.RedBotServer(redconf)
    from multiprocessing import Process
    p = Process(target=redbot_run)
    p.start()
    unittest.main(exit=False, verbosity=2)
    print("done webui test...")
    p.terminate()


@@ -622,9 +622,9 @@
 eep(
-3
+4
 .0)%0A
@@ -743,22 +743,35 @@
 or('
-a%5Baccesskey=%22a
+input%5Bvalue=%22check embedded
 %22%5D')
@@ -813,17 +813,17 @@
 .sleep(1
-0
+2
 .0)%0A    
@@ -1215,192 +1215,8 @@
 /'%0A%0A
-%0Aif __name__ == %22__main__%22:%0A    test_host = %22localhost%22%0A    test_port = 8000%0A    redbot_uri = %22http://%25s:%25s/%22 %25 (test_host, test_port)%0A    import sys%0A    sys.path.insert(0, %22bin%22)%0A    
 def 
@@ -1229,20 +1229,16 @@
 _run():%0A
-    
     impo
@@ -1258,20 +1258,16 @@
 mon%0A    
- 
-   
 from con
@@ -1296,28 +1296,24 @@
 gParser%0A    
-   
- 
 conf = Confi
@@ -1326,20 +1326,16 @@
 r()%0A    
-   
- 
 conf.rea
@@ -1354,20 +1354,16 @@
 t%22)%0A    
-  
-  
 redconf 
@@ -1379,20 +1379,16 @@
 edbot'%5D%0A
-    
     redb
@@ -1419,16 +1419,197 @@
 edconf)%0A
+%0A%0Aif __name__ == %22__main__%22:%0A    test_host = %22localhost%22%0A    test_port = 8000%0A    redbot_uri = %22http://%25s:%25s/%22 %25 (test_host, test_port)%0A    import sys%0A    sys.path.insert(0, %22bin%22)%0A
     from

fix multi test; add a bit more time