SwingMain.java
26.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
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
693
694
695
696
697
698
699
700
701
package swing;
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;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.io.StringReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
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;
import javax.swing.SwingWorker;
import javax.swing.border.LineBorder;
/**
* @author Administrator 图形化
*/
public class SwingMain {
private JFrame frmvBy;
private JTextField supplierName;
private JTextField buyerNo2;
public static String no;
private JTextField account;
private JTextArea SkuNo;
private JTextField password;
private JTextField registerAccount;
private JTextArea ja;
private JTextField po;
private String buyerAccount;//采购商账号,存储于配置文件中,记录上一次使用的账号
private String supplier;//供应商
private String buyerNo;//采购商编号
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SwingMain window = new SwingMain();
window.frmvBy.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public SwingMain() {
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();
}
}
/**
* 将用户输入过的数据保存在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;
}
/**
* frame初始化.
*/
private void initialize() {
frmvBy = new JFrame("ESSA自动化测试工具v1.0.0");
frmvBy.getContentPane().setBackground(UIManager.getColor("Button.background"));
frmvBy.setTitle("ESSA自动化测试工具v1.0.1");
frmvBy.setIconImage(Toolkit.getDefaultToolkit().getImage(SwingMain.class.getResource("/swing/icon.png")));
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);
//日志
JScrollPane jsp;
ja = new JTextArea();
jsp = new JScrollPane(ja);
jsp.setBounds(22, 186, 631, 134);
frmvBy.getContentPane().add(jsp);
ja.setEditable(false);
ja.setWrapStyleWord(true);
ja.setLineWrap(true);
ja.setFont(new Font("微软雅黑", Font.PLAIN, 13));
ja.append(getCurrentTime() + "默认选择场景:新增原厂商品\r\n");
//操作环境选择
JLabel label = new JLabel("操作环境:");
label.setBounds(24, 53, 78, 15);
label.setFont(new Font("微软雅黑", Font.PLAIN, 14));
frmvBy.getContentPane().add(label);
//加入到购物车场景
final JPanel ToCart = new JPanel();
ToCart.setBounds(231, 42, 230, 128);
ToCart.setVisible(false);
frmvBy.getContentPane().add(ToCart);
ToCart.setLayout(null);
//可视化操作选项
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);
//可视化
JRadioButton view = new JRadioButton("是");
view.setBounds(103, 115, 42, 23);
view.setFont(new Font("微软雅黑", Font.PLAIN, 14));
view.setSelected(true);
frmvBy.getContentPane().add(view);
//无头浏览器
JRadioButton notView = new JRadioButton("否");
notView.setBounds(160, 115, 44, 23);
notView.setFont(new Font("微软雅黑", Font.PLAIN, 14));
notView.setEnabled(false);
frmvBy.getContentPane().add(notView);
ButtonGroup group = new ButtonGroup();
group.add(view);
group.add(notView);
//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);
//右侧流程介绍文本
final JLabel process = new JLabel();
process.setBounds(474, 25, 179, 170);
process.setForeground(Color.GRAY);
process.setFont(new Font("微软雅黑", Font.PLAIN, 12));
process.setText(
"<html><body>新增原厂商品场景流程:<br>1.商品建档<br>2.更新商品图片<br>3.审核商品<br>4.检查商品库,验证是否新增成功<br>PS:以上均由账号(linxun)操作<br><br></body></html>");
frmvBy.getContentPane().add(process);
//操作场景
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);
//新增原厂商品场景
final JPanel addOriginal = new JPanel();
addOriginal.setBounds(231, 37, 234, 134);
addOriginal.setVisible(true);
frmvBy.getContentPane().add(addOriginal);
addOriginal.setLayout(null);
//场景选择,插入对应的值,并打印在日志上
final JComboBox selectSystem = new JComboBox<String>();
selectSystem.setBounds(102, 51, 114, 20);
selectSystem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if ("SIT".equals((String) selectSystem.getSelectedItem())) {
Model.setEnv("SIT");
ja.append(getCurrentTime() + "已选择环境:SIT\r\n");
} else if ("DIT".equals((String) selectSystem.getSelectedItem())) {
Model.setEnv("DIT");
ja.append(getCurrentTime() + "已选择环境:DIT\r\n");
} else if ("HOTFIX".equals((String) selectSystem.getSelectedItem())) {
Model.setEnv("HOTFIX");
ja.append(getCurrentTime() + "已选择环境:HOTFIX\r\n");
} else if ("UAT".equals((String) selectSystem.getSelectedItem())) {
Model.setEnv("UAT");
ja.append(getCurrentTime() + "已选择环境:UAT\r\n");
}
}
});
selectSystem.setFont(new Font("微软雅黑", Font.PLAIN, 14));
selectSystem.addItem("SIT");
selectSystem.addItem("HOTFIX");
selectSystem.addItem("UAT");
selectSystem.addItem("DIT");
frmvBy.getContentPane().add(selectSystem);
//添加市场商品
final JPanel addMarket = new JPanel();
addMarket.setBounds(0, 67, 230, 46);
addOriginal.add(addMarket);
addMarket.setVisible(false);
addMarket.setLayout(null);
//采购商注册
final JPanel register = new JPanel();
register.setBounds(231, 42, 224, 134);
frmvBy.getContentPane().add(register);
//浏览器选择
final JComboBox browser = new JComboBox();
browser.setEnabled(false);
browser.setFont(new Font("微软雅黑", Font.PLAIN, 14));
browser.setBounds(102, 147, 114, 20);
browser.setModel(new DefaultComboBoxModel(new String[] { "Chrome", "Firefox", "IE" }));
frmvBy.getContentPane().add(browser);
//场景选择,根据随选场景做对应的交互
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) {
//此处为默认将所有的场景视图先隐藏,后续根据所选场景显示对应的视图
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>");
addOriginal.setVisible(true);
addMarket.setVisible(true);
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>");
addOriginal.setVisible(true);
} 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())) {
ToCart.setVisible(true);
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())) {
ToCart.setVisible(true);
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())) {
ToCart.setVisible(true);
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>");
}
}
});
selectScene.setModel(
new DefaultComboBoxModel(new String[] { "新增原厂商品", "新增市场商品", "发布团购", "采购商注册", "成品询价", "生成PO", "PO询价" }));
frmvBy.getContentPane().add(selectScene);
JLabel label_3 = new JLabel("供应商名称:");
label_3.setFont(new Font("微软雅黑", Font.PLAIN, 14));
label_3.setBounds(9, 15, 91, 15);
addOriginal.add(label_3);
//供应商名称
supplierName = new JTextField();
supplierName.setFont(new Font("微软雅黑", Font.PLAIN, 14));
supplierName.setForeground(Color.BLACK);
supplierName.setBounds(92, 10, 114, 25);
addOriginal.add(supplierName);
supplierName.setText(supplier);
supplierName.setColumns(10);
//选择图片
JButton button = new JButton("选择图片");
button.setFont(new Font("微软雅黑", Font.PLAIN, 14));
button.setBounds(91, 44, 91, 23);
addOriginal.add(button);
JLabel lblSku = new JLabel("商品图片:");
lblSku.setFont(new Font("微软雅黑", Font.PLAIN, 14));
lblSku.setBounds(22, 48, 70, 15);
addOriginal.add(lblSku);
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);
//图片地址
final JLabel picPath = new JLabel("");
picPath.setVisible(false);
addOriginal.add(picPath);
JLabel label_5 = new JLabel("采购商编号:");
label_5.setFont(new Font("微软雅黑", Font.PLAIN, 14));
label_5.setBounds(8, 15, 86, 15);
addMarket.add(label_5);
//采购商编号
buyerNo2 = new JTextField();
buyerNo2.setBounds(93, 11, 114, 25);
addMarket.add(buyerNo2);
buyerNo2.setFont(new Font("宋体", Font.PLAIN, 14));
buyerNo2.setText(buyerNo);
buyerNo2.setColumns(10);
//选择图片按钮
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser jf = new JFileChooser();
jf.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
jf.showDialog(new JLabel(), "选择图片");
File file = jf.getSelectedFile();
String s = null;
try {
s = file.getAbsolutePath();
} catch (NullPointerException exception) {
}
if (s == "" || s == null) {
ja.append(getCurrentTime() + "您未选择图片,请选择图片\r\n");
} else {
ja.append(getCurrentTime() + "选择的图片为:" + s + "\r\n");
picPath.setText(s);
label_7.setText("已选");
}
}
});
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);
//开始按钮
JButton btnNewButton = new JButton("开 始");
btnNewButton.setBounds(551, 325, 101, 35);
frmvBy.getContentPane().add(btnNewButton);
btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 17));
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);
JLabel lblwindowsjdkbug = new JLabel(
"<html><body>提示:1.建议使用版本号为68.0的Chrome浏览器<br> 2.由于部分操作会用到鼠标事件,若运行时手动切换界面可能会导致运行出错</body></html>");
lblwindowsjdkbug.setFont(new Font("微软雅黑", Font.PLAIN, 12));
lblwindowsjdkbug.setBounds(25, 323, 456, 40);
frmvBy.getContentPane().add(lblwindowsjdkbug);
JLabel Account = new JLabel("采购商账号:");
Account.setFont(new Font("微软雅黑", Font.PLAIN, 14));
Account.setBounds(9, 10, 88, 15);
ToCart.add(Account);
JLabel Password = new JLabel("密码:");
Password.setFont(new Font("微软雅黑", Font.PLAIN, 14));
Password.setBounds(50, 41, 65, 15);
ToCart.add(Password);
JLabel No = new JLabel("商品编号:");
No.setFont(new Font("微软雅黑", Font.PLAIN, 14));
No.setBounds(22, 100, 88, 15);
ToCart.add(No);
account = new JTextField();
account.setText(buyerAccount);
account.setFont(new Font("微软雅黑", Font.PLAIN, 12));
account.setBounds(92, 4, 130, 25);
ToCart.add(account);
account.setColumns(10);
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);
//sku编号
SkuNo = new JTextArea();
SkuNo.setText("选填,勿填活动商品");
SkuNo.setForeground(Color.LIGHT_GRAY);
SkuNo.setFont(new Font("微软雅黑", Font.PLAIN, 12));
SkuNo.setLineWrap(true);
SkuNo.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (SkuNo.getText().equals("选填,勿填活动商品") || SkuNo.getText().equals("选填,勿填非活动商品") ) {
SkuNo.setForeground(Color.black);
SkuNo.setText("");
}
}
});
SkuNo.setBounds(92, 100, 130, 25);
SkuNo.setBorder(new LineBorder(new Color(127,157,185), 1, false));
ToCart.add(SkuNo);
SkuNo.setColumns(10);
//商品类型
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);
//活动商品
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);
JLabel RegisterAccount = new JLabel("采购商邮箱:");
register.add(RegisterAccount);
RegisterAccount.setFont(new Font("微软雅黑", Font.PLAIN, 14));
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);
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
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;
}
};
worker.execute();
}
});
}
}