Search code examples
phantomjsodoo-9

Odoo testing with phantomjs - page.evaluate eval result: false


When testing odoo with phantomjs (by defining tours) it helds an error "page.evaluate eval result: false" and console keeps throwing same error:

2018-09-10 13:46:12,250 8311 INFO grp openerp.tests.common: phantomjs: PhantomTest.run: wait for condition: odoo.__DEBUG__.services['web.Tour'].tours.test_type_invisible
2018-09-10 13:46:12,251 8311 INFO grp openerp.tests.common: phantomjs: page.evaluate eval expr: odoo.__DEBUG__.services['web.Tour'].tours.test_type_invisible
2018-09-10 13:46:12,252 8311 INFO grp openerp.tests.common: phantomjs: page.evaluate eval result: false

Complete code as follows:

test_legajo.py

# -*- coding: utf-8 -*-

from openerp.tests import common


class TestsLegajo(common.HttpCase):
    """
        tests models uy_hr.legajo

        Requires:
            -PhantomJS
    """

    MENU_ID = 'uy_hr.uy_hr_legajos_menu'

    post_install = True
    at_install = False

    def setUp(self):
        super(TestsLegajo, self).setUp()
        self.authenticate('admin', 'admin1234')
        self._build_URL()

    def _build_URL(self):
        ir_ui_menu = self.env.ref(self.MENU_ID)
        act_window = ir_ui_menu.action
        modelo = act_window.res_model
        menuId = ir_ui_menu.id
        actId = act_window.id
        self.url = '/web#model=%s&menu_id=%s&action=%s&' % (modelo, menuId, actId)

    def test_type_invisible(self):
        """
            Verifica campo type no aparezca en la vista form
        """
        self.phantom_js(
            url_path=self.url,
            code="odoo.__DEBUG__.services['web.Tour'].run('test_type_invisible', 'test')",
            ready="odoo.__DEBUG__.services['web.Tour'].tours.test_type_invisible",
            login=None
        )

legajo.tour.js

odoo.define('legajo.tour', function(require) {
    'use strict';
    var core = require('web.core');
    var Tour = require('web.Tour');
    var _t = core._t;

    Tour.register({
        id: 'test_type_invisible',
        name: _t("Verifica campo type no aparezca en la vista form"),
        mode: 'test',
        steps: [
            {
                title: _t("1 - Paso Dummy (Carga de Página)."),
                waitFor: 'button.o_list_button_add',
            },
            {
                title: _t("2 - Se accede al formulario de creación de Solicitud de Recursos."),
                waitFor: "button.o_list_button_add",
                element: "button.o_list_button_add",
            },
            {
                title: _t("3 - Verifica campo type no aparezca en la vista form"),
                waitFor: "label.oe_form_label.o_form_invisible:contains('Tipo')",
            },
        ]
    });
 });

When excecuting odoo.DEBUG.services['web.Tour'].run('test_type_invisible', 'test') manually in browser's console it throws: "TypeError: state is undefined"

When executing odoo.DEBUG.services['web.Tour'].tours.test_type_invisible it throws: undefined

So, what is happening? It's origin is really trivial. See my answer below


Solution

  • What's happening here is basically test_legajo.py can't find legajo.tour.js. You have to define an .xml file that tells odoo where legajo.tour.js is located:

    By convention it should be called "resources.xml", must be placed inside views folder and has to be present in openerp.py manifest:

    folder structure

    When odoo can't find js file containing the tours, it will keep trying phantomjs ready="odoo.DEBUG.services['web.Tour'].tours.test_type_invisible", line until failing out of timeout.