Blame view

src/test/java/swing/SwingMain.java 27.5 KB
b914c976   Administrator   init
1
  package swing;

c98c375e   Administrator   all
2
3
4
5
6
7
8
9
10
  

  import java.awt.EventQueue;

  

  import javax.swing.JFrame;

  import javax.swing.ButtonGroup;

  import javax.swing.JButton;

  import java.awt.event.ActionListener;

  import java.io.BufferedReader;

  import java.io.File;

a62053f7   Administrator   add scene
11
12
13
14
  import java.io.FileInputStream;

  import java.io.FileNotFoundException;

  import java.io.FileOutputStream;

  import java.io.IOException;

c98c375e   Administrator   all
15
16
  import java.io.InputStream;

  import java.io.InputStreamReader;

a62053f7   Administrator   add scene
17
18
  import java.io.RandomAccessFile;

  import java.io.StringReader;

c98c375e   Administrator   all
19
20
21
22
  import java.text.SimpleDateFormat;

  import java.util.ArrayList;

  import java.util.Date;

  import java.util.List;

a62053f7   Administrator   add scene
23
24
25
26
  import java.util.Properties;

  import java.util.concurrent.Executors;

  import java.util.concurrent.ScheduledExecutorService;

  import java.util.concurrent.TimeUnit;

c98c375e   Administrator   all
27
28
29
30
  import java.awt.event.ActionEvent;

  import javax.swing.JTextField;

  

  import org.apache.xmlbeans.impl.xb.xsdschema.Public;

a62053f7   Administrator   add scene
31
32
33
34
35
  import org.jdom.Document;

  import org.jdom.Element;

  import org.jdom.JDOMException;

  import org.jdom.input.SAXBuilder;

  import org.jdom.output.XMLOutputter;

c98c375e   Administrator   all
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  import org.testng.TestNG;

  

  import com.essa.framework.BrowserEngine;

  import com.essa.framework.Logger;

  import com.essa.framework.Model;

  import com.essa.pageObject.GoodsManage.AddOriginalGoodsPage;

  import com.essa.pageObject.GoodsManage.GoodsBankPage;

  import com.essa.pageObject.GoodsManage.UpdatePicPage;

  

  import javax.swing.JLabel;

  import javax.swing.JRadioButton;

  import javax.swing.JComboBox;

  import javax.swing.JFileChooser;

  import javax.swing.JScrollPane;

  import javax.swing.JTextArea;

  

  import java.awt.Color;

  import javax.swing.DefaultComboBoxModel;

  import javax.swing.ImageIcon;

  import java.awt.Toolkit;

  import java.awt.BorderLayout;

  import java.awt.Choice;

  import java.awt.Font;

  import java.awt.Graphics;

  

  import javax.swing.JList;

  import javax.swing.JMenuBar;

  import javax.swing.JTextPane;

  import java.awt.event.InputMethodListener;

  import java.awt.event.InputMethodEvent;

  import java.beans.VetoableChangeListener;

  import java.beans.PropertyChangeEvent;

  import javax.swing.JPanel;

  import java.beans.PropertyChangeListener;

  import java.awt.event.MouseAdapter;

  import java.awt.event.MouseEvent;

  import javax.swing.UIManager;

  import java.awt.TextField;

  import java.awt.Panel;

  import javax.swing.JScrollBar;

  import javax.swing.ScrollPaneConstants;

a62053f7   Administrator   add scene
77
  import javax.swing.SwingWorker;

c98c375e   Administrator   all
78
79
80
  import javax.swing.border.LineBorder;

  

  /**

a62053f7   Administrator   add scene
81
   * @author Administrator 图形化

c98c375e   Administrator   all
82
   */

