小编Geo*_*ing的帖子

在单个小黄瓜场景中有多组Given/When/Then是否可以

我在Gherkin编写验收测试,我想根据初始操作测试Web应用程序UI中的多个更改.这是一个例子:

        Scenario: Cancel editing a new text asset
            Given the user "test_user@fakedomain.com" is logged in
            When the user navigates to "/build/"
            And the user clicks the "Sandbox" link
            And the user inputs "Test story for canceling editing of a new text asset" for the "title" field
            And the user inputs "Test User" for the "byline" field 
            And the user inputs "My summary, so exciting!" for the "summary" textarea
            And the user clicks on "Untitled Section" in the section list
            And …
Run Code Online (Sandbox Code Playgroud)

testing bdd gherkin

18
推荐指数
1
解决办法
3万
查看次数

如何使用Python在JSON的HTML标记中转义'/'?

注意:这个问题非常接近于在脚本标记中嵌入JSON对象,但是对该问题的回答提供了我已经知道的内容(在JSON /==中\/).我想知道如何逃避.

HTML规范禁止在<script>元素内的任何位置使用封闭的HTML标记.所以,这会导致解析错误:

<script>
var assets = [{
  "asset_created": null, 
  "asset_id": "575155948f7d4c4ebccb02d4e8f84d2f", 
  "body": "<script></script>"
}];
</script>
Run Code Online (Sandbox Code Playgroud)

在我的情况下,我通过在Django模板中呈现JSON字符串来生成无效情况,即:

<script>
var assets = {{ json_string }};
</script>
Run Code Online (Sandbox Code Playgroud)

我知道JSON解析\/相同/,所以如果我可以在JSON字符串中转义我的结束HTML标记,我会很好.但是,我不确定这样做的最好方法.

我天真的做法就是这样:

json_string = '[{"asset_created": null, "asset_id": "575155948f7d4c4ebccb02d4e8f84d2f", "body": "<script></script>"}]'
escaped_json_string = json_string.replace('</', r'<\/')
Run Code Online (Sandbox Code Playgroud)

有没有更好的办法?或者我忽视的任何陷阱?

html python django escaping

5
推荐指数
1
解决办法
2294
查看次数

如何在提交后重置React表单中的选择元素?

我有一个表单的React组件,定义如下.表格是"受控制的".提交表单时,我想将select元素重置为第一个(和空)选项.我以为我可以通过在提交处理程序中调用setState()来实现这一点.虽然这会导致组件重新渲染,但选择元素中先前选择的选项仍处于选中状态.

const CreateProgram = React.createClass({
  getInitialState: function() {
    return {
      agency: undefined,
      ageGroup: undefined,
      programType: undefined
    };
  },

  render: function() {
    if (!this.props.school) {
      return false;
    }

    if (!this.props.agencies.length) {
      return false;
    }

    let agencyOptions = [
      <option value="" key=""></option>
    ].concat(this.props.agencies.map(function(agency) {
      return <option value={agency.properties.slug} key={agency.properties.slug}>{agency.properties.agency}</option>;
    }));

    let programTypeOptions = [
      <option value="" key=""></option>
    ].concat(this.props.programTypes.map(programType => {
      return <option value={programType} key={programType}>{programType}</option>;
    }));

    return (
      <form className="create-program" onSubmit={this.handleSubmit}>
        <fieldset className="form-group">
          <label htmlFor="agency">Agency</label>
          <select className="form-control" id="agency" value={this.state.agency ? this.state.agency.properties.slug : undefined} onChange={this.handleChangeAgency} …
Run Code Online (Sandbox Code Playgroud)

forms reactjs

3
推荐指数
1
解决办法
8662
查看次数

标签 统计

bdd ×1

django ×1

escaping ×1

forms ×1

gherkin ×1

html ×1

python ×1

reactjs ×1

testing ×1