Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'WebElement' object has no attribute 'get_screenshot' #73

Open
mzbedat opened this issue Jul 2, 2017 · 3 comments
Open

Comments

@mzbedat
Copy link

mzbedat commented Jul 2, 2017

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.

@mzbedat
Copy link
Author

mzbedat commented Jul 3, 2017

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:

  1. CMake (https://cmake.org/download/)
  2. 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

@mzbedat
Copy link
Author

mzbedat commented Jul 3, 2017

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?!

@jeremyqa
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants