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

使用Cypress绕过SAML登录界面时遇Looker模块错误求助

Fixing the [$injector:modulerr] Looker Module Error in Cypress E2E Tests

Hey there! As someone who’s worked through plenty of Cypress + third-party app integration kinks, I can help you tackle this Looker module error you’re hitting after SAML login. Let’s break down what’s going on and how to fix it.

Why This Happens

That [$injector:nomod] error tells us Angular (which Looker relies on) can’t find the 'Looker' module when your test runs. The most likely culprits are:

  • Test case isolation: Cypress runs each it() block in a fresh browser context. Your second test logs in, but the third test starts a new session—so when you visit the dashboard URL, you’re actually trying to load Looker without being authenticated, which fails to load the module properly.
  • Missing wait for dynamic loading: Looker’s modules load dynamically after authentication. Your test might be trying to interact with the dashboard before the Looker module finishes loading.

Step-by-Step Fixes

1. Keep Login State Across Tests (Or Combine Steps)

First, fix the test structure to maintain authentication. Either wrap your login logic in a beforeEach() to run before every test, or combine all steps into a single it() block to keep the session alive.

Here’s a revised version with beforeEach():

describe('Main page', function() {
  beforeEach(function() {
    // Run this before every test to ensure we're logged in
    cy.visit('/login/email')
    
    // Wait for login form to load
    cy.get('#login-email').should('be.visible')
    
    // Submit credentials
    cy.get('#login-email').type('user@supercool.com')
    cy.get('#login-password').type('password')
    cy.get('#login-submit').click()
    
    // Wait for post-login redirect and page to fully load
    // Replace '.dashboard-header' with an element that appears after successful login
    cy.get('.dashboard-header').should('be.visible')
  })

  it('loads the Looker dashboard successfully', function() {
    cy.visit('/dashboards/analytics_external::live_event_summary?time_filter=6%20months&title_filter=&filter_config=%7B"time_filter":%5B%7B"type":"past","values":%5B%7B"constant":"6","unit":"mo"%7D,%7B%7D%5D,"id":4%7D%5D,"title_filter":%5B%7B"type":"%3D","values":%5B%7B"constant":""%7D,%7B%7D%5D,"id":5%7D%5D%7D')
    
    // Verify we're on the dashboard page
    cy.url().should('include', 'dashboards')
    
    // Wait for the Looker module to be available globally
    cy.window().should('have.property', 'Looker')
    
    // Wait for the actual dashboard content to render
    cy.get('.looker-dashboard-container').should('be.visible')
  })
})

2. Add Explicit Waits for Looker Loading

Looker’s modules load asynchronously after the page loads. Use cy.window() to wait for the global Looker object to exist—this ensures the module is ready before your test proceeds.

3. Check for Failed Network Requests

Open the Cypress Test Runner’s Network tab when running your test. If you see 401/403 errors for Looker-related assets, that confirms the test is trying to load Looker without valid authentication. The beforeEach() fix above should resolve this.

4. Adjust Timeouts If Needed

If Looker takes longer to load, increase the default timeout for specific commands. For example:

cy.window().should('have.property', 'Looker').timeout(15000) // Wait up to 15 seconds

Quick Notes

  • Make sure the element you’re waiting for after login (like .dashboard-header) is unique to the post-login state—this ensures Cypress doesn’t proceed until authentication is fully complete.
  • If your SAML login redirects through multiple pages, you can add a wait for the final redirect URL:
    cy.location('pathname').should('eq', '/your-post-login-path')
    

内容的提问来源于stack exchange,提问作者Adam Lahley

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:48:07