撞上路障,终生无法在Google上找到任何东西
我正在使用serenity-js,目前没有刷新交互,因此在本地创建了一个。
这是我的课:
import {browser, protractor} from 'protractor';
import {Interaction} from '@serenity-js/core/lib/screenplay';
import {BrowseTheWeb, UsesAbilities} from 'serenity-js/lib/screenplay-protractor';
export class Refresh implements Interaction {
static browser(): Refresh {
return new Refresh();
}
performAs(actor: UsesAbilities): PromiseLike<void> {
return protractor.browser.refresh().then(console.log(protractor.browser));
}
}
这是我在其中调用的任务,当我的量角器.conf.js中的--headless模式关闭时,它可以完美地工作,但是刷新后进入--headless模式并进入console.log时,它会炸毁。清洗它。发生的错误只是步骤文件中的超时错误。
export class OpenPdf implements Task {
constructor(private columnHeader: string, private invNumLinkToPDF: string) {
}
static insideDocuments(columnHeader: string, invNumLinkToPDF: string): OpenPdf {
return new OpenPdf(columnHeader, invNumLinkToPDF);
}
performAs(actor: PerformsTasks): PromiseLike<void> {
return actor.attemptsTo(
Click.on(AccountInfoUI.pdf.link(this.columnHeader, this.invNumLinkToPDF)),
Wait.for(Duration.ofMillis(3000)),
Switch.toPopupWindow(),
UseAngular.disableSynchronisation(),
Refresh.browser(),
);
}
}
这里是测试后的输出:
Cucumber test run has failed.
[09:34:58] E/launcher - Error: TimeoutError: timeout
(Session info: headless chrome=67.0.3396.87)
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 6.1.7601 SP1 x86_64)
at Object.checkLegacyResponse (C:\dev\account-frontend\node_modules\selenium-webdriver\lib\error.js:546:15)
at parseHttpResponse (C:\dev\account-frontend\node_modules\selenium-webdriver\lib\http.js:509:13)
at doSend.then.response (C:\dev\account-frontend\node_modules\selenium-webdriver\lib\http.js:441:30)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
From: Task: WebDriver.takeScreenshot()
at Driver.schedule (C:\dev\account-frontend\node_modules\selenium-webdriver\lib\webdriver.js:807:17)
at Driver.takeScreenshot (C:\dev\account-frontend\node_modules\selenium-webdriver\lib\webdriver.js:1085:17)
at run (C:\dev\account-frontend\node_modules\protractor\built\browser.js:59:33)
at ProtractorBrowser.to.(anonymous function) [as takeScreenshot] (C:\dev\account-frontend\node_modules\protractor\built\browser.js:67:16)
at C:\dev\account-frontend\node_modules\serenity-js\src\serenity-protractor\screenplay\abilities\browse_the_web.ts:42:41
at C:\dev\account-frontend\node_modules\@serenity-js\core\src\recording\async.ts:4:8
at new Promise (<anonymous>)
at Object.defer (C:\dev\account-frontend\node_modules\@serenity-js\core\src\recording\async.ts:3:12)
at BrowseTheWeb.takeScreenshot (C:\dev\account-frontend\node_modules\serenity-js\src\serenity-protractor\screenplay\abilities\browse_the_web.ts:42:16)
at Photographer.photographWorkOf (C:\dev\account-frontend\node_modules\serenity-js\src\serenity-protractor\stage\photographer.ts:136:36)
at Photographer.photograph (C:\dev\account-frontend\node_modules\serenity-js\src\serenity-protractor\stage\photographer.ts:114:38)
at TakeAPhoto.takeAPhoto (C:\dev\account-frontend\node_modules\serenity-js\src\serenity-protractor\stage\photographer-timing.ts:25:22)
at TimingBehaviour.takeAnAfterPhoto (C:\dev\account-frontend\node_modules\serenity-js\src\serenity-protractor\stage\photographer-timing.ts:15:20)
at PhotoTakingStrategy.activityFinished (C:\dev\account-frontend\node_modules\serenity-js\src\serenity-protractor\stage\photographer.ts:176:25)
at Photographer.notifyOf (C:\dev\account-frontend\node_modules\serenity-js\src\serenity-protractor\stage\photographer.ts:104:55)
at C:\dev\account-frontend\node_modules\@serenity-js\core\src\stage\stage_manager.ts:112:53
at Array.forEach (<anonymous>)
at CrewMembersCommunicationChannel.notify (C:\dev\account-frontend\node_modules\@serenity-js\core\src\stage\stage_manager.ts:112:24)
at StageManager.notifyOf (C:\dev\account-frontend\node_modules\@serenity-js\core\src\stage\stage_manager.ts:24:52)
at Serenity.notify (C:\dev\account-frontend\node_modules\@serenity-js\core\src\serenity.ts:19:28)
at handleStepResultEvent (C:\dev\account-frontend\node_modules\serenity-js\src\serenity-cucumber\cucumber_serenity_notifier.ts:56:18)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
答案 0 :(得分:0)
乍一看,您的实现似乎是正确的。我不知道这是WebDriver ControlFlow和本机Node Promise不兼容的问题吗?您能尝试将对protractor.browser.refresh()
的调用包装到Node Promise对象中吗?
看看BrowseTheWeb
ability的实现以供参考。您将看到我如何使用defer
函数包装其他特定于WebDriver的Promise:
import { defer } from '@serenity-js/core/lib/recording/async'; // <- import `defer`
import {browser, protractor} from 'protractor';
import {Interaction} from '@serenity-js/core/lib/screenplay';
import {BrowseTheWeb, UsesAbilities} from 'serenity-js/lib/screenplay-protractor';
export class Refresh implements Interaction {
static browser(): Refresh {
return new Refresh();
}
performAs(actor: UsesAbilities): PromiseLike<void> {
return defer(() => protractor.browser.refresh()).then(console.log(protractor.browser));
}
}
希望这会有所帮助!