b914c976   Administrator   init
83
  public class SwingMain {

c98c375e   Administrator   all
84
85
86
87
88
89
  

  	private JFrame frmvBy;

  	private JTextField supplierName;

  	private JTextField buyerNo2;

  	public static String no;

  	private JTextField account;

a62053f7   Administrator   add scene
90
  	private JTextArea SkuNo;

c98c375e   Administrator   all
91
92
  	private JTextField password;

  	private JTextField registerAccount;

a62053f7   Administrator   add scene
93
94
  	private JTextArea ja;

  	private JTextField po;

c98c375e   Administrator   all
95
  	

a62053f7   Administrator   add scene
96
97
98
99
  	private String buyerAccount;//采购商账号,存储于配置文件中,记录上一次使用的账号

  	private String supplier;//供应商

  	private String buyerNo;//采购商编号

  

c98c375e   Administrator   all
100
101
102
103
104
105
106
  	/**

  	 * Launch the application.

  	 */

  	public static void main(String[] args) {

  		EventQueue.invokeLater(new Runnable() {

  			public void run() {

  				try {

b914c976   Administrator   init
107
  					SwingMain window = new SwingMain();

c98c375e   Administrator   all
108
109
110
111
112
113
114
115
116
117
118
  					window.frmvBy.setVisible(true);

  				} catch (Exception e) {

  					e.printStackTrace();

  				}

  			}

  		});

  	}

  

  	/**

  	 * Create the application.

  	 */

b914c976   Administrator   init
119
  	public SwingMain() {

c98c375e   Administrator   all
120
  		

a62053f7   Administrator   add scene
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
  		initData();

  		initialize();

  	}

  	

  	/**

  	 * 读取data.xml文件保存的用户使用的数据,用于读取该用户上一次输入的数据

  	 * @throws JDOMException

  	 * @throws IOException

  	 */

  	public void initData() {

  		try {

  			SAXBuilder builder = new SAXBuilder();

  			Document document = builder.build(new File(".\\resources\\data.xml"));

  			Element root = document.getRootElement();

  			Element element = root.getChild("data");

  			this.buyerAccount = element.getChildText("buyerAccount");

  			this.supplier = element.getChildText("supplier");

  			this.buyerNo = element.getChildText("buyerNo");

  		} catch (Exception e) {

  			e.printStackTrace();

  		}

c98c375e   Administrator   all
142
  	}

a62053f7   Administrator   add scene
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  	

  	/**

  	 * 将用户输入过的数据保存在data.xml文件中

  	 * @param key 字段名

  	 * @param value 参数值

  	 * @throws JDOMException

  	 * @throws IOException

  	 */

  	public void setData(String key,String value) {

  		try {

  			SAXBuilder builder = new SAXBuilder();

  			Document document = builder.build(new File(".\\resources\\data.xml"));

  			Element root = document.getRootElement();

  			Element element = root.getChild("data");

  			element.getChild(key).setText(value);

  			XMLOutputter XMLOut = new XMLOutputter();

  			XMLOut.output(document,new FileOutputStream(".\\resources\\data.xml"));

  		} catch (Exception e) {

  			e.printStackTrace();

  		}

  	}

  	

  	/**

  	 * 获取当前时间

  	 * @return

  	 */

  	public String getCurrentTime() {

  		SimpleDateFormat format = new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss] ");

  		Date today = new Date();

  		String time = format.format(today);

  		return time;

c98c375e   Administrator   all
174
175
176
  	}

  

  	/**

a62053f7   Administrator   add scene
177
  	 * frame初始化.

c98c375e   Administrator   all
178
179
180
181
182
  	 */

  	private void initialize() {

  		frmvBy = new JFrame("ESSA自动化测试工具v1.0.0");

  		frmvBy.getContentPane().setBackground(UIManager.getColor("Button.background"));

  		frmvBy.setTitle("ESSA自动化测试工具v1.0.1");

b914c976   Administrator   init
183
  		frmvBy.setIconImage(Toolkit.getDefaultToolkit().getImage(SwingMain.class.getResource("/swing/icon.png")));

c98c375e   Administrator   all
184
185
186
187
188
189
190
191
  		frmvBy.getContentPane().setEnabled(false);

  		frmvBy.setResizable(false);

  		frmvBy.setBackground(UIManager.getColor("Button.background"));

  		frmvBy.setForeground(Color.LIGHT_GRAY);

  		frmvBy.setBounds(650, 350, 526, 467);

  		frmvBy.setSize(686, 405);

  		frmvBy.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  		frmvBy.getContentPane().setLayout(null);

a62053f7   Administrator   add scene
192
193
  

  		//日志

c98c375e   Administrator   all
194
195
196
197
198
  		JScrollPane jsp;

  		ja = new JTextArea();

  		jsp = new JScrollPane(ja);

  		jsp.setBounds(22, 186, 631, 134);

  		frmvBy.getContentPane().add(jsp);

a62053f7   Administrator   add scene
199
  

c98c375e   Administrator   all
200
201
202
203
  		ja.setEditable(false);

  		ja.setWrapStyleWord(true);

  		ja.setLineWrap(true);

  		ja.setFont(new Font("微软雅黑", Font.PLAIN, 13));

a62053f7   Administrator   add scene
204
205
206
  		ja.append(getCurrentTime() + "默认选择场景:新增原厂商品\r\n");

  

  		//操作环境选择

c98c375e   Administrator   all
207
208
209
210
  		JLabel label = new JLabel("操作环境:");

  		label.setBounds(24, 53, 78, 15);

  		label.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		frmvBy.getContentPane().add(label);

a62053f7   Administrator   add scene
211
212
  

  		//加入到购物车场景

c98c375e   Administrator   all
213
214
215
216
217
  		final JPanel ToCart = new JPanel();

  		ToCart.setBounds(231, 42, 230, 128);

  		ToCart.setVisible(false);

  		frmvBy.getContentPane().add(ToCart);

  		ToCart.setLayout(null);

a62053f7   Administrator   add scene
218
219
  

  		//可视化操作选项

c98c375e   Administrator   all
220
221
222
223
  		JLabel label_1 = new JLabel("可视化操作:");

  		label_1.setBounds(10, 119, 88, 15);

  		label_1.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		frmvBy.getContentPane().add(label_1);

a62053f7   Administrator   add scene
224
225
  

  		//可视化

c98c375e   Administrator   all
226
227
228
229
230
  		JRadioButton view = new JRadioButton("是");

  		view.setBounds(103, 115, 42, 23);

  		view.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		view.setSelected(true);

  		frmvBy.getContentPane().add(view);

a62053f7   Administrator   add scene
231
232
  

  		//无头浏览器

c98c375e   Administrator   all
233
234
235
236
237
  		JRadioButton notView = new JRadioButton("否");

  		notView.setBounds(160, 115, 44, 23);

  		notView.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		notView.setEnabled(false);

  		frmvBy.getContentPane().add(notView);

a62053f7   Administrator   add scene
238
  

c98c375e   Administrator   all
239
240
241
  		ButtonGroup group = new ButtonGroup();

  		group.add(view);

  		group.add(notView);

a62053f7   Administrator   add scene
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
  

  		//po询价场景

  		final JPanel POInquiry = new JPanel();

  		POInquiry.setBounds(231, 42, 234, 134);

  		frmvBy.getContentPane().add(POInquiry);

  		POInquiry.setVisible(false);

  		POInquiry.setLayout(null);

  

  		// po单号字段

  		JLabel POnum = new JLabel("PO单号:");

  		POnum.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		POnum.setBounds(25, 5, 68, 25);

  		POInquiry.add(POnum);

  

  		// po单号文本值

  		po = new JTextField();

  		po.setBounds(90, 6, 110, 25);

  		POInquiry.add(po);

  		po.setColumns(10);

  		

  		//必填文本

  		JLabel lblNewLabel = new JLabel("*必填");

  		lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 12));

  		lblNewLabel.setForeground(Color.RED);

  		lblNewLabel.setBounds(200, 10, 44, 15);

  		POInquiry.add(lblNewLabel);

  

  		//右侧流程介绍文本

