电子应用程序在测试执行服务器上不完全可见

Electron app not completely visible on test execution server

我在成功执行我的黄瓜场景时遇到了一些问题,因为出于某种未知原因,我们正在测试的电子应用程序没有完全显示(table 右侧缺少 1 列)。 出于某种原因,这只发生在我们的 windows 测试执行服务器上,而不是在我的本地笔记本电脑上。 服务器分辨率为 1920x1080。 测试通过 Azure DevOps Server 管道启动。

我们使用 typescript 中的 cucumber-js 框架通过 spectron 测试电子应用程序。

import * as path from 'path';

import { Application } from 'spectron';

import * as settings from './globalvars';

export const SUT = new Application({
  path: `${settings.sutExecutablePath}`,
  args: [path.join(__dirname, '../'), '--headless', '--window-size=1920,1080'],
  env: {
    RUNNING_IN_SPECTRON: true,
    XXXXXX_DEV_TOOLS: false,
    SPECTRON_AUTOMATION_VARS: settings.testDataIndex
  },
  chromeDriverArgs: ['--headless', '--window-size=1920,1080', 'resolution=1920x1080', 'resolution: 1920x1080', '--width=1920', '--height=1080'],
  chromeDriverLogPath: path.join(settings.reportPath, 'chromedriver.log'),
  waitTimeout: settings.spectronDefaultImplicitWaitTimeout
});

我一直在胡闹:

none 的更改似乎对应用程序的启动方式有任何影响,事实上,更改 window 大小或最大化启动它甚至对我的笔记本电脑没有任何影响还有。

这是 chromedriver 日志的一个片段。不得不对其进行编辑,但仍然有用。

[1623923272.920][INFO]: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[1623923272.989][INFO]: [c56aabc7011e3a87307e2b8d55b9f003] COMMAND InitSession {
   "capabilities": {
      "alwaysMatch": {
         "goog:chromeOptions": {
            "args": [ "spectron-path=c:\xxxx\xxxx\win-unpacked\xxxxxx.exe", "spectron-arg0=C:\git\xxxxx\02-sxxxx\", "spectron-env-RUNNING_IN_SPECTRON=true", "spectron-env-xxxxx_DEV_TOOLS=false", "spectron-env-SPECTRON_AUTOMATION_VARS=C:\git\xxxx.xxxxxx\automation-vars.json", "--window-size=800,600" ],
            "binary": "C:\git\xxxx\02-xxxxxx\node_modules\spectron\lib\launcher.bat",
            "windowTypes": [ "app", "webview" ]
         }
      },
      "firstMatch": [ {

      } ]
   },
   "desiredCapabilities": {
      "goog:chromeOptions": {
         "args": [ "spectron-path=c:\xxxxx\xxxxxxx\win-unpacked\xxxxxx.exe", "spectron-arg0=C:\git\xxxxxx\02-xxxxxxx\", "spectron-env-RUNNING_IN_SPECTRON=true", "spectron-env-xxxxxxxx_DEV_TOOLS=false", "spectron-env-SPECTRON_AUTOMATION_VARS=C:\git\xxxxxx\automation-vars.json", "--window-size=800,600" ],
         "binary": "C:\git\xxxxx\02-xxxxxxxxxxxmodules\spectron\lib\launcher.bat",
         "windowTypes": [ "app", "webview" ]
      }
   }
}

[1623923272.994][INFO]: Launching chrome: "C:\git\xxxxxxxx-xxxxxxx\node_modules\spectron\lib\launcher.bat" --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-blink-features=ShadowDOMV0 --enable-logging --log-level=0 --no-first-run --no-service-autorun --password-store=basic --remote-debugging-port=0 --spectron-arg0="C:\git\xxxxxxxxx-xxxxxxx\" --spectron-env-running_in_spectron=true --spectron-env-xxxxx_dev_tools=false --spectron-env-spectron_automation_vars="C:\git\xxxxxxxx\automation-vars.json" --spectron-path="c:\bxxxxxxx\xxxxxxxxxx\win-unpacked\xxxxxxx.exe" --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\xxxxx\AppData\Local\Temp\scoped_dir33580_700219467" --window-size=800,600 data:,
[1623923273.323][DEBUG]: DevTools HTTP Request: http://localhost:54323/json/version
[1623923273.637][DEBUG]: DevTools HTTP Response: {

   "Browser": "Chrome/87.0.4280.141",

   "Protocol-Version": "1.3",

   "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) xxxxxxxx/1.0.0-alpha.2022 Chrome/87.0.4280.141 Electron/11.2.2 Safari/537.36",

   "V8-Version": "8.7.220.31",

   "WebKit-Version": "537.36 (@5236eb7c7e51a459c497e4ab474bf474ad7000ef)",

   "webSocketDebuggerUrl": "ws://localhost:54323/devtools/browser/62881ab4-ea89-4b48-b75e-4234f709931b"

}


[1623923273.637][DEBUG]: DevTools HTTP Request: http://localhost:54323/json/list
[1623923273.639][DEBUG]: DevTools HTTP Response: [ {

   "description": "",

   "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:54323/devtools/page/30283E47D490358108E12219527675CE",

   "id": "30283E47D490358108E12219527675CE",

   "title": "index.html",

   "type": "page",

   "url": "file:///C:/xxxxxxxxx/xxxxxxxxx/win-unpacked/resources/app.asar/build/index.html",

   "webSocketDebuggerUrl": "ws://localhost:54323/devtools/page/30283E47D490358108E12219527675CE"

} ]
"test:inProgress": "node ./node_modules/cucumber/bin/cucumber-js feature-files/*.feature --format summary --format progress-bar --format node_modules/cucumber-pretty --logLevel=error --require step-definitions/**/*.ts --require-module ts-node/register --require support/*.ts --format json:../reports/02-xxxx/cucumber-report.json --format node_modules/cucumber-junit-formatter:../reports/02-xxxx/testresults.junit --format-options '{\"scenarioAsStep\":true}' --tags \"@inProgress\"",
    "devDependencies": {
    "@cucumber/cucumber": "^7.0.0",
    "@types/chai": "^4.2.14",
    "@types/cucumber": "^6.0.1",
    "@types/jsonpath": "^0.2.0",
    "@types/xml2js": "^0.4.8",
    "@typescript-eslint/eslint-plugin": "^4.4.0",
    "@typescript-eslint/parser": "^4.4.0",
    "chai": "^4.2.0",
    "cucumber": "^6.0.5",
    "cucumber-html-reporter": "^5.3.0",
    "cucumber-junit-formatter": "^0.2.2",
    "cucumber-pretty": "^6.0.0",
    "date-fns": "^2.21.3",
    "electron": "^10.0.0",
    "eslint": "^7.11.0",
    "eslint-config-prettier": "^7.1.0",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-prettier": "^3.3.1",
    "filecompare": "^1.0.4",
    "jsonpath": "^1.1.0",
    "prettier": "2.2.0",
    "spectron": "^13.0.0",
    "ts-node": "^9.1.1",
    "typescript": "^4.1.3",
    "xml2js": "^0.4.23"
  },```

对于将来可能遇到此问题的任何人。 解决我的问题的方法非常基本。只需手动设置客户端应用程序的边界。

SUT.browserWindow.setSize(1920, 1080);
SUT.browserWindow.setPosition(0, 0);