needle
needle copied to clipboard
AttributeError: 'WebElement' object has no attribute 'get_screenshot'
Hi,
I started looking into needle (instead of ApliTools) and trying to create a test but facing an issue with this command:
element.get_screenshot().save(baseline_file)
In compareScreenshot() method cases.py file
File "C:\Python27\lib\site-packages\needle\cases.py", line 238, in compareScreenshot element.get_screenshot().save(output_file) AttributeError: 'WebElement' object has no attribute 'get_screenshot'
My guess that the driver that am referring to is the selenium web driver, but the one used in cases.py is the needle driver!
My code:
from needle.cases import NeedleTestCase
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC
from time import sleep
class NebulaTest(NeedleTestCase): def init(self): self.output_directory = "C:\screenshots" self.baseline_directory = "C:\screenshots\baseline" #self.engine_class = 'needle.engines.perceptualdiff_engine.Engine' #engine_class = 'needle.engines.imagemagick_engine.Engine'
self.driver = webdriver.Chrome()
self.test_feedback()
def test_feedback(self):
#self.set_viewport_size(width=1024, height=768)
self.driver.get('https://kampyle25.tumblr.com/')
sleep(5)
#try:
# WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "div.kampyle_button-text")))
#finally:
# self.driver.quit()
self.assertScreenshot('div.kampyle_button-text', 'feedback')
NebulaTest()
Thanks in advance.
I switched to Needle Driver:
self.driver = self.get_web_driver()
But now I'm getting:
File "C:\Python27\lib\site-packages\needle\cases.py", line 241, in compareScreenshot self.engine.assertSameFiles(output_file, baseline_file, threshold) AttributeError: 'NebulaTest' object has no attribute 'engine'
This command line:
self.engine.assertSameFiles(output_file, baseline_file, threshold)
From this link I can see that I need to download and install PerceptualDiff: http://the-creative-tester.github.io/Python-Visual-Regression-Testing/
that's require:
- CMake (https://cmake.org/download/)
- FreeImage (https://sourceforge.net/projects/freeimage/?source=typ_redirect)
But these aren't regular installations, the FreeImage for example is a dll... I have a feeling that am going in a wrong direction. Can you please give more insights on it
calling from my Test class:
self.setUpClass()
did the trick.
I still have one question regarding saving the base-line image.... by running: nosetests Needle.py --with-save-baseline I'm getting
c:\workspace_medalia\robotautomation\Galil-RF\RobotFramework\Libraries\VisualTesting>nosetests Needle.py --with-save-baseline E ====================================================================== ERROR: Failure: IOError (The baseline screenshot C:\VisualTesting\screenshots\baseline\feedback.png does not exist. You might want to re-run this test in baseline-saving mode.)
I order to come over it, I had overridden the save_base_line in my test class:
self.save_baseline = True
Isn't there an option to pass it as parameter? the --with-save-baseline was suppose to deal with it, no?!
I had a similar problem at first but I believe I figured out what I was doing wrong. You need to use the driver object that has the NeedleWebDriverMixin. You're using regular chrome when you do
self.driver = webdriver.Chrome()
To do use the one with the Needle mixin, I overrode get_web_driver.
from needle.cases import NeedleTestCase
from needle.driver import NeedleChrome
class ExampleTest(NeedleTestCase):
@classmethod
def get_web_driver(cls):
return NeedleChrome()
def test_example(self):
self.driver.get('http://example.com')
self.assertScreenshot('body', 'example-body')
That came mostly from https://needle.readthedocs.io/en/latest/#selecting-a-webdriver