c98c375e   Administrator   all
270
271
272
273
  		final JLabel process = new JLabel();

  		process.setBounds(474, 25, 179, 170);

  		process.setForeground(Color.GRAY);

  		process.setFont(new Font("微软雅黑", Font.PLAIN, 12));

a62053f7   Administrator   add scene
274
275
  		process.setText(

  				"<html><body>新增原厂商品场景流程:<br>1.商品建档<br>2.更新商品图片<br>3.审核商品<br>4.检查商品库,验证是否新增成功<br>PS:以上均由账号(linxun)操作<br><br></body></html>");

c98c375e   Administrator   all
276
  		frmvBy.getContentPane().add(process);

a62053f7   Administrator   add scene
277
278
  

  		//操作场景

c98c375e   Administrator   all
279
280
281
282
  		JLabel label_2 = new JLabel("操作场景:");

  		label_2.setBounds(24, 87, 78, 15);

  		label_2.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		frmvBy.getContentPane().add(label_2);

a62053f7   Administrator   add scene
283
284
  

  		//新增原厂商品场景

c98c375e   Administrator   all
285
286
287
288
289
  		final JPanel addOriginal = new JPanel();

  		addOriginal.setBounds(231, 37, 234, 134);

  		addOriginal.setVisible(true);

  		frmvBy.getContentPane().add(addOriginal);

  		addOriginal.setLayout(null);

a62053f7   Administrator   add scene
290
291
  

  		//场景选择,插入对应的值,并打印在日志上

c98c375e   Administrator   all
292
293
294
295
  		final JComboBox selectSystem = new JComboBox<String>();

  		selectSystem.setBounds(102, 51, 114, 20);

  		selectSystem.addActionListener(new ActionListener() {

  			public void actionPerformed(ActionEvent e) {

a62053f7   Administrator   add scene
296
  				if ("SIT".equals((String) selectSystem.getSelectedItem())) {

c98c375e   Administrator   all
297
  					Model.setEnv("SIT");

a62053f7   Administrator   add scene
298
299
  					ja.append(getCurrentTime() + "已选择环境:SIT\r\n");

  				} else if ("DIT".equals((String) selectSystem.getSelectedItem())) {

c98c375e   Administrator   all
300
  					Model.setEnv("DIT");

a62053f7   Administrator   add scene
301
302
  					ja.append(getCurrentTime() + "已选择环境:DIT\r\n");

  				} else if ("HOTFIX".equals((String) selectSystem.getSelectedItem())) {

c98c375e   Administrator   all
303
  					Model.setEnv("HOTFIX");

a62053f7   Administrator   add scene
304
305
  					ja.append(getCurrentTime() + "已选择环境:HOTFIX\r\n");

  				} else if ("UAT".equals((String) selectSystem.getSelectedItem())) {

c98c375e   Administrator   all
306
  					Model.setEnv("UAT");

a62053f7   Administrator   add scene
307
  					ja.append(getCurrentTime() + "已选择环境:UAT\r\n");

c98c375e   Administrator   all
308
  				}

c98c375e   Administrator   all
309
310
311
312
313
314
315
316
  			}

  		});

  		selectSystem.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		selectSystem.addItem("SIT");

  		selectSystem.addItem("HOTFIX");

  		selectSystem.addItem("UAT");

  		selectSystem.addItem("DIT");

  		frmvBy.getContentPane().add(selectSystem);

