def test_feature_types(self): "app: `App` given illegal object as feature list (ints) -> Fail with `TypeError` exception" with self.assertRaises(TypeError) as cm: app = mupf.App(features=(30, 50)) print('Exception text:', cm.exception) self.assertEqual(str(cm.exception), 'all features must be of `mupf.F.__Feature` type')
def test_feature_container_type(self): "app: `App` given illegal object as feature list (not iterable) -> Fail with `TypeError` exception" with self.assertRaises(TypeError) as cm: app = mupf.App(features=+mupf.F.core_features) print('Exception text:', cm.exception) self.assertEqual( str(cm.exception), '`feature` argumnet of `App` must be a **container** of features')
def test_hello_world(self): "selenium/basics: None -> Display 'Hello, World!' example" text = "Hello, World!" with mupf.App() as app: client = app.summon_client(frontend=mupf.client.Selenium, headless=True) client.window.document.body.innerHTML = text body = client.selenium.find_element_by_tag_name('body') print(f'Text found: {repr(body.text)}') self.assertEqual(body.text, text)
def test_append_element(self): "selenium/basics: None -> Create and append a <span>" with mupf.App() as app: client = app.summon_client(frontend=mupf.client.Selenium, headless=True) createElement = client.window.document.createElement bodyAppendChild = client.window.document.body.appendChild bodyAppendChild(createElement('span')) body = client.selenium.find_element_by_tag_name('body') span = body.find_element_by_tag_name('span') self.assertIsInstance(span, webdriver.remote.webelement.WebElement)
def test_port_unavailable(self): "selenium/basics: Port already used -> Fail with `OSError` exception" sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.bind(('127.0.0.1', mupf.App.default_port)) except OSError: self.skipTest('Required port was unavaliable in the first place') with self.assertRaises(OSError) as cm: with mupf.App(): pass print('Exception text:', cm.exception) sock.close()
import mupf mupf.log.enable('output.log') with mupf.App().open_with_client() as client: client.window.document.body.innerHTML = "Hello, World!"
import mupf import time mupf.log.enable('app.log', default_all_on=True) print(mupf.F.feature_list) with mupf.App( host='127.0.0.1', features= ( -mupf.F.test_feature, -mupf.F. friendly_obj_names, # This is not working - ReferenceError: id is not defined [static/core-esc.js:64:55] +mupf.F.verbose_macros, )) as app: app.register_route('main.css', file='main.css') app.register_route('app.js', file='app.js') # app.register_route('jquery.js', file='jquery-3.4.1.min.js') client = app.summon_client() # client.install_javascript(src='jquery.js').result client.install_commands(src='app.js') client.command.install_css().wait # time.sleep(20) #client.command('*setfrn*').run(PseudoGhost(docid[1]), 'documento') cprint = client.command.print.run
import mupf import time app = mupf.App() app.open() app.register_route('main.css', file='main.css') app.register_route('app.js', file='app.js') client = app.summon_client(frontend=mupf.client.Selenium) client.install_commands(src='app.js') client.command.install_css().wait cprint = client.command.print.run cinput = client.command.input cprint('Calculation of circle area v.1.0') r = cinput("Give me the radius: ") time.sleep(1.0) client.send_keys("120\n") r = float(r.result) cprint(f'Circle area for r = {r} is equal to A = {3.141592653589793*r*r}') cprint('Thank you for your cooperation', color='red') client.command.sleep(2) client.close() app.close()
import mupf app = mupf.App(features=(-mupf.F.garbage_collection, )) app.open() client = app.summon_client() client.install_javascript(""" mupf.hk.getmsg = (ev) => { console.log(ev.data) return JSON.parse(ev.data) } mupf.cmd.echo = function(args, kwargs){ return args } mupf.cmd.echo.noautoesc = true """, remove=True) document = client.window.document span = document.createElement('span') span.innerHTML = "SPAM!!! span" document.body.appendChild(span) print(client.command.echo("nice", "args").result) print(client.command.echo("~~~~", "nasty", "set", "of", "args").result) print(span.innerHTML) app.close()
# Event handler def button_click(event): """ Calculate SHA256 of the input and print it below """ global input_, bodyAppendChild, createElement value = input_.value hash_ = hashlib.sha256(value.encode('utf-8')).hexdigest() span = createElement('span') span.innerHTML = f"SHA256({repr(value)}) = {hash_}" bodyAppendChild(span) bodyAppendChild(createElement('br')) with mupf.App() as app: client = app.summon_client() # Useful functions createElement = client.window.document.createElement bodyAppendChild = client.window.document.body.appendChild # Creating the GUI button = createElement('button') input_ = createElement('input') bodyAppendChild(input_) bodyAppendChild(button) bodyAppendChild(createElement('br')) button.textContent = 'SHA256' # Attaching an event handler (Python-side function!) button.onclick = button_click