2323import net .sf .cglib .proxy .MethodProxy ;
2424import org .suren .autotest .web .framework .annotation .AutoExpect ;
2525import org .suren .autotest .web .framework .annotation .AutoModule ;
26+ import org .suren .autotest .web .framework .annotation .AutoSessionStorage ;
27+ import org .suren .autotest .web .framework .core .AutoTestException ;
28+ import org .suren .autotest .web .framework .core .ui .Text ;
29+ import org .suren .autotest .web .framework .page .Page ;
2630import org .suren .autotest .web .framework .report .RecordReportWriter ;
2731import org .suren .autotest .web .framework .report .record .ExceptionRecord ;
2832import org .suren .autotest .web .framework .report .record .NormalRecord ;
2933
34+ import java .lang .reflect .Field ;
3035import java .lang .reflect .Method ;
3136import java .util .List ;
3237
@@ -39,11 +44,13 @@ public class AutoModuleProxy implements MethodInterceptor
3944 private Enhancer enhancer = new Enhancer ();
4045 private Object target ;
4146 private List <RecordReportWriter > recordReportWriters ;
47+ private SettingUtil util ;
4248
43- public AutoModuleProxy (Object target , List <RecordReportWriter > recordReportWriters )
49+ public AutoModuleProxy (Object target , List <RecordReportWriter > recordReportWriters , SettingUtil util )
4450 {
4551 this .target = target ;
4652 this .recordReportWriters = recordReportWriters ;
53+ this .util = util ;
4754 }
4855
4956 public Object getProxy ()
@@ -64,6 +71,7 @@ public Object intercept(Object obj, Method method, Object[] args,
6471 Class <?> superCls = obj .getClass ().getSuperclass ();
6572 AutoModule autoModule = superCls .getAnnotation (AutoModule .class );
6673 AutoExpect autoExpect = method .getAnnotation (AutoExpect .class );
74+ AutoSessionStorage autoSessionStorage = method .getAnnotation (AutoSessionStorage .class );
6775
6876 NormalRecord normalRecord = new NormalRecord ();
6977 normalRecord .setBeginTime (beginTime );
@@ -74,6 +82,32 @@ public Object intercept(Object obj, Method method, Object[] args,
7482
7583 try
7684 {
85+ if (autoSessionStorage != null )
86+ {
87+ Class <? extends Page > accountClz = autoSessionStorage .accountPage ();
88+ String accountNameField = autoSessionStorage .accountName ();
89+
90+ Page page = util .getPage (accountClz );
91+ Field accountField = accountClz .getDeclaredField (accountNameField );
92+
93+ accountField .setAccessible (true );
94+ Object value = accountField .get (page );
95+
96+ if (value instanceof Text )
97+ {
98+ String accountNameValue = ((Text ) value ).getValue ();
99+
100+ System .out .println ("accountNameValue:" + accountNameValue );
101+
102+ loadSessionStorage (accountNameValue );
103+ }
104+ else
105+ {
106+ throw new AutoTestException ("Wrong account type in class: " + accountClz + ", and field : "
107+ + accountNameField + ". It should be Text type." );
108+ }
109+ }
110+
77111 result = methodProxy .invokeSuper (obj , args );
78112
79113 normalRecord .setEndTime (System .currentTimeMillis ());
@@ -103,6 +137,10 @@ public Object intercept(Object obj, Method method, Object[] args,
103137 return result ;
104138 }
105139
140+ private void loadSessionStorage (String accountNameValue )
141+ {
142+ }
143+
106144 /**
107145 * 根据注解配置,是否要对异常进行处理
108146 * @param autoExpect
0 commit comments