a62053f7   Administrator   add scene
317
318
  

  		//添加市场商品

c98c375e   Administrator   all
319
320
321
322
323
324
  		final JPanel addMarket = new JPanel();

  		addMarket.setBounds(0, 67, 230, 46);

  		addOriginal.add(addMarket);

  		addMarket.setVisible(false);

  		addMarket.setLayout(null);

  		

a62053f7   Administrator   add scene
325
326
327
328
329
330
  		//采购商注册

  		final JPanel register = new JPanel();

  		register.setBounds(231, 42, 224, 134);

  		frmvBy.getContentPane().add(register);

  

  		//浏览器选择

c98c375e   Administrator   all
331
332
333
334
  		final JComboBox browser = new JComboBox();

  		browser.setEnabled(false);

  		browser.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		browser.setBounds(102, 147, 114, 20);

a62053f7   Administrator   add scene
335
  		browser.setModel(new DefaultComboBoxModel(new String[] { "Chrome", "Firefox", "IE" }));

c98c375e   Administrator   all
336
337
  		frmvBy.getContentPane().add(browser);

  		

a62053f7   Administrator   add scene
338
  		//场景选择,根据随选场景做对应的交互

c98c375e   Administrator   all
339
340
341
342
343
344
  		final JComboBox selectScene = new JComboBox();

  		selectScene.setBounds(102, 85, 114, 20);

  		selectScene.setForeground(Color.BLACK);

  		selectScene.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		selectScene.addActionListener(new ActionListener() {

  			public void actionPerformed(ActionEvent e) {

a62053f7   Administrator   add scene
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
  				//此处为默认将所有的场景视图先隐藏,后续根据所选场景显示对应的视图

  				addOriginal.setVisible(false);

  				addMarket.setVisible(false);

  				ToCart.setVisible(false);

  				POInquiry.setVisible(false);

  				register.setVisible(false);

  				if ("新增原厂商品".equals((String) selectScene.getSelectedItem())) {

  					process.setText(

  							"<html><body>新增原厂商品场景流程:<br>1.商品建档<br>2.更新商品图片<br>3.审核商品<br>4.检查商品库,验证是否新增成功<br>PS:以上均由账号(linxun)操作<br><br></body></html>");

  					addOriginal.setVisible(true);

  					ja.append(getCurrentTime() + "已选择场景:新增原厂商品\r\n");

  				} else if ("新增市场商品".equals((String) selectScene.getSelectedItem())) {

  					process.setText("<html><body>新增市场商品场景流程:<br>" + "1.指定采购商编号(默认:RUS00833)<br>"

  							+ "2.使用账号(maomeixiang)对指定采购商进行市场商品建档并选择审核人为\"邢昌勇\"<br>"

  							+ "3.使用账号(xingchangyong)对市场商品审核<br></body></html>");

c98c375e   Administrator   all
360
  					addOriginal.setVisible(true);

c98c375e   Administrator   all
361
  					addMarket.setVisible(true);

a62053f7   Administrator   add scene
362
363
364
365
366
  					ja.append(getCurrentTime() + "已选择场景:新增市场商品\r\n");

  				} else if ("发布团购".equals((String) selectScene.getSelectedItem())) {

  					ja.append(getCurrentTime() + "已选择场景:发布团购,运行过程中将会打开关闭浏览器2次!\r\n");

  					process.setText(

  							"<html><body>发布团购场景流程:<br><font color=\"red\">1.先执行新增原厂商品流程,生成一个原厂SKU</font><br>2.使用账号(linrong)为新增的SKU分配类目经理<br>3.团购设置中添加该SKU,并发布团购,验证团购发布结果</body></html>");

c98c375e   Administrator   all
367
  					addOriginal.setVisible(true);

a62053f7   Administrator   add scene
368
369
370
371
372
373
  				} else if ("采购商注册".equals((String) selectScene.getSelectedItem())) {

  					register.setVisible(true);

  					ja.append(getCurrentTime() + "已选择场景:采购商注册,运行过程中将会打开关闭浏览器2次!\r\n");

  					process.setText(

  							"<html><body>采购商注册流程:<br>1.使用账号(admin)在bpms后台生成一个邀请码<br>2.采购商平台填写注册信息,并填入上一步生成的邀请码<br>PS:新账号密码默认为:essa123<br><br><br></body></html>");

  				} else if ("添加SKU至购物车".equals((String) selectScene.getSelectedItem())) {

c98c375e   Administrator   all
374
  					ToCart.setVisible(true);

a62053f7   Administrator   add scene
375
376
377
378
  					ja.append(getCurrentTime() + "已选择场景:添加SKU至购物车\r\n");

  					process.setText(

  							"<html><body>添加SKU至购物车流程:<br>1.Buyer平台根据填入的采购<br>商信息进行登录操作<br>2.若未填写商品编号,将从数<br>据库随机查出一个符合要求的<br>sku添加至购物车<br><br><br></body></html>");

  				} else if ("成品询价".equals((String) selectScene.getSelectedItem())) {

c98c375e   Administrator   all
379
  					ToCart.setVisible(true);

a62053f7   Administrator   add scene
380
381
382
383
  					ja.append(getCurrentTime() + "已选择场景:成品询价,将重启浏览器多次\r\n");

  					process.setText(

  							"<html><body>成品询价流程:<br>1.Buyer平台根据填入的采购<br>商信息加入sku,若未填写sku<br>编号,将随机从数据库获取符<br>合要求的sku<br>2.bpms后台登录账号(chenhong)对该sku进行成<br>品询价审核<br></body></html>");

  				} else if ("生成PO".equals((String) selectScene.getSelectedItem())) {

c98c375e   Administrator   all
384
  					ToCart.setVisible(true);

a62053f7   Administrator   add scene
385
386
387
388
389
390
391
  					ja.append(getCurrentTime() + "已选择场景:生成PO,将重启浏览器多次\r\n");

  					process.setText(

  							"<html><body>生成PO流程:<br>1.采购商平台加入商品至购物车<br>2.bpms后台登录账号(chenhong)对该sku进行成品询价审核<br>3.再次登录采购商平台,进行拼柜、设置唛头、贴纸和提交PO操作</body></html>");

  				} else if ("PO询价".equals((String) selectScene.getSelectedItem())) {

  					POInquiry.setVisible(true);

  					ja.append(getCurrentTime() + "已选择场景:PO询价\r\n");

  					process.setText("<html><body>PO询价使用介绍:<br>1.填入需要询价的PO单号<br>2.工具将对该PO单号循环进行询价,直到所有商品均询价完成<br>3.如果运行过程中出现询价异常等弹框,手工关闭弹窗后脚本仍会继续执行之后的操作</body></html>");

c98c375e   Administrator   all
392
393
394
  				}

  			}

  		});

