diff --git a/.gitignore b/.gitignore
index 2d920a8..31ca1db 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,3 +25,4 @@ target
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
+/.idea/
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
deleted file mode 100644
index c18bc66..0000000
--- a/.idea/compiler.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
deleted file mode 100644
index b26911b..0000000
--- a/.idea/encodings.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 4b661a5..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
deleted file mode 100644
index e96534f..0000000
--- a/.idea/uiDesigner.xml
+++ /dev/null
@@ -1,124 +0,0 @@
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index 5512c66..d923bdb 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,11 @@ A simple java selenium testing script, using chrome webDriver
+ `src/main/.../utils`: some beneficial utility
## Usage
-
+### write the URL and MACHINE type in `Constants.java`
+```txt
+type: windows / mac_m1
+url: https://www.baidu.com
+```
### Write the UI elements' xpath in `OR.txt`
> schema: `PageObject = xpath`
diff --git a/driver/chromedriver_mac_m1 b/driver/chromedriver_mac_m1
new file mode 100755
index 0000000..0403dca
Binary files /dev/null and b/driver/chromedriver_mac_m1 differ
diff --git a/src/main/java/com/junit/selenium/config/Constants.java b/src/main/java/com/junit/selenium/config/Constants.java
index 8abc203..792f5eb 100644
--- a/src/main/java/com/junit/selenium/config/Constants.java
+++ b/src/main/java/com/junit/selenium/config/Constants.java
@@ -3,10 +3,11 @@
public class Constants {
// 这里定义为public static的类型,方便其他任何类进行访问和调用
- public static final String URL = "http://gc21131138.imwork.net:20430/test-maker/web/client/index.action";
+ public static final String URL = "https://www.baidu.com";
+ public static final String MACHINE = "mac_m1";
+// public static final String MACHINE = "windows";
- public static final String Path_TestData = ".\\src\\main\\java\\com\\junit\\selenium\\data\\data.xlsx";
- public static final String File_TestData = "data.xlsx";
+ public static final String Path_TestData = "./src/main/java/com/junit/selenium/data/data.xlsx";
// data.xlsx中一些单元格的索引值
@@ -31,7 +32,7 @@ public class Constants {
// OR(对象仓库)文件路径
- public static final String OR_Path =".\\src\\main\\java\\com\\junit\\selenium\\config\\OR.txt";
+ public static final String OR_Path ="./src/main/java/com/junit/selenium/config/OR.txt";
// // 测试登录用到的用户数据
// public static final String UserName = "MaoHaonan";
diff --git a/src/main/java/com/junit/selenium/config/OR.txt b/src/main/java/com/junit/selenium/config/OR.txt
index 2981dc5..fb55ce1 100644
--- a/src/main/java/com/junit/selenium/config/OR.txt
+++ b/src/main/java/com/junit/selenium/config/OR.txt
@@ -1,6 +1,5 @@
-#login page
-loginUsernameInputbox=//*[@id='username']
-loginPasswordInptbox =//*[@id='password']
-loginAuthbtn=//*[@id='auth-button']
-loginProjectlist=//*[@id="project-list"]
-loginLoginbtn=//*[@id='login-button']
\ No newline at end of file
+store=//*[@id="app"]/div[1]/div[1]/div/div[1]/div[2]/div[4]
+pet=//*[@id="app"]/div[1]/div[2]/div/div[2]/div[2]/div/div/div[1]
+buy=//*[@id="app"]/div[1]/div[2]/div/div[1]/div[2]/div[2]/div[3]
+input=//*[@id="kw"]
+search=//*[@id="su"]
\ No newline at end of file
diff --git a/src/main/java/com/junit/selenium/data/data.xlsx b/src/main/java/com/junit/selenium/data/data.xlsx
index 4aed186..b6809fb 100644
Binary files a/src/main/java/com/junit/selenium/data/data.xlsx and b/src/main/java/com/junit/selenium/data/data.xlsx differ
diff --git a/src/main/java/com/junit/selenium/script/DriverScript.java b/src/main/java/com/junit/selenium/script/DriverScript.java
index f3b0398..635f179 100644
--- a/src/main/java/com/junit/selenium/script/DriverScript.java
+++ b/src/main/java/com/junit/selenium/script/DriverScript.java
@@ -13,9 +13,18 @@
public class DriverScript {
private static ActionKeywords actionKeywords;
- private static String sActionKeyword;//从Excel中读到的关键字
- private static String[] sArgs; //输入方法的参数
- public static Properties OR; //页面元素的xpath
+ /**
+ * 从Excel中读到的关键字
+ */
+ private static String sActionKeyword;
+ /**
+ * 输入方法的参数
+ */
+ private static String[] sArgs;
+ /**
+ * 页面元素的xpath
+ */
+ public static Properties OR;
private static Method methods[];
@@ -23,12 +32,12 @@ public class DriverScript {
public static boolean bResult;
- private DriverScript() throws NoSuchMethodException, SecurityException, ClassNotFoundException{
+ private DriverScript() throws SecurityException{
actionKeywords = new ActionKeywords();
methods = actionKeywords.getClass().getMethods();
}
- public static void main(String[] args) throws Exception{
+ public static void main(String[] args) {
try {
DOMConfigurator.configure("log4j.xml");
@@ -37,10 +46,10 @@ public static void main(String[] args) throws Exception{
Log.info("加载和读取Excel数据文件");
ExcelUtils.setExcelFile(Constants.Path_TestData);
- FileInputStream fs = new FileInputStream(Constants.OR_Path);// 创建一个文件输入流对象
- OR = new Properties(System.getProperties()); // 创建一个Properties对象
+ FileInputStream fs = new FileInputStream(Constants.OR_Path);
+ OR = new Properties(System.getProperties());
- OR.load(fs);// 加载全部对象仓库文件
+ OR.load(fs);
DriverScript startEngine = new DriverScript();
Log.info("开始执行测试用例。");
@@ -124,7 +133,8 @@ private static void execute_Actions() throws Exception {
// 一但匹配到相关关键字方法,就会调用对应的关键字静态方法
// methods[i].invoke(actionKeywords);
- method.invoke(actionKeywords, sArgs); //如果元素对象是空的,则excel中必须有个空格字符,否则java会编译不通过。
+ //如果元素对象是空的,则excel中必须有个空格字符,否则java会编译不通过。
+ method.invoke(actionKeywords, sArgs);
// 一旦任何关键字被执行,利用break语句去跳出for循环。
// This code block will execute after every test step
diff --git a/src/main/java/com/junit/selenium/utils/ChromeDriverUtils.java b/src/main/java/com/junit/selenium/utils/ChromeDriverUtils.java
index 78dad17..6ffc43a 100644
--- a/src/main/java/com/junit/selenium/utils/ChromeDriverUtils.java
+++ b/src/main/java/com/junit/selenium/utils/ChromeDriverUtils.java
@@ -1,8 +1,9 @@
package com.junit.selenium.utils;
+import com.junit.selenium.config.Constants;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
-import org.openqa.selenium.remote.DesiredCapabilities;
+import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.io.File;
@@ -13,8 +14,14 @@ public class ChromeDriverUtils {
private static void createAndStartService() throws IOException {
+ String driverPath = "";
+ if(Constants.MACHINE.equals("mac_m1")){
+ driverPath = "driver/chromedriver_mac_m1";
+ }else{
+ driverPath = "driver/chromedriver.exe";
+ }
service = new ChromeDriverService.Builder()
- .usingDriverExecutable(new File("driver/chromedriver.exe"))
+ .usingDriverExecutable(new File(driverPath))
.usingAnyFreePort()
.build();
service.start();
@@ -27,7 +34,7 @@ private static void stopService() {
public static WebDriver createDriver() throws IOException {
createAndStartService();
WebDriver driver = new RemoteWebDriver(service.getUrl(),
- DesiredCapabilities.chrome());
+ new ChromeOptions());
return driver;
}
diff --git a/src/test/java/com/junit/selenium/ChromeDriverTest.java b/src/test/java/com/junit/selenium/ChromeDriverTest.java
index 3905e5c..cbf4be8 100644
--- a/src/test/java/com/junit/selenium/ChromeDriverTest.java
+++ b/src/test/java/com/junit/selenium/ChromeDriverTest.java
@@ -19,7 +19,7 @@ public class ChromeDriverTest extends TestCase {
// @BeforeClass
// public static void createAndStartService() throws IOException {
// service = new ChromeDriverService.Builder()
-// .usingDriverExecutable(new File("driver/chromedriver.exe"))
+// .usingDriverExecutable(new File("driver/chromedriver_mac_m1.exe"))
// .usingAnyFreePort()
// .build();
// service.start();
@@ -46,6 +46,6 @@ public void testBingSearch() {
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("webdriver");
- assertEquals("微软 Bing 搜索 - 国内版", driver.getTitle());
+ assertEquals("必应", driver.getTitle());
}
}