Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit b4d8542

Browse files
committed
增加批量操作元素的单元测试
1 parent b41af51 commit b4d8542

2 files changed

Lines changed: 152 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright 2002-2007 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.suren.autotest.web.framework.util;
18+
19+
import java.io.IOException;
20+
21+
import org.dom4j.DocumentException;
22+
import org.junit.After;
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.suren.autotest.web.framework.page.HomePage;
26+
import org.suren.autotest.web.framework.page.LoginPage;
27+
import org.suren.autotest.web.framework.settings.SettingUtil;
28+
import org.xml.sax.SAXException;
29+
30+
/**
31+
* 元素批量操作的工具类单元测试
32+
* @author suren
33+
* @date 2017年5月14日 下午9:43:38
34+
*/
35+
public class ElementUtilTest
36+
{
37+
private SettingUtil util;
38+
39+
/**
40+
* 加载元素定位信息,初始化数据源
41+
* @throws IOException
42+
* @throws DocumentException
43+
* @throws SAXException
44+
*/
45+
@Before
46+
public void before() throws IOException, DocumentException, SAXException
47+
{
48+
util = new SettingUtil();
49+
util.readFromClassPath("elements/xml/maimai_chrome.xml");
50+
util.initData();
51+
}
52+
53+
/**
54+
* 释放资源
55+
* @throws IOException
56+
*/
57+
@After
58+
public void after() throws IOException
59+
{
60+
util.close();
61+
}
62+
63+
@Test
64+
public void buttonClick() throws IOException, DocumentException, SAXException
65+
{
66+
HomePage homePage = util.getPage(HomePage.class);
67+
homePage.open();
68+
ElementUtil.click(homePage.getToLoginBut());
69+
}
70+
71+
@Test
72+
public void textFillValue()
73+
{
74+
HomePage homePage = util.getPage(HomePage.class);
75+
homePage.open();
76+
ElementUtil.click(homePage.getToLoginBut());
77+
78+
LoginPage loginPage = util.getPage(LoginPage.class);
79+
ElementUtil.fillValue(loginPage.getPhone(), loginPage.getPassword());
80+
}
81+
82+
@Test
83+
public void pageOperation()
84+
{
85+
HomePage homePage = util.getPage(HomePage.class);
86+
homePage.open();
87+
ElementUtil.click(homePage);
88+
89+
LoginPage loginPage = util.getPage(LoginPage.class);
90+
ElementUtil.fillValue(loginPage);
91+
ElementUtil.click(loginPage);
92+
}
93+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<suren:autotest xmlns:suren="http://surenpi.com"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://surenpi.com http://surenpi.com/schema/autotest/autotest.web.framework.xsd ">
5+
<suren:engine driver="chrome"/>
6+
<suren:pages pagePackage="org.suren.autotest.web.framework.page">
7+
<suren:page class="HomePage" url="${startUrl}">
8+
<suren:field name="toLoginBut" type="button" byCss="login"/>
9+
</suren:page>
10+
11+
<suren:page class="LoginPage" dataSource="user_data">
12+
<suren:field name="phone" type="input" byName="m" strategy="zone"
13+
byXpath="//input[@placeholder='请输入手机号码/脉脉号']">
14+
<suren:locators>
15+
<suren:locator name="byId" value="form"/>
16+
<suren:locator name="byXpath" value="//input[1]"/>
17+
</suren:locators>
18+
</suren:field>
19+
<suren:field name="password" type="input" strategy="zone"
20+
byXpath="//input[@placeholder='请输入密码']">
21+
<suren:locators>
22+
<suren:locator name="byId" value="form"/>
23+
<suren:locator name="byXpath" value="//input[@type='password']"/>
24+
</suren:locators>
25+
</suren:field>
26+
<suren:field name="loginBut" type="button" strategy="zone"
27+
byXpath="//input[@value='登录']">
28+
<suren:locators>
29+
<suren:locator name="byId" value="form"/>
30+
<suren:locator name="byXpath" value="//input[@value='登录']"/>
31+
</suren:locators>
32+
</suren:field>
33+
</suren:page>
34+
35+
<suren:page class="MenuPage">
36+
<suren:field name="gossipBut" type="button" byPartialLinkText="匿名八卦" strategy="zone">
37+
<suren:locators>
38+
<suren:locator name="byId" value="react_app"/>
39+
<suren:locator name="byPartialLinkText" value="匿名八卦"/>
40+
</suren:locators>
41+
</suren:field>
42+
</suren:page>
43+
44+
<suren:page class="SSIPPage" dataSource="post_msg">
45+
<suren:field name="inputPanel" type="input" byCss="inputPanel"></suren:field>
46+
<suren:field name="postBut" type="button" byPartialLinkText="发布" strategy="zone">
47+
<suren:locators>
48+
<suren:locator name="byId" value="react_app"/>
49+
<suren:locator name="byPartialLinkText" value="发布"/>
50+
</suren:locators>
51+
</suren:field>
52+
</suren:page>
53+
</suren:pages>
54+
55+
<suren:dataSources>
56+
<suren:dataSource name="user_data" type="xml_data_source" resource="dataSource/xml/user_data.xml"/>
57+
<suren:dataSource name="post_msg" type="xml_data_source" resource="dataSource/xml/post_msg.xml"/>
58+
</suren:dataSources>
59+
</suren:autotest>

0 commit comments

Comments
 (0)