a62053f7   Administrator   add scene
395
396
  		selectScene.setModel(

  				new DefaultComboBoxModel(new String[] { "新增原厂商品", "新增市场商品", "发布团购", "采购商注册", "成品询价", "生成PO", "PO询价" }));

c98c375e   Administrator   all
397
  		frmvBy.getContentPane().add(selectScene);

a62053f7   Administrator   add scene
398
  

c98c375e   Administrator   all
399
400
401
402
  		JLabel label_3 = new JLabel("供应商名称:");

  		label_3.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		label_3.setBounds(9, 15, 91, 15);

  		addOriginal.add(label_3);

a62053f7   Administrator   add scene
403
404
  

  		//供应商名称

c98c375e   Administrator   all
405
406
407
408
409
  		supplierName = new JTextField();

  		supplierName.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		supplierName.setForeground(Color.BLACK);

  		supplierName.setBounds(92, 10, 114, 25);

  		addOriginal.add(supplierName);

a62053f7   Administrator   add scene
410
  		supplierName.setText(supplier);

c98c375e   Administrator   all
411
  		supplierName.setColumns(10);

a62053f7   Administrator   add scene
412
413
  

  		//选择图片

c98c375e   Administrator   all
414
415
416
417
  		JButton button = new JButton("选择图片");

  		button.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		button.setBounds(91, 44, 91, 23);

  		addOriginal.add(button);

a62053f7   Administrator   add scene
418
  

c98c375e   Administrator   all
419
420
421
422
  		JLabel lblSku = new JLabel("商品图片:");

  		lblSku.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		lblSku.setBounds(22, 48, 70, 15);

  		addOriginal.add(lblSku);

a62053f7   Administrator   add scene
423
  

c98c375e   Administrator   all
424
425
426
427
428
  		final JLabel label_7 = new JLabel("*必填");

  		label_7.setFont(new Font("微软雅黑", Font.PLAIN, 12));

  		label_7.setBounds(192, 48, 42, 15);

  		addOriginal.add(label_7);

  		label_7.setForeground(Color.RED);

a62053f7   Administrator   add scene
429
430
  

  		//图片地址

c98c375e   Administrator   all
431
432
433
  		final JLabel picPath = new JLabel("");

  		picPath.setVisible(false);

  		addOriginal.add(picPath);

a62053f7   Administrator   add scene
434
  

