赛普拉斯:使HTTP请求与Promise一起使用

时间:2019-04-12 09:00:11

标签: javascript promise cypress

我正在尝试在服务器上发出HTTP请求,然后检查结果。 目前,我在postCar方法的response对象中得到了结果。但是结果是null经过then()方法的测试。

问题出在哪里?

postCar($access_token, $body) {
        return new Cypress.Promise((resolve) => {
            let bodyString = '';
            cy.request({
                method: 'POST',
                url: '/applications',
                form: true,
                failOnStatusCode: false,
                body: $body,
                headers: {
                    Content: 'application/json',
                    Authorization: 'Bearer ' + $access_token
                }
            })
            .then((response) => {
                cy.log('Response = ' + JSON.stringify(response));
                resolve(response);
            });
        });
    }

我的测试:

it('Car Spec : create a car', function () {

    let accessToken = Cypress.env('ACCESS_TOKEN')
    var correct_body = getValidBody();

    cy.postCar(accessToken, correct_body).then(function(res) {
       cy.log('Application Spec : postCar response :' + JSON.stringify(res));
    });

});

1 个答案:

答案 0 :(得分:1)

您不应将命令包装在def searchValue(obs, concept): try: found = re.search('## !!' + str(concept) + '=(.+?)!! ##',obs) except AttributeError: found = 'null' return found obs= '!!1834=7850!! ## !!1915=Patient is awaiting imaging results, then start darcabazine 250 ml every 21 days.!! ## !!1915=Patient is HIV positive since 2016,no presents with pains on the plantar surface and pelvic pain.!! ## !!5096=2013-07-29!! ## !!5219=1068!! ## !!6504=7189!! ## !!6509=6511!! ## !!6575=1107!! ## !!6605=1065!! ## !!7191=MELANOMA OF THE RIGHT HEEL.!! ## !!8723=5622!!' bett = searchValue(obs, str(1915)) print(bett) 中。赛普拉斯自定义命令并不旨在返回承诺。试试这个:

import pandas as pd

df = pd.read_csv('<filename>')
df.columns = [x.upper() for x in df.columns]