从空手道中的html响应中提取Javascript [英] Extract Javascript from html response in karate

查看:93
本文介绍了从空手道中的html响应中提取Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里我需要帮助.我有一个POST请求,该请求返回带有HTML响应的响应,并且此HTML响应中包含javascript.我需要提取文本/javascript,其中说出checkout = {"TransactionID"} ..并使用空手道将其作为正文传递到新的POST请求中.我想我需要在空手道功能文件中编写javascript函数,我无法导入库等.

I need help here. I have a POST request which returns response with a HTML response and this HTML response contains javascript inside it. I need to extract text/javascript where it says checkout = {"TransactionID""} .. and pass it as a body in the new POST Request using Karate. I think I need to write javascript function inside the karate feature file, however, I am not able to import libraries etc.

        <!DOCTYPE html>
<html lang="en">
<head>
    <title> ABC test</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="#eb843a">
    <meta name="theme-color" content="#eb843a">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" href="https://use.typekit.net/plq2clw.css" />
    <style type="text/css">
        body {
            background-color: #eff3ef;
        }

        .splash-content {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }



        .splash-ring {
            position: relative;
            width: 64px;
            height: 64px;
            margin: 0 auto;
            margin-bottom: 20px;
        }



        }
    </style>
</head>
<body>
    <div aurelia-app="root">





        <div class="splash-body animated fadeIn">
            <div class="splash-content splash-primary">

                <div>
                    <div class="splash-ring"><div></div><div></div><div></div><div></div></div>
                </div>
                humming...
            </div>
        </div>
    </div>

    <script src="/Client/jspm_packages/system.js"></script>
    <script type="text/javascript">
        System.baseURL = "/Client/";
        var version = '1.1.46.29705';
        var checkout = null;
        var transactionId = null;
        var channel = null;
    </script>

    <script src="/Scripts/crtgpf.js"></script>
    <script src="/Scripts/crtgpf-wrapper.js"></script>

        <script type="text/javascript">
            checkout = **{"TransactionId":457123,"TransactionTimeout":0,"Step":38,"Status":10,"Channel":1,"Variation":"DEFAULT","ProductType":"EPOZ","ProductMode":2,"PlatformType":"Default","Platform":{"Name":"Default","Currency":"AUD","IsTesting":false,"IsShipped":false,"Nonce":null,"CustomerInfo":{"Title":"Mr","FirstName":"first541","MiddleName":"JOURNEYA","LastName":"external541","FullName":"first541 JOURNEYA external541","Email":"aaa@b.com.au","Mobile":"33333","PhoneHome":"33333","PhoneWork":"0881110011","DateOfBirth":"1970-08-01T00:00:00Z"},"Instalments":[],"Deposit":0.0,"DepositInitial":0.0,"Amount":200.5,"Description":"","FinancedAmount":200.5,"Frequency":2,"TermsInMonths":5},"Data":{"customer.detail.middleName":"JOURNEYA","employment.suburb":"burb1","customer.address.home.line1":"1528 STURT ,"client.headers":"[{"Key":"Cache-Control","Value":"max-age=0"},{"Key":"Connection","Value":"keep-alive"},{"Key":"Content-Length","Value":"1549"},{"Key":"Content-Type","Value":"application/x-www-form-urlencoded"},"Outcome":0,"AcceptedTerms":null,"AcceptedPrivacy":null,"ConsumerFees":null,"PaymentPlans":[],"Redirect":null,"AuthReason":null,"ErrorCode":null}**;
            transactionId = 457123;
        </script>

    <script src="/Client/2222/config.js"></script>
    <script src="/Client/2222/dist/startup.js"></script>
        <!-- Google Tag Manager -->
        <script>
            var gtmContainerId = 'GTM-5533';

            (function (w, d, s, l, i) {
                w[l] = w[l] || []; w[l].push({
                    'gtm.start':
                        new Date().getTime(), event: 'gtm.js'
                }); var f = d.getElementsByTagName(s)[0],
                    j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src =
                        'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f);
            })(window, document, 'script', 'dataLayer', gtmContainerId);
        </script>
        <!-- End Google Tag Manager -->

</body>
</html>;

我需要提取此javascript,这将是下一个POST调用中的请求.

I need to extract this javascript which will be a request in the next POST call.

推荐答案

使用我们将从0.9.6.RC3开始将其添加为karate.extract()助手:

We will be adding this as a karate.extract() helper in 0.9.6.RC3 onwards: https://github.com/intuit/karate/issues/1094#issuecomment-616059232

这篇关于从空手道中的html响应中提取Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