【问题标题】:Set referrer for Firefox on Test Cafe在 Testcafe 上设置 Firefox 的推荐人
【发布时间】:2020-04-09 07:54:25
【问题描述】:

希望通过 Test Cafe 为我的测试设置自定义引荐来源网址,但找不到合适的解决方案。在 Firefox 上,您可以使用一些插件轻松更改引荐来源网址,但如何在 Test Cafe 中进行呢?

【问题讨论】:

    标签: testing automated-tests e2e-testing testcafe referrer


    【解决方案1】:

    您可以为此目的使用Request Hooks 机制。我创建了一个示例来演示这种方法:

    import { RequestHook } from 'testcafe';
    
    fixture `fixture`
        .page `http://example.com`;
    
    
    export class MyRequestHook extends RequestHook {
        constructor (requestFilterRules, responseEventConfigureOpts) {
            super(requestFilterRules, responseEventConfigureOpts);
        }
        async onRequest (event) {
            event.requestOptions.headers['Referer'] = 'http://my-modified-referer.com';
        }
        async onResponse (event) {
        }
    }
    
    const hook = new MyRequestHook();
    
    test.requestHooks(hook)('referer', async t => {
        await t.navigateTo('https://www.whatismyreferer.com/');
    
        await t.debug();
    });
    

    【讨论】:

    • 谢谢伙计!解决了我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    • 2017-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多