You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XPages/JSF局部刷新在Cypress中无法生效的问题问询

XPages局部刷新在Cypress测试中未正常更新DOM的问题

我在XPages/JSF应用中使用局部刷新功能,比如勾选复选框时,元素会向服务器提交数据,服务器更新DOM中指定元素。但在Cypress编写的测试里,Chrome浏览器中待更新的元素并未完成更新。我是否遗漏了Cypress的某些配置,或是对其能力的理解存在偏差?

我制作了一个极简表单,包含两种局部刷新方式:通过CSJS调用xsp.partialrefreshget,以及通过控件属性配置局部刷新,代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
    xmlns:xc="http://www.ibm.com/xsp/custom">
    <xp:this.beforePageLoad><![CDATA[#{javascript:viewScope.put("switch","on")}]]></xp:this.beforePageLoad>
    <xp:panel id="pnlAll">
        <xp:button value="On" id="btnOn">
            <xp:eventHandler event="onclick" submit="true"
                refreshMode="norefresh">
                <xp:this.action><![CDATA[#{javascript:viewScope.put("switch","on")}]]></xp:this.action>
                <xp:this.onComplete><![CDATA[XSP.partialRefreshGet("#{id:pnlAll}", {
    onComplete: function() {
        console.log("pnlAll refreshed?")
    }
});]]></xp:this.onComplete>
            </xp:eventHandler>
        </xp:button>
        <xp:checkBox text="on" id="cbOn">
            <xp:eventHandler event="onclick" submit="true"
                refreshMode="partial" refreshId="pnlAll">
                <xp:this.action><![CDATA[#{javascript:viewScope.put("switch","on")}]]></xp:this.action>
            </xp:eventHandler>
        </xp:checkBox>
        <xp:button value="Off" id="btnOff">
            <xp:eventHandler event="onclick" submit="true"
                refreshMode="norefresh">
                <xp:this.action><![CDATA[#{javascript:viewScope.put("switch","off")}]]></xp:this.action>
                <xp:this.onComplete><![CDATA[XSP.partialRefreshGet("#{id:pnlAll}", {
    onComplete: function() {
        console.log("pnlAll refreshed?")
    }
});]]></xp:this.onComplete>
            </xp:eventHandler>
        </xp:button>
        <xp:checkBox text="off" id="cbOff">
            <xp:eventHandler event="onclick" submit="true"
                refreshMode="partial" refreshId="pnlAll">
                <xp:this.action><![CDATA[#{javascript:viewScope.put("switch","off")}]]></xp:this.action>
            </xp:eventHandler>
        </xp:checkBox>
        <xp:panel id="pnlSwitch">
            <xp:panel tagName="h1" id="offmode">
                Emergency. We are in off mode
                <xp:this.rendered><![CDATA[#{javascript:viewScope.get("switch").equals("off")}]]></xp:this.rendered>
            </xp:panel>
            <xp:panel tagName="h3" id="onmode">
                Chill. We are on.
                <xp:this.rendered><![CDATA[#{javascript:viewScope.get("switch").equals("on")}]]></xp:this.rendered>
            </xp:panel>
        </xp:panel>
    </xp:panel>
</xp:view>

我的Cypress测试代码如下:

describe('Partial Refresh', () => {

  beforeEach(() => {
    cy.fixture('credentials.json').then(user => {
      expect(user.name).to.eq("dummy user")
      expect(user.password).to.eq("dummy password")

      cy.visit('https://server1.acme.org/names.nsf?logout&redirectto=projectX/patrick/app.nsf/cypress.xsp')
      cy.get('#user-id').type(user.name)
      cy.get('#pw-id').type(user.password)
      cy.get('[type="submit"]').click()
    })
  })

  it('passes', () => {
    cy.wait(1000)
    cy.get('#view\:_id1\:onmode')

    cy.get('#view\:_id1\:btnOff').click()
    cy.wait(1000)
    cy.get('#view\:_id1\:offmode')

    cy.get('#view\:_id1\:btnOn').click()
    cy.wait(1000)
    cy.get('#view\:_id1\:onmode')

     cy.get('#view\:_id1\:cbOff').check()
     cy.wait(1000)
     cy.get('#view\:_id1\:offmode')
     cy.get('#view\:_id1\:cbOff').uncheck()


     cy.get('#view\:_id1\:cbOn').check()
     cy.wait(1000)
     cy.get('#view\:_id1\:onmode')
     cy.get('#view\:_id1\:cbOn').uncheck()

     cy.get('#view\:_id1\:btnOff').click()
     cy.get('#view\:_id1\:offmode')
  })

})

这个简单表单的测试能顺利通过,但我在控制台发现了警告:

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 runner:next listeners added. Use emitter.setMaxListeners() to increase limit

我的生产环境表单规模很大,还使用了select2、bootstrap文件上传等多个Web插件,会不会是因为负载过高导致Cypress出现问题?

内容的提问来源于stack exchange,提问作者Patrick Kwinten

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 20:27:02