如何使用请求承诺本地客户端向API调用添加cookie

时间:2018-06-25 13:58:37

标签: api selenium jasmine protractor request-promise

不确定在哪里出错,请帮助我与请求承诺本地客户端一起修复此APi请求。

fdescribe('Firm Customization Manage Template Tests', function() {
let allGroupsIndex = 4,
    checklistID1 = '786',
    checklist = 'Checklist',
    req = require('request'),
    rp = require('request-promise'),
    tough = require('tough-cookie'),
    tabs,
    email = personResult.obj.Email,
    pw = seEnv.adminPassword;

beforeEach(function() {
    toolbox.isNonAngular(true);
});

afterEach(function() {
    browser.driver.switchTo().defaultContent();
});
fit('should check 14-15 template works as intended',
    function() {
        console.log('template URL =======' +  beforeLastYearTempPage);
        browser.driver.get(beforeLastYearTempPage);
        toolbox.waitToClick(collabSE.avatarBtn, 50000);
        let randomId = toolbox.getRandomNumString(4),
        url = 'https://colqaproxy.caseware.com/auto27rel_sedev-2/e/api/firm',

            cookiejar = req.jar(),
            cookie = req.cookie('__machineid__=' + machineIDFirm);

        cookiejar.setCookie(cookie, url);

        element(by.buttonText('Close')).click();
        browser.sleep(12345).then(function() {
            var options = {
                method: 'POST',
                uri: url,

                requestBody : {
                    'jsonrpc': '2.0',
                    'id': randomId,
                    'method': 'createFirmTemplate',
                    'params': [
                        {
                            'sourceEngId': null,
                            'primaryAuthor': true,
                            'templateId': 'com.caseware.au.audit.smsf.2015'
                        }
                    ]
                },

                headers: {
                    'Content-Type': 'application/json',
                    jar: cookiejar
                }
            };

            let onSuccess = function() {
                console.info('Template Published,=======================)');
            };

            let successArgs = [];

            rp(options)
                .then(function(body) {
                    console.log('id iss' + body.result.object.id);
                })
                .catch(function(err) {
                    console.log('Failed to create template ==========' + 
err);
                });
        });

响应: StatusCodeError:500-“ Apache Tomcat / 8.0.33-错误报告H1 {font-family:Tahoma,Arial,sans-serif; color:white; background-color:#525D76; font-size:22px;} H2 {font-family :Tahoma,Arial,sans-serif;“ line \”>“

0 个答案:

没有答案