c98c375e   Administrator   all
435
436
437
438
  		JLabel label_5 = new JLabel("采购商编号:");

  		label_5.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		label_5.setBounds(8, 15, 86, 15);

  		addMarket.add(label_5);

a62053f7   Administrator   add scene
439
440
  

  		//采购商编号

c98c375e   Administrator   all
441
442
443
444
  		buyerNo2 = new JTextField();

  		buyerNo2.setBounds(93, 11, 114, 25);

  		addMarket.add(buyerNo2);

  		buyerNo2.setFont(new Font("宋体", Font.PLAIN, 14));

a62053f7   Administrator   add scene
445
  		buyerNo2.setText(buyerNo);

c98c375e   Administrator   all
446
  		buyerNo2.setColumns(10);

a62053f7   Administrator   add scene
447
448
  

  		//选择图片按钮

c98c375e   Administrator   all
449
450
451
  		button.addActionListener(new ActionListener() {

  			public void actionPerformed(ActionEvent e) {

  				JFileChooser jf = new JFileChooser();

a62053f7   Administrator   add scene
452
  				jf.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

c98c375e   Administrator   all
453
  				jf.showDialog(new JLabel(), "选择图片");

a62053f7   Administrator   add scene
454
  				File file = jf.getSelectedFile();

c98c375e   Administrator   all
455
456
457
458
459
  				String s = null;

  				try {

  					s = file.getAbsolutePath();

  				} catch (NullPointerException exception) {

  				}

a62053f7   Administrator   add scene
460
461
462
463
  				if (s == "" || s == null) {

  					ja.append(getCurrentTime() + "您未选择图片,请选择图片\r\n");

  				} else {

  					ja.append(getCurrentTime() + "选择的图片为:" + s + "\r\n");

c98c375e   Administrator   all
464
465
466
467
468
  					picPath.setText(s);

  					label_7.setText("已选");

  				}

  			}

  		});

a62053f7   Administrator   add scene
469
  

c98c375e   Administrator   all
470
471
472
473
  		JLabel label_4 = new JLabel("浏览器:");

  		label_4.setBounds(38, 149, 62, 15);

  		label_4.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		frmvBy.getContentPane().add(label_4);

a62053f7   Administrator   add scene
474
475
  

  		//开始按钮

c98c375e   Administrator   all
476
477
478
479
480
  		JButton btnNewButton = new JButton("开 始");

  		btnNewButton.setBounds(551, 325, 101, 35);

  		frmvBy.getContentPane().add(btnNewButton);

  		btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 17));

  

c98c375e   Administrator   all
481
482
483
484
  		JLabel lblEssav = new JLabel("ESSA自动化测试工具 V1.0.1");

  		lblEssav.setBounds(225, 10, 228, 29);

  		lblEssav.setFont(new Font("微软雅黑", Font.BOLD, 16));

  		frmvBy.getContentPane().add(lblEssav);

a62053f7   Administrator   add scene
485
486
487
  

  		JLabel lblwindowsjdkbug = new JLabel(

  				"<html><body>提示:1.建议使用版本号为68.0的Chrome浏览器<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.由于部分操作会用到鼠标事件,若运行时手动切换界面可能会导致运行出错</body></html>");

c98c375e   Administrator   all
488
489
490
  		lblwindowsjdkbug.setFont(new Font("微软雅黑", Font.PLAIN, 12));

  		lblwindowsjdkbug.setBounds(25, 323, 456, 40);

  		frmvBy.getContentPane().add(lblwindowsjdkbug);

a62053f7   Administrator   add scene
491
  

c98c375e   Administrator   all
492
493
494
495
  		JLabel Account = new JLabel("采购商账号:");

  		Account.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		Account.setBounds(9, 10, 88, 15);

  		ToCart.add(Account);

a62053f7   Administrator   add scene
496
  

c98c375e   Administrator   all
497
498
499
500
  		JLabel Password = new JLabel("密码:");

  		Password.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		Password.setBounds(50, 41, 65, 15);

  		ToCart.add(Password);

a62053f7   Administrator   add scene
501
  

c98c375e   Administrator   all
502
503
  		JLabel No = new JLabel("商品编号:");

  		No.setFont(new Font("微软雅黑", Font.PLAIN, 14));

a62053f7   Administrator   add scene
504
  		No.setBounds(22, 100, 88, 15);

c98c375e   Administrator   all
505
  		ToCart.add(No);

a62053f7   Administrator   add scene
506
  

c98c375e   Administrator   all
507
  		account = new JTextField();

a62053f7   Administrator   add scene
508
  		account.setText(buyerAccount);

c98c375e   Administrator   all
509
510
511
512
  		account.setFont(new Font("微软雅黑", Font.PLAIN, 12));

  		account.setBounds(92, 4, 130, 25);

  		ToCart.add(account);

  		account.setColumns(10);

a62053f7   Administrator   add scene
513
  

