自动化测试协助理工科程师具(Selenium IDE等)

      本随表目录

el (expression language)

    Selenium
IDE安装和动用

el 基础操作符

    FireBug安装和平运动用

图片 1

    FirePath安装和动用

el 能够隐含对象(便是能够平素访问的)

 

图片 2

Selenium IDE安装

el 的两种采纳办法,第1类别似在jsp中尚无什么样用,首要用以jsf

措施一:打开Firefox–》添加组件–》搜索出selenium
IDE –》安装到Firefox
需重启安装—》检查是或不是安装成功(工具中查阅)

图片 3

只顾:这种形式不必然能寻找的到

el可以访问的对象(javaBean , 类集, 枚举 , 隐含对象)

 

图片 4

措施二:安装Selenium
IDE 是火狐的二个插件 官网:http://docs.seleniumhq.org/download/

在oracle官方网站上记录下来的部分自个儿以为有效的东西:

别的一种方法正是先在官网上下载插件,然后打开火狐的工具—扩张—点击设置的图标—采纳从文件安装附属类小部件组件

1. 
${customer}
The web container evaluates the variable that appears in an expression
by looking up its value according to the behavior of
PageContext.findAttribute(String), where the String argument is the name
of the variable. For example, when evaluating the expression
${customer}, the container will
look for customer in the page, request, session, and application scopes
and will return its value. If customer is not found, a null value is
returned.

 

 web容器在拍卖那段代码是后台使用的是
PageContext.findAttribute(String)方法,该方法的定义如下:

设置方式详见:http://www.cnblogs.com/TankXiao/p/4140543.html

图片 5

设置不上的原由

该方式是抽象类PageContext继承抽象类JspContext的。

如果您的firefor
不能够安装Selenium IDE, 最或者的缘故是您的Firefox 的本子太高了,

那个法子的概念和地方深藕红字体的叙说基本相同,正是说会规行矩步page ->
request -> session -> application
的这么些顺序搜寻customer属性,如果有再次来到,否者再次来到null。

建议设置一个低一些版本的firefox,
并且禁止Firefox自动升级

 

应用selenium
webdriver做自动化,火狐浏览器的本子不可能太高,不然会运行战败,一般推荐版本为27-32里面

2. 

 

 

什么是Selenium
IDE?

Where Value Expressions Can Be Used
Value expressions using the ${} delimiters can be used in

Selenium
IDE是Firefox的浏览器插件,能够达成网页操作步骤的录制和重播,并得以导出Java,Python,C#等语言格式的程序代码。

Static text

亮点:小巧简单,无需程序经验,火速上手

Any standard or custom tag
attribute that can accept an expression

症结:摄像脚本转换为代码语言会有错误,须求自动化测试职员认为更改调式

The value of an expression in static text is computed and inserted into
the current output. Here is an example of an expression embedded in
static text:

 

<some:tag>
some text ${expr} some
text
</some:tag>
If the static text appears in a tag body, note that an expression will
not be evaluated if the body is declared to be tagdependent.

Selenium
IDE界面和作用介绍

Lvalue expressions can be used only in tag attributes that can accept
lvalue expressions.

开辟selenium IDE
查看文件中有那2个Test Case 和Test Suite

A tag attribute value using either an rvalue or lvalue expression can be
set in the following ways:

二个有关的测试用例(Test
Case)便是1个测试套件(Test
Suite),也正是说一个测试套件由两个测试用例串联组成,能够将测试套件驾驭为测试用例组

With a single expression construct:

 

<some:tag
value=”${expr}”/>
<another:tag
value=”#{expr}”/>
These expressions are evaluated, and the result is converted to the
attribute’s expected type.

① 、打开selenium
IDE进行脚本摄像

With one or more expressions separated or surrounded by text:

在Base
UHavalL中地址,点击录像按钮,打开浏览器操作,暗许进入为摄像情形

<some:tag
value=”some${expr}${expr}text${expr}”/>
<another:tag
value=”some#{expr}#{expr}text#{expr}”/>
These kinds of expression, called composite expressions, are evaluated
from left to right. Each expression embedded in the composite expression
is converted to a String and then concatenated with any intervening
text. The resulting String is then converted to the attribute’s expected
type.

2个测试用例对应的正是如拾草芥的操作步骤

只看有颜色的字,
第一个说el能够再平凡文书和当作标签的值使用,第四个和第三个颜色字分别为在普通文书和作为标签属性的实例。第七个代表el能够和文字任何搭配使用,个中的#本人还不掌握在jsp中有怎样用。

Command:命令,表示要执行的操作时怎么样

 

Target:目的,即操作的界面成分是哪些

ognl

Value:值,操作时选拔的值

 

图片 6

  1. 重庆大学讲了ognl的调用链,该调用链只能用于get值,无法set值。

 

The fundamental unit of an OGNL expression is the navigation chain,
usually just called “chain.”

