【问题标题】:how to fix 'AssertionError: expected false to be truthy' error?如何修复“AssertionError:预期的错误是真实的”错误?
【发布时间】:2019-03-25 18:28:12
【问题描述】:

我是 E2E 测试的初学者,我想通过 TestCafe 注册一个 github 帐户测试,但在运行测试时出现此错误:

ExternalAssertionLibraryError {
  code: 'E53',
  isTestCafeError: true,
  callsite:
   CallsiteRecord {
     filename: 'TestCafe\\authentication.page.js',
     lineNum: 152,
     callsiteFrameIdx: 6,
     stackFrames:
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        CallSite {},
        [Object],
        [Object],
        [Object],
        [Object],
        CallSite {} ],
     isV8Frames: true },
  errMsg: 'AssertionError: expected false to be truthy'
}

这是我的代码authentication.page.js:

import { Selector, t } from 'testcafe';

export default class AuthenticationPage {
    constructor(){
        //add page elements to our page model
        //select sign up form elements 
        this.username = Selector('#user_login');
        this.user_email= Selector('#user_email');
        this.user_password = Selector('#user_password');
        this.signup_form = Selector('#signup-form');
        this.registerBtn = Selector('#signup_button');

        //continue button
        this.continue_btn = Selector('.btn.btn-primary.js-choose-plan-submit');
    }

    //create a new github account
    async register(){
        /**
         * Step 1:
         * Set up your account
         * first thing to do is checking for the form
         */
        await t
            .setTestSpeed(0.1)
            .expect(this.signup_form.exists).ok()
            .expect(this.signup_form.getAttribute('method')).eql('post')
            .expect(this.signup_form.getAttribute('action')).eql('/join')
            .catch((error) => {
                console.error(error);
            });

        // input elements
        await t
            .setTestSpeed(0.1)

            // username input check
            .expect(this.username.exists).ok()
            .expect(this.username.getAttribute('type')).eql('text')
            .expect(this.username.value).eql('')

            // email input check
            .expect(this.user_email.exists).ok()
            .expect(this.user_email.getAttribute('type')).eql('text')
            .expect(this.user_email.value).eql('')

            // password input check
            .expect(this.user_password.exists).ok()
            .expect(this.user_password.getAttribute('type')).eql('password')
            .expect(this.user_password.value).eql('')

            .catch((error) => {
                console.error(error);
            });
        // fill out the inputs
        await t
            .setTestSpeed(0.1)

            .typeText(this.username, 'some username')
            .expect(this.username.getAttribute('class')).eql('form-control is-autocheck-successful')

            .typeText(this.user_email, 'some email')
            .expect(this.user_email.getAttribute('class')).eql('form-control is-autocheck-successful')

            .typeText(this.user_password, 'some password')

            .catch((error) => {
                console.log(error);
            });
        // Captcha verification

        await t
            .expect(await Selector('svg[class="octicon octicon-check text-green"]').exists).ok()
            .catch((error) => {
                console.log(error);
            }); 
        await t
            .setTestSpeed(0.1)

            // Input data check
            .expect(this.username.value).contains('some username')
            .expect(this.user_email.value).contains('some email')
            .expect(this.user_password.value).contains('some password')

            // Singup Check
            .expect(this.registerBtn.exists).ok()
            .expect(this.registerBtn.getAttribute('type')).eql('submit')
            .click(this.registerBtn)

            .catch((error) => {
                console.error(error);
            });
        /**
         * Step 2:
         * Choose your plan
         */
        await t
                .expect(this.continue_btn.exists).ok()
                .expect(this.continue_btn.getAttribute('type')).eql('submit')
                .click(this.continue_btn)
                .catch((error) => {
                    console.log(error);
                });
        /**
         * Step 3:
         * Tailor your experience
         */
        const prog_exp_level = Selector('#answers_98_choice_476');
        const github_uses_plan = Selector('#answers_99_choice_468');
        const describe = Selector('#answers_100_choice_472');
        const submit_btn = Selector('input[type="submit"]')
        await t
                .setTestSpeed(0.1)
                .expect(prog_exp_level.exists).ok()
                .expect(prog_exp_level.getAttribute('type')).eql('radio')
                .click(prog_exp_level)

                .expect(github_uses_plan.exists).ok()
                .expect(github_uses_plan.getAttribute('type')).eql('checkbox')
                .click(github_uses_plan)
                .expect(github_uses_plan.checked).ok()

                .expect(describe.exists).ok()
                .expect(describe.getAttribute('type')).eql('radio')
                .click(describe)

                .expect(submit_btn.exists).ok()
                .click(submit_btn)

                .catch((error) => {
                    console.log(error);
                });
    }
}

在这个文件中我调用了注册函数register.test.js:

// import the testcafe module
import { Selector, ClientFunction} from 'testcafe';
import AuthenticationPage from './authentication.page';

const page = new AuthenticationPage();
//declare a fixture
fixture `Github Signup Test`
    .page `https://github.com/join`;

//create login test code
test
    .before( async t => {
        const link = await Selector('a').withText('Sign up');
        if(await link.exists && await link.visible){
            await t
                .click(link)

                .catch((error) => {
                    console.error(error);
                });
        }
    })
    ('register test', async t => {
        await page.register();

    })
    .after( async t => {
        console.log('test..');
    });

在进行测试时,我看到验证码验证无法检查。 我需要知道如何解决这个问题,拜托 有什么建议吗?

【问题讨论】:

  • 如果我错了请纠正我:您的脚本尝试自动注册一个新的 Github 帐户? IE。这是一个 Github 帐户生成器机器人?你是在问如何欺骗验证码以验证它不是机器人?
  • 您能否更详细地描述您想要实现的目标以及如何实现,而不仅仅是发布整批代码?
  • @RolfBly 确切地说,我应该通过 github 中的 testcafe 自动创建一个用户,并且我的脚本会显示,但是当我通过 testcafe chrome register.test.js 运行测试时出现错误,您可以尝试测试你是否只想安装TestCafe框架然后运行这个命令:testcafe chrome register.test.js你可以看到测试如何在浏览器中创建一个新的github帐户
  • @Hanae 您是否考虑过创建一个阻碍对机器人的保护的机器人的道德规范?

标签: javascript github testing e2e-testing testcafe


【解决方案1】:

嗯……,

  1. 首先,验证码嵌套在两个 iframe 中。你必须切换 到这些 iframe 解释 here

  2. 那么你必须按照here的说明截取验证码;

  3. 然后你必须创建和训练一个神经网络来识别如何 图像放置:您可以使用 TensorFlow为此目的

【讨论】:

  • 为什么要使用Tensorflow,创建一个github账号只是一个简单的测试
  • @hanae,简单的测试并不意味着简单的测试:做这样的测试会让你成为英雄。
  • 是的,我知道,你能帮我看看怎么做吗?
  • @hanae,是的,当然,给我一些时间来设置一个 tensorflow 神经网络,准备好后我会 ping 你
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-19
  • 2021-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多