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

Commit c37f862

Browse files
committed
增加注解支持
1 parent 7a88a91 commit c37f862

12 files changed

Lines changed: 314 additions & 4 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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;
18+
19+
import org.springframework.context.annotation.ComponentScan;
20+
import org.springframework.context.annotation.Configuration;
21+
22+
/**
23+
* Spring零配置
24+
* @author suren
25+
* @date 2017年6月8日 上午8:21:10
26+
*/
27+
@Configuration
28+
@ComponentScan
29+
public class AutoApplication
30+
{
31+
32+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.annotation;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Target;
22+
23+
/**
24+
* @author suren
25+
* @date 2017年6月8日 下午12:40:15
26+
*/
27+
@Target(ElementType.FIELD)
28+
@Documented
29+
public @interface AutoData
30+
{
31+
/**
32+
* 默认为空字符串
33+
* @return 数据
34+
*/
35+
String value() default "";
36+
}

src/main/java/org/suren/autotest/web/framework/annotation/AutoField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* @author suren
3030
* @date 2017年6月7日 下午6:57:34
3131
*/
32-
@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
32+
@Target(ElementType.FIELD)
3333
@Retention(RetentionPolicy.RUNTIME)
3434
@Documented
3535
@Autowired

src/main/java/org/suren/autotest/web/framework/annotation/AutoLocator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@
4040
* @return 定位的具体内容
4141
*/
4242
String value();
43+
44+
/**
45+
* @return 显式的查找超时时间(单位:毫秒)
46+
*/
47+
long timeout() default 0;
4348
}