c98c375e   Administrator   all
514
515
516
517
518
519
520
  		password = new JTextField();

  		password.setText("essa123");

  		password.setToolTipText("");

  		password.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		password.setBounds(92, 37, 130, 25);

  		ToCart.add(password);

  		password.setColumns(10);

a62053f7   Administrator   add scene
521
522
523
524
  

  		//sku编号

  		SkuNo = new JTextArea();

  		SkuNo.setText("选填,勿填活动商品");

c98c375e   Administrator   all
525
  		SkuNo.setForeground(Color.LIGHT_GRAY);

a62053f7   Administrator   add scene
526
527
  		SkuNo.setFont(new Font("微软雅黑", Font.PLAIN, 12));

  		SkuNo.setLineWrap(true);

c98c375e   Administrator   all
528
529
530
  		SkuNo.addMouseListener(new MouseAdapter() {

  			@Override

  			public void mouseClicked(MouseEvent e) {

a62053f7   Administrator   add scene
531
  				if (SkuNo.getText().equals("选填,勿填活动商品") || SkuNo.getText().equals("选填,勿填非活动商品")  ) {

c98c375e   Administrator   all
532
533
534
535
536
  					SkuNo.setForeground(Color.black);

  					SkuNo.setText("");

  				}

  			}

  		});

a62053f7   Administrator   add scene
537
538
  		SkuNo.setBounds(92, 100, 130, 25);

  		SkuNo.setBorder(new LineBorder(new java.awt.Color(127,157,185), 1, false));

c98c375e   Administrator   all
539
540
541
  		ToCart.add(SkuNo);

  		SkuNo.setColumns(10);

  		

a62053f7   Administrator   add scene
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
  		//商品类型

  		JLabel kind = new JLabel("商品类型:");

  		kind.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		kind.setBounds(22, 75, 70, 15);

  		ToCart.add(kind);

  		

  		//非活动商品

  		JRadioButton notActivity = new JRadioButton("非活动");

  		notActivity.addActionListener(new ActionListener() {

  			public void actionPerformed(ActionEvent arg0) {

  				Model.setIsactivity(0);

  				SkuNo.setText("选填,勿填活动商品");

  			}

  		});

  		notActivity.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		notActivity.setBounds(92, 71, 70, 23);

  		ToCart.add(notActivity);

c98c375e   Administrator   all
559
  		

a62053f7   Administrator   add scene
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
  		//活动商品

  		JRadioButton isActivity = new JRadioButton("活动");

  		isActivity.addActionListener(new ActionListener() {

  			public void actionPerformed(ActionEvent e) {

  				Model.setIsactivity(1);

  				SkuNo.setText("选填,勿填非活动商品");

  			}

  		});

  		isActivity.setFont(new Font("微软雅黑", Font.PLAIN, 14));

  		isActivity.setBounds(165, 71, 64, 23);

  		ToCart.add(isActivity);

  		

  		//活动和非活动单选

  		ButtonGroup group1 = new ButtonGroup();

  		group1.add(notActivity);

  		group1.add(isActivity);

  		notActivity.setSelected(true);

  

c98c375e   Administrator   all
578
579
580
  		JLabel RegisterAccount = new JLabel("采购商邮箱:");

  		register.add(RegisterAccount);

  		RegisterAccount.setFont(new Font("微软雅黑", Font.PLAIN, 14));

a62053f7   Administrator   add scene
581
  

c98c375e   Administrator   all
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
  		registerAccount = new JTextField();

  		registerAccount.setForeground(Color.LIGHT_GRAY);

  		registerAccount.setText("若不填写将自动生成");

  		registerAccount.addMouseListener(new MouseAdapter() {

  			@Override

  			public void mouseClicked(MouseEvent e) {

  				if (registerAccount.getText().equals("若不填写将自动生成")) {

  					registerAccount.setForeground(Color.black);

  					registerAccount.setText("");

  				}

  			}

  		});

  		register.add(registerAccount);

  		registerAccount.setFont(new Font("微软雅黑", Font.PLAIN, 13));

  		registerAccount.setColumns(10);

  

