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

时间:2018-09-10 13:57:32

标签: phantomjs odoo-9

在使用phantomjs测试odoo时(通过定义游览),它会显示错误“ page.evaluate eval结果: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时。调试。services['web.Tour']。run('test_type_invisible','test')在浏览器控制台中手动进行时,它会抛出: “ TypeError:状态未定义”

执行odoo时。调试 .services ['web.Tour']。tours.test_type_invisible会引发: 未定义

那么,发生了什么事?它的起源确实是微不足道的。请在下面查看我的答案

1 个答案:

答案 0 :(得分:0)

这里发生的基本上是test_legajo.py找不到legajo.tour.js。 您必须定义一个.xml文件,该文件告诉odoo legajo.tour.js的位置:

按照惯例,它应该称为“ resources.xml”,必须放置在views文件夹中,并且必须存在于 openerp .py清单中:

folder structure

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