为何用Protractor启动Chrome隐身模式时SSO仍启用?
Hey there! I totally get why this would be frustrating—manual incognito works exactly as you expect, but your automated tests keep skipping the login prompt. Let's break down what might be going on and how to fix it.
Why This Might Be Happening
Chrome's incognito mode is supposed to isolate sessions, but when Protractor launches Chrome, it might still be loading residual configuration, shared profile state, or even password manager data that triggers the auto-login. Your current config enables incognito, but it's missing a few key flags to fully lock down the session and prevent SSO from kicking in.
Fixes to Try
Let's update your capabilities with these additional Chrome flags to ensure a completely clean, isolated incognito session:
- Disable password and autofill features: Turn off Chrome's built-in password manager and autofill, which could be silently reusing SSO credentials.
- Use a temporary disposable profile: Force Chrome to use a fresh temporary directory for each run, so no old session data lingers between tests.
- Disable extensions and shared state: Some SSO-related extensions might still run in incognito, and shared profile state can carry over unexpected data.
Here's what your updated capabilities would look like:
config.capabilities = { browserName: 'chrome', chromeOptions: { args: [ 'disable-infobars', '--incognito', '--log-level=3', '--disable-gpu', '--window-size=1600,1200', // New flags to block auto-login '--disable-autofill', '--disable-password-manager-reauthentication', '--disable-profile-shared-state', '--disable-extensions', '--no-default-browser-check', '--no-first-run', '--user-data-dir=/tmp/protractor-chrome-temp' // Fresh temp profile every run ] }, //shardTestFiles: true, //maxInstances: 3, deviceProperties:{ browser: { name: 'chrome', version: 'latest' }, platform: { name: 'Windows', version: '10' } } }
Additional Checks
- If auto-login still happens, try cranking up the log level to
0(replace--log-level=3with--log-level=0) to see detailed Chrome startup logs. Look for lines about loading profiles, extensions, or credential stores—this might point to where the persisted SSO data is coming from. - You can also add a test step to clear all cookies and local storage before navigating to the login URL, just to eliminate any leftover session data from previous runs.
The core difference between manual and automated incognito is that Protractor launches Chrome with a set of default arguments that aren't as strict as a manually opened incognito window. Adding these flags should force a truly isolated session, matching the behavior you see when you open incognito by hand.
内容的提问来源于stack exchange,提问作者cris

