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

Commit 1ac9dc8

Browse files
committed
代码整理
1 parent c8e1206 commit 1ac9dc8

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@
120120
<artifactId>autotest.report</artifactId>
121121
<version>1.0.0-20170618</version>
122122
</dependency>
123+
<dependency>
124+
<groupId>com.surenpi.autotest</groupId>
125+
<artifactId>autotest.webui</artifactId>
126+
<version>1.0-SNAPSHOT</version>
127+
</dependency>
123128

124129
<!-- Selenium依赖 -->
125130
<dependency>

src/main/java/org/suren/autotest/web/framework/page/Page.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434

3535
/**
3636
* 对HTML页面的逻辑封装,不一定是一一对应
37+
* @deprecated 建议使用WebPage类来代替
3738
* @author suren
3839
* @date Jul 17, 2016 9:06:52 AM
3940
*/
41+
@Deprecated
4042
public class Page
4143
{
4244
/** 页面唯一标示 */
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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.selenium;
18+
19+
import org.openqa.selenium.Alert;
20+
import org.openqa.selenium.UnhandledAlertException;
21+
import org.openqa.selenium.WebDriver;
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
24+
import com.surenpi.autotest.webui.Page;
25+
26+
/**
27+
* @author suren
28+
* @date 2017年7月4日 下午7:51:57
29+
*/
30+
public class WebPage extends Page
31+
{
32+
@Autowired
33+
private SeleniumEngine engine;
34+
35+
@Override
36+
public void open()
37+
{
38+
String paramUrl = paramTranslate(getUrl());
39+
40+
engine.openUrl(paramUrl);
41+
42+
try
43+
{
44+
engine.computeToolbarHeight();
45+
}
46+
catch(UnhandledAlertException e)
47+
{
48+
Alert alert = engine.getDriver().switchTo().alert();
49+
if(alert != null)
50+
{
51+
alert.dismiss();
52+
53+
engine.computeToolbarHeight();
54+
}
55+
}
56+
}
57+
58+
@Override
59+
public void close()
60+
{
61+
engine.close();
62+
}
63+
64+
@Override
65+
public void closeOthers()
66+
{
67+
String currentTitle = getTitle();
68+
String currentWinHandle = engine.getDriver().getWindowHandle();
69+
70+
for(String winHandle : engine.getDriver().getWindowHandles())
71+
{
72+
WebDriver itemDrive = engine.getDriver().switchTo().window(winHandle);
73+
if(!itemDrive.getTitle().equals(currentTitle))
74+
{
75+
itemDrive.close();
76+
}
77+
}
78+
79+
engine.getDriver().switchTo().window(currentWinHandle);
80+
}
81+
82+
@Override
83+
public String getCurrentUrl()
84+
{
85+
return engine.getDriver().getCurrentUrl();
86+
}
87+
88+
@Override
89+
public String getPageSource()
90+
{
91+
return engine.getDriver().getPageSource();
92+
}
93+
94+
@Override
95+
public String getTitle()
96+
{
97+
return engine.getDriver().getTitle();
98+
}
99+
100+
}

0 commit comments

Comments
 (0)