在HTML块

时间:2016-05-02 19:30:46

标签: selenium rspec capybara

我让我的Selenium测试导航到公共虚拟收件箱以验证收到的电子邮件递送,并在那里执行一些确认工作流程(密码更改等)。它变得太慢而且不可靠。

我现在正在使用邮件服务的API来检索电子邮件。我能够搜索我需要的消息,并且能够检索我经常检查的HTML块。

有没有办法在HTML文本块上使用Capybara finder?

1 个答案:

答案 0 :(得分:1)

你可以通过

将一串html变成Capybara可以使用的东西
# l represents half the length of the array
l=1; # Sets l to 1, set the following while statement evaluates true
# Sets l to $RANDOM until it is an even number 
while [ $((l % 2)) -ne 0 ]; do 
    l=$RANDOM; 
done;
echo $l;
# Sets m and n to l
n=$l; # n is the number of 'a's 
m=$l; # m is the number of '-a's
# Initialises result as an empty string
result="";
# Doesn't stop until both 'a's and '-a's have been exhausted, i.e. n and m both equal 0
while [ "$n" != "0" ] && [ "$m" != "0" ]; do
    # Decides between 'a' and '-a'
    i=$(($RANDOM % 2));
    # Evaluates true if $i is 0, and the number of '-a's has not been exhausted, however also evaluates true if the number of '-a's has been exhausted
    if ([ "$i" == "0" ] && [ "$n" != "0" ]) || [ "$m" == "0" ]; then
        # Appends 'a' to result
        result="$result a";
        # Decrement the amount of 'a's left
        n=$((n-1));
    # Evaluates true if $i is 1, and the number of 'a's has not been exhausted, however also evaluates true if the number of 'a's has been exhausted
    elif ([ "$i" == "1" ] && [ "$m" != "0" ]) || [ "$n" == "0" ]; then
        # Appends '-a' to result
        result="$result -a";
        # Decrements the amount of '-a's left
        m=$((m-1));
    fi; 
done;
# Prints the result
echo $result;

然后你可以在节点上调用查找器

node.find(...)