src/main/java/org/suren/autotest/web/framework/annotation/AutoPage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@
3939
* @return 关联配置路径
4040
*/
4141
String path() default "";
42+
43+
/**
44+
* @return 当前页面的url地址
45+
*/
46+
String url() default "";
4247
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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.core;
18+
19+
/**
20+
* 定位方法枚举
21+
* @author suren
22+
* @date 2017年6月7日 下午7:00:15
23+
*/
24+
public enum LocatorType
25+
{
26+
BY_ID, BY_NAME, BY_XPATH, BY_TAGNAME, BY_CSS,
27+
BY_LINK_TEXT,
28+
BY_PARTIAL_LINK_TEXT;
29+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.invoker;
18+
19+
import org.suren.autotest.web.framework.settings.SettingUtil;
20+
import org.suren.autotest.web.framework.util.ElementUtil;
21+
22+
/**
23+
* 批量操作执行器
24+
* @author suren
25+
* @date 2017年5月15日 上午7:01:27
26+
*/
27+
public class BatchOperationInvoker
28+
{
29+
/**
30+
* 批量操作元素
31+
* @param util
32+
* @param params
33+
*/
34+
public static void execute(SettingUtil util, String[] params)
35+
{
36+
// ElementUtil.click(buttons);
37+
}
38+
}

src/main/java/org/suren/autotest/web/framework/settings/SettingUtil.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@
4646
import org.springframework.beans.BeanUtils;
4747
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
4848
import org.springframework.context.ApplicationContext;
49+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
4950
import org.springframework.context.support.AbstractApplicationContext;
5051
import org.springframework.context.support.ClassPathXmlApplicationContext;
52+
import org.suren.autotest.web.framework.AutoApplication;
53+
import org.suren.autotest.web.framework.annotation.AutoPage;
5154
import org.suren.autotest.web.framework.core.ConfigException;
5255
import org.suren.autotest.web.framework.core.ConfigNotFoundException;
5356
import org.suren.autotest.web.framework.core.Locator;
@@ -64,6 +67,7 @@
6467
import org.suren.autotest.web.framework.hook.ShutdownHook;
6568
import org.suren.autotest.web.framework.page.Page;
6669
import org.suren.autotest.web.framework.selenium.SeleniumEngine;
70+
import org.suren.autotest.web.framework.spring.AutotestScope;
6771
import org.suren.autotest.web.framework.util.BeanUtil;
6872
import org.suren.autotest.web.framework.util.StringUtils;
6973
import org.suren.autotest.web.framework.validation.Validation;
@@ -100,10 +104,18 @@ public SettingUtil()
100104
context = SpringUtils.getApplicationContext();
101105
if(context == null || !((AbstractApplicationContext) context).isActive())
102106
{
103-
context = new ClassPathXmlApplicationContext(new String[]{"classpath*:autoTestContext.xml",
107+
ClassPathXmlApplicationContext xmlContext = new ClassPathXmlApplicationContext(new String[]{"classpath*:autoTestContext.xml",
104108
"classpath*:applicationContext.xml", "classpath*:beanScope.xml"});
109+
110+
context = new AnnotationConfigApplicationContext(AutoApplication.class);
111+
((AnnotationConfigApplicationContext) context).setParent(xmlContext);
112+
113+
((AnnotationConfigApplicationContext) context).getBeanFactory().registerScope("autotest", new AutotestScope());
105114
}
106115

116+
//auto注解扫描
117+
annotationScan();
118+
107119
try
108120
{
109121
//设置页面上下文对象
@@ -136,6 +148,35 @@ public SettingUtil()
136148
logger.info("init process done.");
137149
}
138150

151+
/**
152+
* auto注解扫描
153+
*/
154+
private void annotationScan()
155+
{
156+
Map<String, Object> beanMap = context.getBeansWithAnnotation(AutoPage.class);
157+
beanMap.forEach((name, bean) -> {
158+
if(!(bean instanceof Page)) {
159+
return;
160+
}
161+
162+
String clsName = bean.getClass().getName();
163+
pageMap.put(clsName, (Page) bean);
164+
165+
//属性上的注解处理
166+
fieldAnnotationProcess((Page) bean);
167+
});
168+
}
169+
170+
/**
171+
* 属性上的注解处理
172+
* @param bean Page类
173+
*/
174+
private void fieldAnnotationProcess(Page bean)
175+
{
176+
// TODO Auto-generated method stub
177+
178+
}
179+
139180
/**
140181
* 从本地文件中读取
141182
*

src/main/resources/beanScope.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://www.springframework.org/schema/beans
55
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
6+
<!--
67
<p:bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
78
<p:property name="scopes">
89
<p:map>
@@ -11,4 +12,5 @@
1112
</p:map>
1213
</p:property>
1314
</p:bean>
15+
-->
1416
</p:beans>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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.driver;
18+
//
19+
//import io.appium.java_client.AppiumDriver;
20+
//
21+
//import java.io.File;
22+
//import java.net.MalformedURLException;
23+
//import java.net.URL;
24+
//
25+
//import org.junit.Test;
26+
//import org.openqa.selenium.remote.CapabilityType;
27+
//import org.openqa.selenium.remote.DesiredCapabilities;
28+
//
29+
///**
30+
// * @author suren
31+
// * @date 2017年5月20日 下午5:42:00
32+
// */
33+
//public class AndroidTest
34+
//{
35+
// @Test
36+
// public void test() throws MalformedURLException
37+
// {
38+
// File appFile = new File("D:/suren.apk");
39+
//
40+
// //设置自动化相关参数
41+
// DesiredCapabilities capabilities = new DesiredCapabilities();
42+
// capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
43+
// capabilities.setCapability("platformName", "Android");
44+
// capabilities.setCapability("deviceName", "750BBKP23E75"); //该参数可通过adb命令来获取
45+
//
46+
// //设置安卓系统版本
47+
// capabilities.setCapability("platformVersion", "4.3");
48+
// //设置apk路径
49+
// capabilities.setCapability("app", appFile.getAbsolutePath());
50+
//
51+
// //设置app的主包名和主类名
52+
// capabilities.setCapability("appPackage", "com.example.android.contactmanager");
53+
// capabilities.setCapability("appActivity", ".ContactManager");
54+
//
55+
// //初始化
56+
// AppiumDriver driver = new AppiumDriver(
57+
// new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
58+
//
59+
// System.out.println("started");
60+
//
61+
// driver.quit();
62+
// }
63+
//}

0 commit comments

Comments
 (0)