Get error array from selenium get_log function - robotframework

I want to extract the array error from Chrome console.
I have a RIDE application with an OpenBrowserAndLog function, that it should open the browser in logging mode, as follows:
${c_opts}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${c_opts} add_argument enable-logging
Call Method ${c_opts} add_argument v\=1
Call Method ${c_opts} add_argument loglevel\=ERROR
Create Webdriver Chrome crm_alias chrome_options=${c_opts}
Then, I have a python script that extracts those logs, using the selenium library and webdriver:
from robot.libraries.BuiltIn import BuiltIn
def get_log():
selib = BuiltIn().get_library_instance('SeleniumLibrary')
f = open('get_log_result.txt', 'a')
str1 = ', '.join(map(str,selib.driver.get_log('browser')))
f.write(str1)
f.close()
return True
my output is:
'source': 'network', 'timestamp': 1563272856199}, {'level': 'SEVERE', 'message': 'https://10.158.114.251:3080/hijat2-ui-static/main.4380998255cb0e09727f.js 0:908345 "ERROR" Array(10)', 'source': 'console-api', 'timestamp': 1563272876919}
What i want to get are the 10 ERRORs inside that "ERROR" Array

Related

mocked function is called but fails assert_called test

I have a test like:
import somemodule
import somemodule2
class SomeTestCase(unittest.TestCase):
def setUp(self):
super().setUp()
self.ft_mock = mock.MagicMock(spec=somemodule.SomeClass,
name='mock_it')
def tearDown(self) -> None:
self.ft_mock.reset_mock(return_value=True, side_effect=True)
#mock.patch('somemodule2.someFunk2',
name = 'mock_2',
spec=True,
side_effect='some val')
def testSomething(self, mock_rr):
m = self.ft_mock
m.addMemberSomething()
self.assertEqual(len(m.addMember.call_args_list), 1)
m.addSomethingElse.return_value = 'RETURN IT'
m.addSomethingElse()
m.addSomethingElse.assert_called_once()
res = somemodule.FooClass.foo()
mock_rr.assert_called()
Here somemodule.FooClass.foo() internally calls someFunk2 from somemodule2 which has been mocked as mock_rr
In the test debug it does call it as i print out a line from someFunk2 but testing it when mock_rr.assert_called() is called, it throws:
AssertionError: Expected 'mock_2' to have been called.
I've tried several ways using patch and patch.object
The issue was that somemodule also imported someFunk2 from somemodule2.
So when patching/mocking, the patched object was from somemodule2 while the object that Needed to be patched was somemodule.someFunk2

the testcase did not run when run as test suite with unittest framework

this is my testrun,there are cases in the imported testclass
from apa_login import Apa_login
from processmap import Show_processmap
import unittest,HTMLTestRunner,apa_login,processmap
def suite(self):
suite = unittest.TestSuite()
suite = unittest.TestLoader().loadTestsFromTestCase(Apa_login)
suite = unittest.TestLoader().loadTestsFromTestCase(Show_processmap)
return suite
if __name__ == '__main__':
runner = unittest.TextTestRunner()
runner.run(suite)
print suite
then it gives me this result??
$ python testrun.py
Ran 0 tests in 0.001s
OK
It should not be 0 tests,right?
You need to pass the TestSuite instance to runner.run() by invoking the suite() function. You're currently passing the suite function itself.
runner.run(suite()) # Pass the TestSuite by invoking suite()
Also note that you should probably remove the self argument from suite() if that function is not part of a class.

jsdom virtual console: TypeError: jsdom.createVirtualConsole is not a function

In:
const jsdom = require("jsdom");
const initialVirtualConsole = jsdom.createVirtualConsole();
I get:
TypeError: jsdom.createVirtualConsole is not a function
at Query.<anonymous> (/my_jsdom_script.js:112:55)
at emitNone (events.js:72:20)
at Query.emit (events.js:166:7)
at Query.Sequence.end (/Users/xxx/Sites/node_modules/mysql/lib/protocol/sequences/Sequence.js:99:12)
at Query._handleFinalResultPacket (/Users/xxx/Sites/node_modules/mysql/lib/protocol/sequences/Query.js:144:8)
at Query.EofPacket (/Users/xxx/Sites/node_modules/mysql/lib/protocol/sequences/Query.js:128:8)
at Protocol._parsePacket (/Users/xxx/Sites/node_modules/mysql/lib/protocol/Protocol.js:280:23)
at Parser.write (/Users/xxx/Sites/node_modules/mysql/lib/protocol/Parser.js:73:12)
at Protocol.write (/Users/xxx/Sites/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/Users/xxx/Sites/node_modules/mysql/lib/Connection.js:96:28)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at TCP.onread (net.js:523:20)
I would like to run the tests for jsdom on my local machine to see how jsdom performs in my local environment.
Could anyone be so good as to guide a noob in running the tests in https://github.com/tmpvar/jsdom/tree/master/test ?
Here's what's in my beforeEach() block (I'm using mocha over node.js to test)
import jsdom from 'jsdom'
const virtualConsole = jsdom.createVirtualConsole()
const document = jsdom.jsdom(undefined, {
virtualConsole: virtualConsole.sendTo(console)
})
virtualConsole.on('log', (...args) => {
// do something with `args` sent to logs
// e.g, assign result to a variable and run your assertions over it
})
window = document.defaultView
global.window = window
global.document = document
Check out the tests for further examples: https://github.com/tmpvar/jsdom/blob/master/test/jsdom/virtual-console.js

About tornado.gen.Task's usage - asynchronous request

below is my source:
class Get_Salt_Handler(tornado.web.RequestHandler):
#tornado.web.asynchronous
#tornado.gen.coroutine
def get(self):
#yield tornado.gen.Task(tornado.ioloop.IOLoop.instance().add_timeout, time.time() + 5)
yield tornado.gen.Task(self.get_salt_from_db, 123)
self.write("when i sleep 5s")
def get_salt_from_db(self, params):
print params
and I run it; the console reported that:
TypeError: get_salt_from_db() got an unexpected keyword argument 'callback'
and I don't know why?
gen.Task is used to adapt a callback-based function to the coroutine style; it cannot be used to call synchronous functions. What you probably want is a ThreadPoolExecutor (standard in Python 3.2+, available with pip install futures on Python 2):
# global
executor = concurrent.futures.ThreadPoolExecutor(NUM_THREADS)
#gen.coroutine
def get(self):
salt = yield executor.submit(self.get_salt_from_db)

Simplest tornado.gen example

I am trying to use Tornado's sync-style 'gen' tool to run a simple echo function, in a non-blocking style:
import tornado.web
import tornado.gen
import logging
def echo(message):
return message
#tornado.gen.engine
def runme():
response = yield tornado.gen.Task(echo, 'this is a message')
logging.warn(response)
runme()
As far as I can tell this code isn't significantly different to the demo code in the docs, minus the unnecessary request handler stuff - I'm not handling any HTTP requests, AFAICT that's orthagonal to running something asynchronously. Yet this always fails with:
Traceback (most recent call last):
File "./server.py", line 46, in <module>
runme()
TypeError: wrapper() takes at least 1 argument (0 given)
Exactly where am I missing the argument? How can I make Tornado run this function asynchronously?
Task doesn't actually make a callback for the function being run, and start the callback when the function returns, as I originally thought.
I need to create a callback in the task being run myself, and invoke it, i.e.:
import tornado.web
import tornado.gen
import logging
def echo(message, callback=None):
callback(message)
#tornado.gen.engine
def runme():
response = yield tornado.gen.Task(echo, 'this is a message')
logging.warn(response)
runme()

Resources