如何在每次运行硒测试时增加字段值?

时间:2009-04-25 15:19:19

标签: selenium

每次通过Selenium IDE运行Selenium测试时,是否有任何简单的方法可以将字段值增加+1?

Command: Type 
Target: some kind of id
Value: number+1

编辑1 :感谢krosenvold的回复。我有了你的想法,这是我到目前为止的简化版本:

...     
store | 10 | x
storeEval | storedVars['x'] = ${x}+1 | 
...

变量的x值确实会增加,但是如何在不同的测试运行之间保存该值?它甚至可能吗?

每次运行测试时我应该获得$ x值吗?在测试页面结束时我会将$ x值分配给某个虚拟元素,这样我可以在下次运行测试时检索先前增加的值吗?

5 个答案:

答案 0 :(得分:5)

正确答案

商店| 10 |我

商店| javascript {storedVars.i ++;} |我

回声| $ {I}

答案 1 :(得分:4)

这是您的问题的解决方案

store | 10 | i
store | javascript{storedVars.i++;} 
echo  | ${i}

答案 2 :(得分:1)

您可以使用eval;

eval($('elementId').value = $('elementId').value +1);

我所展示的确切语法暗示了客户端上的原型;

document.getElementById('elementId').value也应该在standard DOM环境中执行此操作。

答案 3 :(得分:0)

这对我有用

<?php
    require('Assests/connection/connection.php');
    error_reporting(0);
    $vcntlist = "";
    if (!empty($_POST['cntid'])) {
        $id = $_POST['cntid'];
        $result = mysqli_query($conn, "SELECT `id`, `vndr_cntname`, `designation`, `vndr_cntmobile`, `vndr_cntmail`,`vndr_id` FROM `vndr_cntdtls`where id=$id");
        $rowcount = mysqli_num_rows($result);
        if ($rowcount > 0) {
            $row = mysqli_fetch_array($result);
            $vcntid = $row['id'];
            $cntname = $row['vndr_cntname'];
            $cntdesignation = $row['designation'];
            $cntmobile = $row['vndr_cntmobile'];
            $cntmail = $row['vndr_cntmail'];
        }
    }
    if (!empty($_POST['name']) && !empty($_POST['dgnation']) &&
        !empty($_POST['mobileno']) && !empty($_POST['emailid']) &&
        !empty($_POST['vid'])) {
        $id = $_POST['id'];
        $name = $_POST['name'];
        $degination = $_POST['dgnation'];
        $mobile = $_POST['mobileno'];
        $email = $_POST['emailid'];
        $vndrid = $_POST['vid'];
        if (empty($_POST['id'])) {
            $query = mysqli_query($conn, "INSERT INTO `vndr_cntdtls`(`vndr_cntname`, `designation`, `vndr_cntmobile`, `vndr_cntmail`, `vndr_id`) VALUES ('$name','$degination','$mobile','$email',$vndrid)");
        } else {
            $update1 = mysqli_query($conn, "UPDATE `vndr_cntdtls` SET `vndr_cntname`='$name',`designation`='$degination',`vndr_cntmobile`='$mobile',`vndr_cntmail`='$email' WHERE id=$id") or die(mysqli_error($conn));
        }
        $result = mysqli_query($conn, "SELECT  DISTINCT `id`, `vndr_cntname`, `designation`, `vndr_cntmobile`, `vndr_cntmail`,vc.vndr_id FROM `vndr_cntdtls` vc INNER JOIN vendors v ON vc.vndr_id=$vndrid") or die(mysqli_error($conn));
        $rowcount = mysqli_num_rows($result);
        if ($rowcount > 0) {
            while ($row = mysqli_fetch_array($result)) {
                $vcntid = $row['id'];
                $cntname = $row['vndr_cntname'];
                $cntdesignation = $row['designation'];
                $cntmobile = $row['vndr_cntmobile'];
                $cntmail = $row['vndr_cntmail'];
            }
        }
    }
    echo json_encode($row);
?>

答案 4 :(得分:0)

store          | 0                                | iterator
echo           | ${iterator}                      |
execute script | return parseInt(${iterator}) + 1 | iterator
echo           | ${iterator}                      |

结果将是:

0
1