how to fix 'AssertionError: expected false to be truthy' error?

Refresh

April 2019

Views

86 time

1

I am beginner on E2E Tests and I want to make a e2e signup to a github account test with TestCafe, but I get this error when runing test:

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'
}

this my code 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);
                });
    }
}

and in this file I did I call to register function 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..');
    });

while do test, I see that the captcha verification can't checked. I need to know how can I fix this problem, please any ideas for help?

1 answers

3

Hum...,

  1. first of all, the captcha is nested in two iframes. You must switch to these iframes as explained here.

  2. Then you must take a screenshot of the captcha as explained here;

  3. Then you have to create and train a neural network to recognize how the image is placed: you can use TensorFlow for this purpose