② 、编写恐怕摄像脚本

 name.toCharArray()[0].numericValue.toString()

编辑脚本区域:右键–》Insert
New…–》输入指令,Target 点击select
–》find,然后鼠标移入浏览器,输入框等会宝石蓝高亮显示

Note that this example can only be used to get a value

叁 、脚本弄好现在,导出脚本

 

如:
文件—》Export Test Case Aa—》Java Junit4 WebDriver

 2. ognl无法接纳setValue()那样会造成InappropriateExpressionException
极度抛出

导出的脚本语言有很二种,支持java,python,C#等

from an object, not to set a value.Passing the above expression to the
Ognl.setValue() method would cause an InappropriateExpressionException
to be thrown, because the last link in the chain is neither a property
name nor an array index.

④ 、eclipse导入脚本

  1. ognl 的二种特性调用形式

   常用命令的选用:

 For example, OGNL internally treats the “array.length” expression
exactly the same as this expression: array[“length”] And this
expression would have the same result (though not the same internal
form):  array[“len” + “gth”]

  • 安装延时:pause
    如:pause 三千
  • ….

 

 

  1. ognl同时能够调用方法,当然前提是该情势在ognl中,方法参数用逗号隔断。

FireBug安装

5.
在逗号前面加上括号,在括号中得以对前边的对象值进行引用,例如上边的这几个例子,#this表示listeners.size()的值。 

工具–附加组件–搜索所需组件–安装

listeners.size().(#this > 100? 2*#this : 20+#this)

FireBug的使用(查看html源码)

 

将鼠标放在,如:输入框,右键—使用FireBug查看页面成分

  1. 对变量赋值,与Java类似,如下例,#相应和不相同范围的变量有关

 

To assign a value to a variable explicitly, simply write an assignment
statement with a variable reference on the left-hand side:

FirePath的使用(原生的firebug并无法支撑按XPath查找成分,要求选取firebug的恢弘插件firepath)

#var = 99

先打开FireBug—》页面上回出现FirePath,见图

 

图片 7

  1. 动用括号改变总计次序以及包装总结单元,方法类似于Java

 

Parenthetical Expressions As you would expect, an expression enclosed
in parentheses is evaluated as a unit, separately from any surrounding
operators. This can be used to force an evaluation order different from
the one that would be implied by OGNL operator precedences. It is also
the only way to use the comma operator in a method argument.

 

7.
在逗号后边使用括号,上边的那段代码会先搜寻headline.parent属性,然后执行ensureLoaded()方法,然后回到parent属性的name属性值

headline.parent.(ensureLoaded(), name)

traverses through the headline and parent properties,ensures that the
parent is loaded and then returns (or sets) the parent’s name.

 

8.
直接行使逗号,不行使括号的盘算次序,上面那段代码和地点的接近,不过估量应用了默许的对象作为上下文

Top-level expressions can also be chained in this way.The result of the
expression is the right-most expression element.

ensureLoaded(), name

This will call ensureLoaded() on the root object, then get the name
property of the root object as the result of the expression.

 

9.
利用花括号定义list对象,下边这些表明式是用于判断name是还是不是相等null也许Untitiled,作者猜想应该是先将name封装成list

name in { null,”Untitled” }

 

  1.  ognl定义原始类型的数组

new int[] { 1, 2, 3 }

new int[5]

  1.  定义map

#{ “foo” : “foo value”, “bar” : “bar value” }

  1.  使用ognl遍历Collection类型的靶子,其中的objects表示一个类集对象,
    #this代表遍历的方今因素,然后遵照表明式对每二个要素进行计算,然后回到总括后获得的list元素,这在ognl官网上称为projecting

objects.{ #this instanceof String ? #this :#this.toString()}

 

  1.  使用ognl从类集对象中抽取出有个别因素,那在ognl官方网站上称作selection
    ,下边这么些表达式从listeners类集对象中抽取出那几个是ActionListener的要素

listeners.{? #this instanceof ActionListener}

 

应用ognl从类集对象中筛选出第3个适合的对象,然后将该对象封装成List再次来到,原始的做法是listeners.{?
true
}[0],不过那种方法是cumbersome(愚蠢的),因为一旦没有匹配到别的结果要么listeners.{?
true}是空的,那么会抛出ArrayIndexOutOfBoundsException相当。使用上面那种格式会将首先个卓殊的要素作为一个list对象回来,假若没有匹配到任何因素则会回到八个空list。

objects.{^ #this instanceof String }

  1.  相同获取最终二个相当的成分

objects.{$ #this instanceof String }

 

  1. 动用ognl调用构造方法必须使用类的人名

You can create new objects as in Java, with the new operator. One
difference is that you must specify the fully qualified class name for
classes other than those in the java.lang package.

 

  1. 利用ognl调用静态方法,这一个leave out class 是怎么样意思?

 If you leave out class, it defaults to java.lang.Math,to make it easier
to call min and max methods. If you specify the class, you must give the
fully qualified

 name.  

@class@method(args)

  1.  获取静态属性

 @class@field

 

18.
 表明式的乘除,上边那一个表明式会将30看成BigInteger放入root对象(应该是value
stack)中

#fact(30H)

 

  1.  伪Lambda表达式(Pseudo-Lambda Expressions)

#fact = :[#this<=1? 1 : #this*#fact(#this-1)], #fact(30H)

The lambda expression is everything inside the brackets. The #this
variable holds the argument to the expression, which is initially 30H,
and is then one less for each successive call to the expression.

lambda表明式的具有情节都在局地方括号中,#this变量为lambda传递进参数fact的值,那个fact的值在后头进行了早先化为30H。

  1.  Connection 的伪属性

图片 8

  1.  在标点符号上与Java的两样

,(comma)

  逗号用于分开多个单身的表明式,逗号后边的百般值是该逗号表明式的再次来到值。比如ensureLoaded(),
name

{}(curly braces)

  用于创设list对象,比如{ null, true, false }

in/not in

  判断值是或不是属于有些集合,例如name in {null,”Untitled”} || name

 

  1.  ognl能够推行隐式的强制类型转换,具体规则如下:

Interpreting Objects as Booleans

  Any object can be used where a boolean is required. OGNL interprets
objects as booleans like this:

  1) If the object is a Boolean, its value is extracted and returned;

  2) If the object is a Number, its double-precision floating-point
value is compared with zero; non-zero is treated as true, zero as false;

  3) If the object is a Character, its boolean value is true if and
only if its char value is non-zero;

  Otherwise, its boolean value is true if and only if it is non-null.

Interpreting Objects as Numbers

  Numerical operators try to treat their arguments as numbers. The
basic primitive-type wrapper classes (Integer, Double, and so on,
including Character   and Boolean, which are treated as integers), and
the “big” numeric classes from the java.math package (BigInteger and
BigDecimal), are recognized as    special numeric types. Given an
object of some other class, OGNL tries to parse the object’s string
value as a number.Numerical operators that take two   arguments use
the following algorithm to decide what type the result should be. The
type of the actual result may be wider, if the result does not fit
  in the given type.

  1)  If both arguments are of the same type, the result will be of
the same type if possible;

  2)  If either argument is not of a recognized numeric class, it will
