Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3790d94

Browse files
committed
JUnit5 改造示例
1 parent fb94603 commit 3790d94

5 files changed

Lines changed: 455 additions & 442 deletions

File tree

pom.xml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,30 @@
6262
<artifactId>log4j</artifactId>
6363
<version>1.2.17</version>
6464
</dependency>
65+
<!-- JUnit 5 -->
6566
<dependency>
66-
<groupId>junit</groupId>
67-
<artifactId>junit</artifactId>
68-
<version>4.12</version>
67+
<groupId>org.junit.jupiter</groupId>
68+
<artifactId>junit-jupiter-api</artifactId>
69+
<version>5.6.0</version>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.junit.jupiter</groupId>
74+
<artifactId>junit-jupiter-params</artifactId>
75+
<version>5.6.0</version>
76+
<scope>test</scope>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.junit.jupiter</groupId>
80+
<artifactId>junit-jupiter-engine</artifactId>
81+
<version>5.6.0</version>
82+
<scope>test</scope>
83+
</dependency>
84+
<!-- Macaca Reporter -->
85+
<dependency>
86+
<groupId>com.macacajs</groupId>
87+
<artifactId>macaca-reporter-java-plugin</artifactId>
88+
<version>1.0</version>
6989
</dependency>
7090
<dependency>
7191
<groupId>org.hamcrest</groupId>
Lines changed: 156 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,156 @@
1-
package macaca.client;
2-
3-
import com.alibaba.fastjson.JSONArray;
4-
import com.alibaba.fastjson.JSONObject;
5-
6-
import org.junit.After;
7-
import org.junit.Assert;
8-
import org.junit.Before;
9-
import org.junit.Test;
10-
11-
import java.io.File;
12-
import java.io.IOException;
13-
import java.util.List;
14-
import macaca.client.commands.Element;
15-
16-
import static org.hamcrest.CoreMatchers.containsString;
17-
18-
public class AndroidSampleTest {
19-
MacacaClient driver = new MacacaClient();
20-
// set screenshot save path
21-
File directory = new File("");
22-
public String courseFile = directory.getCanonicalPath();
23-
24-
public AndroidSampleTest() throws IOException {
25-
}
26-
27-
@Before
28-
public void setUp() throws Exception {
29-
// platform: android or ios
30-
String platform = "android";
31-
32-
/*
33-
Desired Capabilities are used to configure webdriver when initiating the session.
34-
Document URL: https://macacajs.github.io/desired-caps.html
35-
*/
36-
JSONObject porps = new JSONObject();
37-
porps.put("platformName", platform);
38-
porps.put("app", "https://npmcdn.com/android-app-bootstrap@latest/android_app_bootstrap/build/outputs/apk/android_app_bootstrap-debug.apk");
39-
porps.put("reuse", 1);
40-
// device id
41-
// porps.put("udid","0715f7ea12391134");
42-
JSONObject desiredCapabilities = new JSONObject();
43-
desiredCapabilities.put("desiredCapabilities", porps);
44-
driver.initDriver(desiredCapabilities);
45-
}
46-
47-
@Test
48-
public void testCaseOne() throws Exception {
49-
50-
System.out.println("------------#1 login test-------------------");
51-
loginTest();
52-
53-
System.out.println("------------#2 scroll tableview test-------------------");
54-
scrollTableViewTest();
55-
56-
System.out.println("------------#3 webview test-------------------");
57-
webViewTest();
58-
59-
System.out.println("------------#4 baidu web test-------------------");
60-
baiduWebTest();
61-
62-
System.out.println("------------#5 logout test-------------------");
63-
logoutTest();
64-
65-
}
66-
67-
public void loginTest() throws Exception {
68-
driver.elementById("com.github.android_app_bootstrap:id/mobileNoEditText")
69-
.sendKeys("中文+Test+12345678");
70-
71-
List<Element> elements = driver.elementsByClassName("android.widget.EditText");
72-
elements.get(1).sendKeys("111111");
73-
driver.elementByName("Login").click();
74-
driver.sleep(1000);
75-
}
76-
77-
78-
public void scrollTableViewTest() throws Exception {
79-
driver.elementByName("HOME").click();
80-
driver.elementByName("list").click();
81-
driver.sleep(1000);
82-
driver.drag(200, 420, 200, 10, 0.5);
83-
driver.sleep(5000);
84-
85-
86-
// 拖拽一个元素或者在多个坐标之间移动,实现tableview滚动操作
87-
driver.drag(200, 420, 200, 20, 0.5);
88-
driver.sleep(1000);
89-
driver.back();
90-
driver.sleep(1000);
91-
}
92-
93-
public void webViewTest() throws Exception {
94-
driver.elementByName("Webview").click();
95-
driver.sleep(3000);
96-
// save screen shot
97-
driver.saveScreenshot(courseFile + "/webView.png");
98-
99-
switchToWebView(driver).elementById("pushView").click();
100-
driver.sleep(5000);
101-
102-
switchToWebView(driver).elementById("popView").click();
103-
driver.sleep(5000);
104-
}
105-
106-
public void baiduWebTest() throws Exception {
107-
switchToNative(driver).elementByName("Baidu").click();
108-
driver.sleep(5000);
109-
driver.saveScreenshot(courseFile + "/baidu.png");
110-
111-
// switchToWebView(driver).elementById("index-kw").sendKeys("中文+TesterHome");
112-
113-
Element input = switchToWebView(driver).elementById("index-kw");
114-
input.sendKeys("中文+TesterHome");
115-
driver.sleep(1000);
116-
117-
// 测试清理API
118-
input.clearText();
119-
driver.sleep(1000);
120-
121-
// 重新输入
122-
input.sendKeys("中文+TesterHome");
123-
driver.sleep(1000);
124-
125-
driver.elementById("index-bn").click();
126-
driver.sleep(5000);
127-
String source = driver.source();
128-
Assert.assertThat(source, containsString("TesterHome"));
129-
}
130-
131-
132-
public void logoutTest() throws Exception {
133-
134-
switchToNative(driver).elementByName("PERSONAL").click();
135-
driver.sleep(1000).elementByName("Logout").click();
136-
driver.sleep(1000);
137-
}
138-
139-
140-
// switch to the context of the last pushed webview
141-
public MacacaClient switchToWebView(MacacaClient driver) throws Exception {
142-
JSONArray contexts = driver.contexts();
143-
return driver.context(contexts.get(contexts.size() - 1).toString());
144-
}
145-
146-
// switch to the context of native
147-
public MacacaClient switchToNative(MacacaClient driver) throws Exception {
148-
JSONArray contexts = driver.contexts();
149-
return driver.context(contexts.get(0).toString());
150-
}
151-
152-
@After
153-
public void tearDown() throws Exception {
154-
driver.quit();
155-
}
156-
}
1+
//package macaca.client;
2+
//
3+
//import com.alibaba.fastjson.JSONArray;
4+
//import com.alibaba.fastjson.JSONObject;
5+
//
6+
//import org.junit.After;
7+
//import org.junit.Assert;
8+
//import org.junit.Before;
9+
//import org.junit.Test;
10+
//
11+
//import java.io.File;
12+
//import java.io.IOException;
13+
//import java.util.List;
14+
//import macaca.client.commands.Element;
15+
//
16+
//import static org.hamcrest.CoreMatchers.containsString;
17+
//
18+
//public class AndroidSampleTest {
19+
// MacacaClient driver = new MacacaClient();
20+
// // set screenshot save path
21+
// File directory = new File("");
22+
// public String courseFile = directory.getCanonicalPath();
23+
//
24+
// public AndroidSampleTest() throws IOException {
25+
// }
26+
//
27+
// @Before
28+
// public void setUp() throws Exception {
29+
// // platform: android or ios
30+
// String platform = "android";
31+
//
32+
// /*
33+
// Desired Capabilities are used to configure webdriver when initiating the session.
34+
// Document URL: https://macacajs.github.io/desired-caps.html
35+
// */
36+
// JSONObject porps = new JSONObject();
37+
// porps.put("platformName", platform);
38+
// porps.put("app", "https://npmcdn.com/android-app-bootstrap@latest/android_app_bootstrap/build/outputs/apk/android_app_bootstrap-debug.apk");
39+
// porps.put("reuse", 1);
40+
// // device id
41+
//// porps.put("udid","0715f7ea12391134");
42+
// JSONObject desiredCapabilities = new JSONObject();
43+
// desiredCapabilities.put("desiredCapabilities", porps);
44+
// driver.initDriver(desiredCapabilities);
45+
// }
46+
//
47+
// @Test
48+
// public void testCaseOne() throws Exception {
49+
//
50+
// System.out.println("------------#1 login test-------------------");
51+
// loginTest();
52+
//
53+
// System.out.println("------------#2 scroll tableview test-------------------");
54+
// scrollTableViewTest();
55+
//
56+
// System.out.println("------------#3 webview test-------------------");
57+
// webViewTest();
58+
//
59+
// System.out.println("------------#4 baidu web test-------------------");
60+
// baiduWebTest();
61+
//
62+
// System.out.println("------------#5 logout test-------------------");
63+
// logoutTest();
64+
//
65+
// }
66+
//
67+
// public void loginTest() throws Exception {
68+
// driver.elementById("com.github.android_app_bootstrap:id/mobileNoEditText")
69+
// .sendKeys("中文+Test+12345678");
70+
//
71+
// List<Element> elements = driver.elementsByClassName("android.widget.EditText");
72+
// elements.get(1).sendKeys("111111");
73+
// driver.elementByName("Login").click();
74+
// driver.sleep(1000);
75+
// }
76+
//
77+
//
78+
// public void scrollTableViewTest() throws Exception {
79+
// driver.elementByName("HOME").click();
80+
// driver.elementByName("list").click();
81+
// driver.sleep(1000);
82+
// driver.drag(200, 420, 200, 10, 0.5);
83+
// driver.sleep(5000);
84+
//
85+
//
86+
// // 拖拽一个元素或者在多个坐标之间移动,实现tableview滚动操作
87+
// driver.drag(200, 420, 200, 20, 0.5);
88+
// driver.sleep(1000);
89+
// driver.back();
90+
// driver.sleep(1000);
91+
// }
92+
//
93+
// public void webViewTest() throws Exception {
94+
// driver.elementByName("Webview").click();
95+
// driver.sleep(3000);
96+
// // save screen shot
97+
// driver.saveScreenshot(courseFile + "/webView.png");
98+
//
99+
// switchToWebView(driver).elementById("pushView").click();
100+
// driver.sleep(5000);
101+
//
102+
// switchToWebView(driver).elementById("popView").click();
103+
// driver.sleep(5000);
104+
// }
105+
//
106+
// public void baiduWebTest() throws Exception {
107+
// switchToNative(driver).elementByName("Baidu").click();
108+
// driver.sleep(5000);
109+
// driver.saveScreenshot(courseFile + "/baidu.png");
110+
//
111+
//// switchToWebView(driver).elementById("index-kw").sendKeys("中文+TesterHome");
112+
//
113+
// Element input = switchToWebView(driver).elementById("index-kw");
114+
// input.sendKeys("中文+TesterHome");
115+
// driver.sleep(1000);
116+
//
117+
// // 测试清理API
118+
// input.clearText();
119+
// driver.sleep(1000);
120+
//
121+
// // 重新输入
122+
// input.sendKeys("中文+TesterHome");
123+
// driver.sleep(1000);
124+
//
125+
// driver.elementById("index-bn").click();
126+
// driver.sleep(5000);
127+
// String source = driver.source();
128+
// Assert.assertThat(source, containsString("TesterHome"));
129+
// }
130+
//
131+
//
132+
// public void logoutTest() throws Exception {
133+
//
134+
// switchToNative(driver).elementByName("PERSONAL").click();
135+
// driver.sleep(1000).elementByName("Logout").click();
136+
// driver.sleep(1000);
137+
// }
138+
//
139+
//
140+
// // switch to the context of the last pushed webview
141+
// public MacacaClient switchToWebView(MacacaClient driver) throws Exception {
142+
// JSONArray contexts = driver.contexts();
143+
// return driver.context(contexts.get(contexts.size() - 1).toString());
144+
// }
145+
//
146+
// // switch to the context of native
147+
// public MacacaClient switchToNative(MacacaClient driver) throws Exception {
148+
// JSONArray contexts = driver.contexts();
149+
// return driver.context(contexts.get(0).toString());
150+
// }
151+
//
152+
// @After
153+
// public void tearDown() throws Exception {
154+
// driver.quit();
155+
// }
156+
//}

0 commit comments

Comments
 (0)