c98c375e   Administrator   all
598
599
  		btnNewButton.addActionListener(new ActionListener() {

  			public void actionPerformed(ActionEvent e) {

a62053f7   Administrator   add scene
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
  				SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {// 加入线程

  

  					@Override

  					protected Void doInBackground() throws Exception {

  						String Environment = (String) selectSystem.getSelectedItem();

  						String Scene = (String) selectScene.getSelectedItem();

  						String Browser = (String) browser.getSelectedItem();

  						//记录用户输入的数据,下次读取

  						setData("supplier", supplierName.getText());

  						setData("buyerNo", buyerNo2.getText());

  						setData("buyerAccount", account.getText());

  						ja.append(getCurrentTime() + "程序正在启动中……切勿双击【开始】\r\n");

  						BrowserEngine.setInit(Environment, Browser);

  						TestNG testNG = new TestNG();

  						List<String> suites = new ArrayList<String>();

  						if (Scene == "新增原厂商品") {

  							AddOriginalGoodsPage.setSupplierName(supplierName.getText());

  							UpdatePicPage.setPicPath(picPath.getText());

  							suites.add(".\\resources\\suites\\addOriginalGoods.xml");// 图形界面

  						} else if (Scene == "新增市场商品") {

  							Model.setBuyerNo(buyerNo2.getText());

  							Model.setPicPath(picPath.getText());

  							Model.setSupplierName(supplierName.getText());

  							suites.add(".\\resources\\suites\\addMarketGoods.xml");// 图形界面

  						} else if (Scene == "发布团购") {

  							AddOriginalGoodsPage.setSupplierName(supplierName.getText());

  							UpdatePicPage.setPicPath(picPath.getText());

  							suites.add(".\\resources\\suites\\publishGroupPurchase.xml");// 图形界面

  						} else if (Scene == "采购商注册") {

  							if (!(registerAccount.getText().equals("")

  									|| registerAccount.getText().equals("若不填写将自动生成"))) {

  								Model.setEmail(registerAccount.getText());

  							}

  							suites.add(".\\resources\\suites\\buyerRegister.xml");// 图形界面

  						} else if (Scene == "添加SKU至购物车") {// 暂时舍弃

  							Model.setBuyerAccount(account.getText());

  							Model.setBuyerPassword(password.getText());

  							Model.setSkuNo(SkuNo.getText());

  							suites.add(".\\resources\\suites\\addSkuToCart.xml");

  						} else if (Scene == "成品询价") {

  							Model.setBuyerAccount(account.getText());

  							Model.setBuyerPassword(password.getText());

  							Model.setSkuNo(SkuNo.getText());

  							if (Model.getIsactivity() == 1) {

  								suites.add(".\\resources\\suites\\activityInquiry.xml");

  							}else {

  								suites.add(".\\resources\\suites\\productInquiry.xml");

  							}

  						} else if (Scene == "生成PO") {

  							Model.setBuyerAccount(account.getText());

  							Model.setBuyerPassword(password.getText());

  							Model.setSkuNo(SkuNo.getText());

  							if (Model.getIsactivity() == 1) {

  								suites.add(".\\resources\\suites\\activitySendPO.xml");

  							}else {

  								suites.add(".\\resources\\suites\\sendPO.xml");

  							}

  						} else if (Scene == "PO询价") {

  							Model.setPoNum(po.getText());

  							suites.add(".\\resources\\suites\\POInquiry.xml");

  						}

  						testNG.setTestSuites(suites);

  						testNG.run();

  						ja.append(getCurrentTime() + "=======" + Scene + "场景,执行完毕!=======\r\n");

  						if (Scene == "新增原厂商品" || Scene == "新增市场商品" || Scene == "发布团购") {

  							no = Model.getSkuNo();

  							if (no != null) {

  								ja.append(getCurrentTime() + "SKU商品编号:" + no + "\r\n");

  							} else {

  								ja.append(getCurrentTime()

  										+ "程序执行失败了!\r\n你可查看目录中test-output/index.html的测试报告,或者查看Log中的执行日志检查原因\r\n");

  							}

  						} else if (Scene == "采购商注册") {

  							String code = Model.getInvateCode();

  							String email = Model.getEmail();

  							if (code != null && email != null) {

  								ja.append(getCurrentTime() + "生成的邀请码:" + Model.getInvateCode() + "\r\n");

  								ja.append(getCurrentTime() + "新采购商邮箱:" + Model.getEmail() + "\r\n");

  							} else {

  								ja.append(getCurrentTime()

  										+ "程序执行失败了!\r\n你可以分析目录中test-output/index.html的测试报告,或者查看目录中Log文件夹生成的执行日志\r\n");

  							}

  						} else if (Scene == "添加SKU至购物车") {

  							ja.append(getCurrentTime() + "所选采购商账号:" + Model.getBuyerAccount() + "\r\n");

  							ja.append(getCurrentTime() + "添加的SKU编号为:" + Model.getSkuNo() + "\r\n");

  						} else if (Scene == "成品询价") {

  							ja.append(getCurrentTime() + "采购商账号:" + Model.getBuyerAccount() + "\r\n");

  							ja.append(getCurrentTime() + "SKU编号:" + Model.getSkuNo() + "\r\n");

  						} else if (Scene == "生成PO") {

  							ja.append(getCurrentTime() + "采购商账号:" + Model.getBuyerAccount() + "\r\n");

  							ja.append(getCurrentTime() + "PO单号:" + Model.getPoNum() + "\r\n");

  						}

  						return null;

c98c375e   Administrator   all
693
  					}

a62053f7   Administrator   add scene
694
695
696
  				};

  				worker.execute();

  

c98c375e   Administrator   all
697
698
  			}

  		});

a62053f7   Administrator   add scene
699
  

c98c375e   Administrator   all
700
701
  	}

  }