Advertisement
Guest User

Untitled

a guest
Aug 12th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.16 KB | None | 0 0
  1. class Bot:
  2.     drv: Remote
  3.     conf: dict
  4.  
  5.     def __init__(self, gui, drv=None):
  6.         options = Options()
  7.         if not gui:
  8.             options.headless = True
  9.         options.add_argument("window-size=1280,720")
  10.  
  11.         bs = self.conf['browserstack']
  12.         if drv is None:
  13.             self.drv = Remote(command_executor=bs['api_url'], desired_capabilities=bs['desired_cap'])
  14.         else:
  15.             self.drv = drv
  16.  
  17.         self.conf = getconfig()
  18.  
  19.     def save_config(self, config: dict):
  20.         data = dumps(config, indent=4, ensure_ascii=False)
  21.         with open(self.config_filename, "w") as f:
  22.             f.write(data)
  23.  
  24.     config_filename = "config.json"
  25.  
  26.  
  27. class TestSample(Bot, unittest.TestCase):
  28.     def test_sample(self):
  29.         form = self.conf['forms']['sample']
  30.         self.drv.get(form['url'])
  31.  
  32.         rows = self.drv.find_elements_by_xpath('//*[@id="ext-gen624"]/div')
  33.         for row in rows:
  34.             row.click()
  35.  
  36.             row_price = row.find_elements_by_xpath('.//tr/td')[1].find_element_by_xpath('./div').text
  37.             panel_price = self.drv.find_element_by_xpath('//*[@id="ext-gen572"]').get_attribute('value')
  38.             self.assertEqual(row_price, panel_price,
  39.                              f'Price from row not equals to price on panel: {row_price} != {panel_price}')
  40.  
  41.  
  42. ### Traceback
  43. Traceback (most recent call last):
  44.   File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
  45.     return _run_code(code, main_globals, None,
  46.   File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
  47.     exec(code, run_globals)
  48.   File "/usr/lib/python3.8/unittest/__main__.py", line 18, in <module>
  49.     main(module=None)
  50.   File "/usr/lib/python3.8/unittest/main.py", line 100, in __init__
  51.     self.parseArgs(argv)
  52.   File "/usr/lib/python3.8/unittest/main.py", line 124, in parseArgs
  53.     self._do_discovery(argv[2:])
  54.   File "/usr/lib/python3.8/unittest/main.py", line 244, in _do_discovery
  55.     self.createTests(from_discovery=True, Loader=Loader)
  56.   File "/usr/lib/python3.8/unittest/main.py", line 154, in createTests
  57.     self.test = loader.discover(self.start, self.pattern, self.top)
  58.   File "/usr/lib/python3.8/unittest/loader.py", line 349, in discover
  59.     tests = list(self._find_tests(start_dir, pattern))
  60.   File "/usr/lib/python3.8/unittest/loader.py", line 405, in _find_tests
  61.     tests, should_recurse = self._find_test_path(
  62.   File "/usr/lib/python3.8/unittest/loader.py", line 460, in _find_test_path
  63.     return self.loadTestsFromModule(module, pattern=pattern), False
  64.   File "/usr/lib/python3.8/unittest/loader.py", line 124, in loadTestsFromModule
  65.     tests.append(self.loadTestsFromTestCase(obj))
  66.   File "/usr/lib/python3.8/unittest/loader.py", line 93, in loadTestsFromTestCase
  67.     loaded_suite = self.suiteClass(map(testCaseClass, testCaseNames))
  68.   File "/usr/lib/python3.8/unittest/suite.py", line 24, in __init__
  69.     self.addTests(tests)
  70.   File "/usr/lib/python3.8/unittest/suite.py", line 57, in addTests
  71.     for test in tests:
  72.   File "/home/claes/PycharmProjects/spanish_testing/bot.py", line 36, in __init__
  73.     bs = self.conf['browserstack']
  74. AttributeError: 'TestSample' object has no attribute 'conf'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement