Odoo 使用 phantomjs 进行测试 - page.evaluate 评估结果:false

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

使用 phantomjs 测试 odoo(通过定义游览)时出现错误 "page.evaluate eval result: false" 并且控制台不断抛出相同的错误:

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

完整代码如下:

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')",
            },
        ]
    });
 });

在手动执行odoo.DEBUG.services['web.Tour'].运行('test_type_invisible','test')时它抛出的浏览器控制台: "TypeError: state is undefined"

当执行 odoo.DEBUG.services['web.Tour'].tours.test_type_invisible 它抛出: 未定义

所以,这是怎么回事?它的起源实在是微不足道。请参阅下面我的回答

这里的情况基本是test_legajo.py找不到legajo.tour.js。 您必须定义一个 .xml 文件,告诉 odoo legajo.tour.js 位于何处:

按照惯例,它应该被称为 "resources.xml",必须放在 views 文件夹中,并且必须出现在 openerp.py 清单中:

当odoo找不到包含tours的js文件时,它会继续尝试phantomjs ready="odoo.DEBUG.services['web.Tour'].tours.test_type_invisible", line直到超时失败。