be treated as if it was a Double for the rest of this algorithm;

  3)  If both arguments are approximations to real numbers (Float,
Double, or BigDecimal), the result will be the wider type;

  4)  If both arguments are integers (Boolean, Byte, Character, Short,
Integer, Long, or BigInteger), the result will be the wider type;

    5)  If one argument is a real type and the other an integer type,
the result will be the real type if the integer is narrower than “int”;
BigDecimal if the       integer is BigInteger; or the wider of the
real type and Double otherwise.

Interpreting Objects as Integers

   Operators that work only on integers, like the bit-shifting
operators, treat their arguments as numbers, except that BigDecimals and
BigIntegers are   operated on as BigIntegers and all other kinds of
numbers are operated on as Longs. For the BigInteger case, the result of
these operators remains a   BigInteger; for the Long case, the result
is expressed as the same type of the arguments, if it fits, or as a Long
otherwise.

Interpreting Objects as Collections

  The projection and selection operators (e1.{e2} and e1.{?e2}), and
the in operator, all treat one of their arguments as a collection and
walk it. This is   done differently depending on the class of the
argument:

  1) Java arrays are walked from front to back;

  2) Members of java.util.Collection are walked by walking their
iterators;

  3) Members of java.util.Map are walked by walking iterators over
their values;

  4) Members of java.util.Iterator and java.util.Enumeration are
walked by iterating them;

  5) Members of java.lang.Number are “walked” by returning integers
less than the given number starting with zero;

  All other objects are treated as singleton collections containing
only themselves.

 小说来源 http://commons.apache.org/proper/commons-ognl/language-guide.html

地方讲的都以ognl的部分性格,上边说一说都在哪些地点使用

The normal usage of OGNL is to embed the language inside of other
constructs to provide a place for flexible binding of values from one
place to another. An example of this is a web application where values
need to be bound from a model of some sort to data transfer objects that
are operated on by a view. Another example is an XML configuration file
wherein values are generated via expressions which are then bound to
configured objects.

 上面那段话来自于ognl官方网站,首如果说ognl首要用来view(jsp)中,还有便是置于XML文件中,比如在web项目中的web.xml
和 strut中的struts.xml

关于ognl的使用

http://blog.csdn.net/li\_tengfei/article/details/6098134。//
详细讲解valueStack,以及Ognl语言特性

http://www.blogjava.net/max/archive/2007/04/28/114417.html   //
Ognl的应用

 那两篇博客讲的很精通,小编补偿二个valueStack中指标的压人顺序:

图片 9

图片 10

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图