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

Bug que no muestra nombre de productos en la tabla #71

Open
RamiGordon opened this issue May 31, 2018 · 1 comment
Open

Bug que no muestra nombre de productos en la tabla #71

RamiGordon opened this issue May 31, 2018 · 1 comment
Labels
question Further information is requested

Comments

@RamiGordon
Copy link

RamiGordon commented May 31, 2018

Hola, tengo problema con este ejercicio (paso el codigo tambien):

def test_nomb_produc(self):
        '''
        Punto 2_b:
        Hacer un test de integración con Selenium para verificar
        que se haya solucionado el bug no mostraba el nombre del producto
        en la tabla, arreglado en la Actividad 2
        '''
        driver = self.driver
        driver.get(self.baseURL)
        time.sleep(10)

        #Creo orden
        orden = Order(id=1)
        db.session.add(orden)

        #Creo producto
        producto = Product(id=1, name='Cuchillo', price=50)
        db.session.add(producto)

        #Creo orden_producto
        ordenProducto = OrderProduct(order_id=1, product_id=1, quantity=5, product=producto)
        db.session.add(ordenProducto)

        #commiteo
        db.session.commit()

        #Guardo el path de donde tendria que aparecel el nombre del producto
        nombre_producto = driver.find_element_by_xpath('//*[@id="orders"]/table/tbody/tr[1]/td[2]')
        
        #Comparo si ese nombre aparece y es igual al producto que cree
        self.assertEqual(nombre_producto.text, "Cuchillo"), 'No aparece el nombre del producto'

y este es el error:

________________________ Ordering.test_nomb_produc ________________________

self = <test.test_e2e.Ordering testMethod=test_nomb_produc>

def test_nomb_produc(self):
    '''
        Punto 2_b:
        Hacer un test de integración con Selenium para verificar
        que se haya solucionado el bug no mostraba el nombre del producto
        en la tabla, arreglado en la Actividad 2
        '''
    driver = self.driver
    driver.get(self.baseURL)
    time.sleep(10)

    #Creo orden
    orden = Order(id=1)
    db.session.add(orden)

    #Creo producto
    producto = Product(id=1, name='Cuchillo', price=50)
    db.session.add(producto)

    #Creo orden_producto
    ordenProducto = OrderProduct(order_id=1, product_id=1, quantity=5, product=producto)
    db.session.add(ordenProducto)

    #commiteo
    db.session.commit()

    #Guardo el path de donde tendria que aparecel el nombre del producto
  nombre_producto = driver.find_element_by_xpath('//*[@id="orders"]/table/tbody/tr[1]/td[2]')

test_e2e.py:111:


c:\program files (x86)\python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py:387: in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
c:\program files (x86)\python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py:957: in find_element
'value': value})['value']
c:\program files (x86)\python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py:314: in execute
self.error_handler.check_response(response)


self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x0454AFB0>
response = {'sessionId': '18090aa2e7c945f126caf6a740de7876', 'status': 7, 'value': {'message': 'no such element: Unable to locate...ver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 10.0.17134 x86_64)'}}

def check_response(self, response):
    """
        Checks that a JSON response from the WebDriver does not have an error.

        :Args:
         - response - The JSON response from the WebDriver server as a dictionary
           object.

        :Raises: If the response contains an error message.
        """
    status = response.get('status', None)
    if status is None or status == ErrorCode.SUCCESS:
        return
    value = None
    message = response.get("message", "")
    screen = response.get("screen", "")
    stacktrace = None
    if isinstance(status, int):
        value_json = response.get('value', None)
        if value_json and isinstance(value_json, basestring):
            import json
            try:
                value = json.loads(value_json)
                if len(value.keys()) == 1:
                    value = value['value']
                status = value.get('error', None)
                if status is None:
                    status = value["status"]
                    message = value["value"]
                    if not isinstance(message, basestring):
                        value = message
                        message = message.get('message')
                else:
                    message = value.get('message', None)
            except ValueError:
                pass

    exception_class = ErrorInResponseException
    if status in ErrorCode.NO_SUCH_ELEMENT:
        exception_class = NoSuchElementException
    elif status in ErrorCode.NO_SUCH_FRAME:
        exception_class = NoSuchFrameException
    elif status in ErrorCode.NO_SUCH_WINDOW:
        exception_class = NoSuchWindowException
    elif status in ErrorCode.STALE_ELEMENT_REFERENCE:
        exception_class = StaleElementReferenceException
    elif status in ErrorCode.ELEMENT_NOT_VISIBLE:
        exception_class = ElementNotVisibleException
    elif status in ErrorCode.INVALID_ELEMENT_STATE:
        exception_class = InvalidElementStateException
    elif status in ErrorCode.INVALID_SELECTOR \
            or status in ErrorCode.INVALID_XPATH_SELECTOR \
            or status in ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER:
        exception_class = InvalidSelectorException
    elif status in ErrorCode.ELEMENT_IS_NOT_SELECTABLE:
        exception_class = ElementNotSelectableException
    elif status in ErrorCode.ELEMENT_NOT_INTERACTABLE:
        exception_class = ElementNotInteractableException
    elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
        exception_class = InvalidCookieDomainException
    elif status in ErrorCode.UNABLE_TO_SET_COOKIE:
        exception_class = UnableToSetCookieException
    elif status in ErrorCode.TIMEOUT:
        exception_class = TimeoutException
    elif status in ErrorCode.SCRIPT_TIMEOUT:
        exception_class = TimeoutException
    elif status in ErrorCode.UNKNOWN_ERROR:
        exception_class = WebDriverException
    elif status in ErrorCode.UNEXPECTED_ALERT_OPEN:
        exception_class = UnexpectedAlertPresentException
    elif status in ErrorCode.NO_ALERT_OPEN:
        exception_class = NoAlertPresentException
    elif status in ErrorCode.IME_NOT_AVAILABLE:
        exception_class = ImeNotAvailableException
    elif status in ErrorCode.IME_ENGINE_ACTIVATION_FAILED:
        exception_class = ImeActivationFailedException
    elif status in ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
        exception_class = MoveTargetOutOfBoundsException
    elif status in ErrorCode.JAVASCRIPT_ERROR:
        exception_class = JavascriptException
    elif status in ErrorCode.SESSION_NOT_CREATED:
        exception_class = SessionNotCreatedException
    elif status in ErrorCode.INVALID_ARGUMENT:
        exception_class = InvalidArgumentException
    elif status in ErrorCode.NO_SUCH_COOKIE:
        exception_class = NoSuchCookieException
    elif status in ErrorCode.UNABLE_TO_CAPTURE_SCREEN:
        exception_class = ScreenshotException
    elif status in ErrorCode.ELEMENT_CLICK_INTERCEPTED:
        exception_class = ElementClickInterceptedException
    elif status in ErrorCode.INSECURE_CERTIFICATE:
        exception_class = InsecureCertificateException
    elif status in ErrorCode.INVALID_COORDINATES:
        exception_class = InvalidCoordinatesException
    elif status in ErrorCode.INVALID_SESSION_ID:
        exception_class = InvalidSessionIdException
    elif status in ErrorCode.UNKNOWN_METHOD:
        exception_class = UnknownMethodException
    else:
        exception_class = WebDriverException
    if value == '' or value is None:
        value = response['value']
    if isinstance(value, basestring):
        if exception_class == ErrorInResponseException:
            raise exception_class(response, value)
        raise exception_class(value)
    if message == "" and 'message' in value:
        message = value['message']

    screen = None
    if 'screen' in value:
        screen = value['screen']

    stacktrace = None
    if 'stackTrace' in value and value['stackTrace']:
        stacktrace = []
        try:
            for frame in value['stackTrace']:
                line = self._value_or_default(frame, 'lineNumber', '')
                file = self._value_or_default(frame, 'fileName', '<anonymous>')
                if line:
                    file = "%s:%s" % (file, line)
                meth = self._value_or_default(frame, 'methodName', '<anonymous>')
                if 'className' in frame:
                    meth = "%s.%s" % (frame['className'], meth)
                msg = "    at %s (%s)"
                msg = msg % (meth, file)
                stacktrace.append(msg)
        except TypeError:
            pass
    if exception_class == ErrorInResponseException:
        raise exception_class(response, message)
    elif exception_class == UnexpectedAlertPresentException:
        alert_text = None
        if 'data' in value:
            alert_text = value['data'].get('text')
        elif 'alert' in value:
            alert_text = value['alert'].get('text')
        raise exception_class(message, screen, stacktrace, alert_text)
  raise exception_class(message, screen, stacktrace)

E selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="orders"]/table/tbody/tr[1]/td[2]"}
E (Session info: chrome=66.0.3359.181)
E (Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 10.0.17134 x86_64)

c:\program files (x86)\python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py:242: NoSuchElementException
------------------------------ Captured log call ------------------------------
_internal.py 88 ERROR Error on request:
Traceback (most recent call last):
File "c:\program files (x86)\python36-32\lib\site-packages\werkzeug\serving.py", line 270, in run_wsgi
execute(self.server.app)
File "c:\program files (x86)\python36-32\lib\site-packages\werkzeug\serving.py", line 258, in execute
application_iter = app(environ, start_response)
File "c:\program files (x86)\python36-32\lib\site-packages\flask\app.py", line 1997, in call
return self.wsgi_app(environ, start_response)
File "c:\program files (x86)\python36-32\lib\site-packages\flask\app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "c:\program files (x86)\python36-32\lib\site-packages\flask\app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "c:\program files (x86)\python36-32\lib\site-packages\flask_compat.py", line 33, in reraise
raise value
File "c:\program files (x86)\python36-32\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "c:\program files (x86)\python36-32\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "c:\program files (x86)\python36-32\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "c:\program files (x86)\python36-32\lib\site-packages\flask_compat.py", line 33, in reraise
raise value
File "c:\program files (x86)\python36-32\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "c:\program files (x86)\python36-32\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functionsrule.endpoint
File "C:\Users\joaquin\Documents\GitHub\orderingg\app\routes.py", line 50, in order
order = Order.query.get(pk)
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\orm\query.py", line 882, in get
ident, loading.load_on_pk_identity)
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\orm\query.py", line 952, in _get_impl
return db_load_fn(self, primary_key_identity)
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\orm\loading.py", line 247, in load_on_pk_identity
return q.one()
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\orm\query.py", line 2884, in one
ret = self.one_or_none()
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\orm\query.py", line 2854, in one_or_none
ret = list(self)
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\orm\query.py", line 2925, in iter
return self._execute_and_instances(context)
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\orm\query.py", line 2948, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\engine\base.py", line 948, in execute
return meth(self, multiparams, params)
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\sql\elements.py", line 269, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\engine\base.py", line 1060, in _execute_clauseelement
compiled_sql, distilled_params
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\engine\base.py", line 1200, in _execute_context
context)
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\engine\base.py", line 1413, in _handle_dbapi_exception
exc_info
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\util\compat.py", line 203, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\util\compat.py", line 186, in reraise
raise value.with_traceback(tb)
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\engine\base.py", line 1193, in _execute_context
context)
File "c:\program files (x86)\python36-32\lib\site-packages\sqlalchemy\engine\default.py", line 507, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: order [SQL: 'SELECT "order".id AS order_id \nFROM "order" \nWHERE "order".id = ?'] [parameters: ('1',)] (Background on this error at: http://sqlalche.me/e/e3q8)
===================== 2 failed, 1 passed in 96.68 seconds =====================

Hasta donde entiendo, la logica del codigo no esta mal, porque guardo el path en "nombre_producto" y despues comparo en el assert con "nombre_producto.text". Tampoco entiendo el error igual

@RodrigoJacznik
Copy link
Contributor

Hola, el problema esta en que vos haces el get antes de crear el producto.

@RodrigoJacznik RodrigoJacznik added the question Further information is requested label May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants