diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..3c8a0a2
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,136 @@
+
+
+ 4.0.0
+
+ com.essatest
+ essa
+ 1.0-SNAPSHOT
+ jar
+
+ essa
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+
+ org.testng
+ testng
+ 6.14.3
+
+
+
+
+ org.seleniumhq.selenium
+ selenium-java
+ 3.11.0
+
+
+
+
+ org.seleniumhq.selenium
+ selenium-firefox-driver
+ 3.11.0
+
+
+
+ org.seleniumhq.selenium
+ selenium-chrome-driver
+ 3.11.0
+
+
+
+ org.seleniumhq.selenium
+ selenium-safari-driver
+ 3.11.0
+
+
+
+ org.seleniumhq.selenium
+ selenium-ie-driver
+ 3.11.0
+
+
+
+
+ org.seleniumhq.selenium
+ selenium-support
+ 2.46.0
+
+
+
+ javax.mail
+ mail
+ 1.4
+
+
+
+ org.apache.commons
+ commons-collections4
+ 4.1
+
+
+
+ org.apache.poi
+ poi
+ 3.14
+
+
+
+ org.apache.poi
+ poi-ooxml
+ 3.14
+
+
+
+ org.apache.poi
+ poi-ooxml-schemas
+ 3.14
+
+
+
+ org.apache.commons
+ commons-io
+ 1.3.2
+
+
+
+ mysql
+ mysql-connector-java
+ 6.0.6
+
+
+ org.dbunit
+ dbunit
+ 2.5.4
+
+
+ jdom
+ jdom
+ 1.0
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.7.1
+
+
+
+ resources/suites/testng.xml
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/buyer/pageObject/AssetManagementPage.java b/src/main/java/com/buyer/pageObject/AssetManagementPage.java
new file mode 100644
index 0000000..883c8b5
--- /dev/null
+++ b/src/main/java/com/buyer/pageObject/AssetManagementPage.java
@@ -0,0 +1,11 @@
+package com.buyer.pageObject;
+
+import org.openqa.selenium.WebDriver;
+
+import com.essa.framework.BasePage;
+
+public class AssetManagementPage extends BasePage {
+ public AssetManagementPage(WebDriver driver) {
+ super(driver);
+ }
+}
diff --git a/src/main/java/com/buyer/pageObject/BuyerLoginPage.java b/src/main/java/com/buyer/pageObject/BuyerLoginPage.java
new file mode 100644
index 0000000..d69e77b
--- /dev/null
+++ b/src/main/java/com/buyer/pageObject/BuyerLoginPage.java
@@ -0,0 +1,48 @@
+package com.buyer.pageObject;
+
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.FindBy;
+
+import com.essa.framework.BasePage;
+
+/**
+ * 采购商登录页
+ * @author Administrator
+ *
+ */
+public class BuyerLoginPage extends BasePage {
+ public BuyerLoginPage(WebDriver driver) {
+ super(driver);
+ }
+ /*
+ * 页面元素定位
+ */
+ //用户名:邮箱
+ @FindBy (xpath = "//*[@id='username']")
+ WebElement userName;
+
+ //密码
+ @FindBy (xpath = "//*[@id='password']")
+ WebElement passWord;
+
+ //登录按钮
+ @FindBy (xpath = "//*[@id='login']")
+ WebElement signIn;
+
+ /*
+ * 页面方法
+ */
+ /**
+ * 采购商登录方法
+ * @param account 账号
+ * @param password 密码
+ * @return IndexPage
+ */
+ public IndexPage login(String account,String password) {
+ sendKeys(userName, account);
+ sendKeys(passWord, password);
+ click(signIn);
+ return new IndexPage(driver);
+ }
+}
diff --git a/src/main/java/com/buyer/pageObject/ConslidationPage.java b/src/main/java/com/buyer/pageObject/ConslidationPage.java
new file mode 100644
index 0000000..86827fc
--- /dev/null
+++ b/src/main/java/com/buyer/pageObject/ConslidationPage.java
@@ -0,0 +1,97 @@
+package com.buyer.pageObject;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.FindBy;
+
+import com.essa.framework.BasePage;
+import com.essa.framework.Model;
+
+/**
+ * 暂存柜,拼柜页面
+ * @author Administrator
+ *
+ */
+public class ConslidationPage extends BasePage {
+ public ConslidationPage(WebDriver driver) {
+ super(driver);
+ }
+ /*
+ * 元素定位
+ */
+ //关闭提示
+ @FindBy(xpath="//*[@class='close']")
+ WebElement close;
+
+ //选择散货
+ @FindBy (xpath ="//button[text()='Bulk cargo']")
+ WebElement bulkCargo;
+
+ //确认
+ @FindBy (xpath="//button[text()='OK']")
+ WebElement ok;
+
+ //查询输入框
+ @FindBy (xpath="//*[@id='left-search']/div/input")
+ WebElement searchText;
+
+ //查询按钮
+ @FindBy (xpath="//*[@id='left-search']/div/span")
+ WebElement search;
+
+ //左边列表第一个复选框
+ @FindBy (xpath="//*[@id='left-product-list']/div[1]/div/div[2]/div/ul/li[1]/input")
+ WebElement leftFirstCheckbox;
+
+ //中间加入右边的箭头
+ @FindBy (xpath="//*[@id='icon-pi-right-big']")
+ WebElement add;
+
+ //右边的第一个复选框
+ @FindBy (xpath="//*[@id='right-product-list']/div/div/div[2]/div/ul/li[1]/input")
+ WebElement rightFirstCheckbox;
+
+ //下一步,设置贴纸
+ @FindBy (xpath="//*[@id='next']")
+ WebElement next;
+
+ //确认弹框-可能会提示价格不一致
+ @FindBy (xpath ="//a[text()='OK']")
+ WebElement ok2;
+
+ /**
+ * 开始拼柜
+ * @return SettingMarkerPage
+ */
+ public SettingMarksPage conslidation() {
+ //是否有操作提示弹框
+ if(isVisibility(By.xpath("//*[@class='close']"))) {
+ click(close);
+ }
+ forceWait(1000);
+ //是否有选择货柜
+ if(isVisibility(By.xpath("//button[text()='Bulk cargo']"))) {
+ click(bulkCargo);
+ click(ok);
+ forceWait(1000);
+ }
+ sendKeys(searchText, Model.getSkuNo());
+ click(search);
+ click(leftFirstCheckbox);
+ click(add);
+ //是否有加入到暂存柜
+ dynamicWait(By.xpath("//*[@id='right-product-list']/div/div/div[2]/div/ul/li[1]/input"));
+ forceWait(2000);
+ moveHeightScroll("100");
+ forceWait(1000);
+ click(next);
+ //如果提示价格变化,确认弹框
+ if(isVisibility(By.xpath("//a[text()='OK']"))) {
+ click(ok2);
+ forceWait(1000);
+ click(next);
+ }
+ return new SettingMarksPage(driver);
+ }
+}
diff --git a/src/main/java/com/buyer/pageObject/IndexPage.java b/src/main/java/com/buyer/pageObject/IndexPage.java
new file mode 100644
index 0000000..4161e69
--- /dev/null
+++ b/src/main/java/com/buyer/pageObject/IndexPage.java
@@ -0,0 +1,131 @@
+package com.buyer.pageObject;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.FindBy;
+
+import com.essa.framework.BasePage;
+import com.essa.framework.Model;
+
+/**
+ * 采购商首页
+ * @author Administrator
+ *
+ */
+public class IndexPage extends BasePage {
+ public IndexPage(WebDriver driver) {
+ super(driver);
+ }
+ /*
+ * 元素定位
+ */
+ //登录-sign in
+ @FindBy (xpath ="//*[@id='SignIn']/a")
+ WebElement signIn;
+
+ //注册-register
+ @FindBy (xpath ="//*[@class='u-login']/a")
+ WebElement register;
+
+ //关键字输入框
+ @FindBy (xpath ="//*[@class='search-tx']/input")
+ WebElement searchText;
+
+ //查询按钮
+ @FindBy (xpath ="//*[@class='btn btn-primary search-btn']")
+ WebElement searchButton;
+
+ //绑定手机弹窗-关闭按钮
+ @FindBy (xpath ="//*[contains(@class,'layui-layer-close1')]")
+ WebElement closed;
+
+ //右上角购物车
+ @FindBy (xpath ="//*[@id='miniCart']")
+ WebElement minicart;
+
+ /*
+ * 页面方法
+ */
+ /**
+ * 进入登录页面
+ * @return BuyerLoginPage
+ */
+ public BuyerLoginPage toLoginPage() {
+ click(signIn);
+ return new BuyerLoginPage(driver);
+ }
+
+ /**
+ * 进入注册页面
+ * @return RegisterPage
+ */
+ public RegisterPage toRegisterPage() {
+ click(register);
+ return new RegisterPage(driver);
+ }
+
+ /**
+ * 进入购物车
+ * @return ShoppingCartPage
+ */
+ public ShoppingCartPage toShoppingCartPage() {
+ if (isVisibility(By.xpath("//*[@id='bind-phone']"))) {
+ forceWait(1000);
+ click(closed);
+ }
+ click(minicart);
+ return new ShoppingCartPage(driver);
+ }
+ /**
+ * 关键字搜索商品
+ * @return KeywordResultPage
+ */
+ public KeywordResultPage keywordSearch() {
+ //判断是否绑定手机
+ if (isVisibility(By.xpath("//*[@id='bind-phone']"))) {
+ click(closed);
+ }
+ //如果是非活动
+// if (Model.getIsactivity()==0 &&(Model.getSkuNo().equals("选填,勿填活动商品")||Model.getSkuNo().equals(""))) {
+ if (Model.getIsactivity()==0 &&(("选填,勿填活动商品").equals(Model.getSkuNo())||("").equals(Model.getSkuNo()))) {
+ //判断是否自定义输入商品编号
+ String sql = "SELECT s.id,s.`no` from prd_category c\r\n" +
+ "LEFT JOIN prd_goods g on c.id = g.category_id\r\n" +
+ "LEFT JOIN prd_goods_sku s on s.goods_id = g.id\r\n" +
+ "where find_in_set(5,REPLACE(c.path,'.',','))\r\n" +
+ "AND s.`no` > 200000000\r\n" +
+ "AND s.id NOT IN (SELECT g.sku_id FROM sale_group_buy g)\r\n" +
+ "AND s.id NOT IN (SELECT t.sku_id FROM sale_shopping_cart t)\r\n" +
+ "AND s.src = 1\r\n" +
+ "AND s.`status` = 2\r\n" +
+ "AND s.is_stop_product = 0\r\n" +
+ "AND s.is_delete = 0\r\n" +
+ "limit 1";
+ Model.setSkuNo(DBSqlSearch(sql, "no"));
+ }else if (Model.getIsactivity()==1 &&(("选填,勿填非活动商品").equals(Model.getSkuNo())||("").equals(Model.getSkuNo()))) {
+ //活动商品
+ String sql = "SELECT s.id,s.`no` from prd_category c\r\n" +
+ "LEFT JOIN prd_goods g on c.id = g.category_id\r\n" +
+ "LEFT JOIN prd_goods_sku s on s.goods_id = g.id\r\n" +
+ "LEFT JOIN sale_group_buy a on a.sku_id = s.id\r\n" +
+ "where s.`no` > 200000000\r\n" +
+ "AND s.id NOT IN (SELECT t.sku_id FROM sale_shopping_cart t)\r\n" +
+ "AND a.`status` = 20 and s.src = 1 \r\n" +
+ "limit 1;";
+ Model.setSkuNo(DBSqlSearch(sql, "no"));
+ }
+// System.out.println(Model.getSkuNo());
+ sendKeys(searchText, Model.getSkuNo());
+ click(searchButton);
+ return new KeywordResultPage(driver);
+ }
+
+ /**
+ * 断言是否注册成功,根据是否有绑定手机号的弹窗来判断
+ * @return boolean
+ */
+ public boolean isSucceed() {
+ return isVisibility(By.xpath("//*[contains(@class,'layui-layer-close1')]"));
+ }
+}
diff --git a/src/main/java/com/buyer/pageObject/KeywordResultPage.java b/src/main/java/com/buyer/pageObject/KeywordResultPage.java
new file mode 100644
index 0000000..d5fc48f
--- /dev/null
+++ b/src/main/java/com/buyer/pageObject/KeywordResultPage.java
@@ -0,0 +1,116 @@
+package com.buyer.pageObject;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.FindBy;
+
+import com.essa.framework.BasePage;
+import com.essa.framework.Model;
+
+/**
+ * 关键字查询结果页
+ * @author Administrator
+ *
+ */
+public class KeywordResultPage extends BasePage {
+ public KeywordResultPage(WebDriver driver) {
+ super(driver);
+ }
+ /*
+ * 元素定位
+ */
+ //加入购物车
+ @FindBy (xpath ="//*[@id='product-list']/ul[1]/div[1]/li[1]/div[1]/div[1]/div[4]/div[2]")
+ WebElement addToCart;
+
+ //确认添加
+ @FindBy (xpath ="//*[@id='product-list']/ul[1]/div[1]/li[1]/div[2]/div[3]/div[1]")
+ WebElement confirmAdd;
+
+ //添加购物车时,提示加入一款成功toast
+ @FindBy (xpath ="//*[@class='util-bill-pd']")
+ WebElement toast;
+
+ //右上角购物车
+ @FindBy (xpath ="//*[@id='miniCart']")
+ WebElement minicart;
+
+ //订购量
+ @FindBy (xpath="//*[contains(text(),'quantity')]/../span[2]/input")
+ WebElement count;
+
+ //活动商品-添加购物车
+ @FindBy (xpath ="//*[@class='btn-box']/div[2]")
+ WebElement addToCart1;
+
+ //查询输入框
+ @FindBy (xpath ="//*[@class='search-tx']/input")
+ WebElement searchText;
+
+ /*
+ * 页面方法
+ */
+ /**
+ * 加入到购物车中,且会进入购物车校验是否加入成功
+ * @return ShoppingCartPage
+ */
+ public ShoppingCartPage addToCart() {
+ if (Model.getIsactivity() == 0) {//该sku为非活动商品
+ click(addToCart);
+ forceWait(1000);
+ click(count);
+ sendKeys(count, "50");
+ }else if (Model.getIsactivity() == 1) {//该sku为活动商品
+ click(addToCart1);
+ forceWait(1000);
+ click(count);
+ sendKeys(count, "200");
+ }
+
+ click(confirmAdd);
+ dynamicWait(By.xpath("//*[@class='util-bill-pd']"));
+ forceWait(1000);
+ click(minicart);
+ if (Model.getIsactivity() == 1) {
+ getManager();//找出对应的类目经理
+ }
+ return new ShoppingCartPage(driver);
+ }
+ /**
+ * 由于操作过快,系统会提示:有人正在操作
+ * sku加入到购物车,但不进入购物车,防止无法操作后续的拼柜
+ * 此方法与addToCart()一样,只是不进入购物车
+ */
+ public void addSku() {
+ if (Model.getIsactivity() == 0) {
+ click(addToCart);
+ forceWait(1000);
+ click(count);
+ sendKeys(count, "50");
+ }else if (Model.getIsactivity() == 1) {
+ click(addToCart1);
+ forceWait(1000);
+ click(count);
+ sendKeys(count, "200");
+ }
+ click(confirmAdd);
+ dynamicWait(By.xpath("//*[@class='util-bill-pd']"));
+ if (Model.getIsactivity() == 1) {
+ sendKeys(searchText, "查询数据库ing……程序还在进行,无聊可以先去撩撩妹子呀!");
+ getManager();//找出对应的类目经理
+ }
+ }
+
+ /**
+ * 根据sql查出商品对应类目经理,并在model类中设置其值
+ */
+ public void getManager() {
+ //查找商品对应的类目经理sql
+ String sql = "SELECT u.account_name from prd_goods g \r\n" +
+ "LEFT JOIN prd_goods_sku s on g.id = s.goods_id\r\n" +
+ "LEFT JOIN pri_user u on u.id = g.category_manager_id\r\n" +
+ "where s.`no` in ("+Model.getSkuNo()+");";
+ Model.setManager(DBSqlSearch(sql, "account_name"));
+ }
+}
diff --git a/src/main/java/com/buyer/pageObject/MyOrderPage.java b/src/main/java/com/buyer/pageObject/MyOrderPage.java
new file mode 100644
index 0000000..35c748c
--- /dev/null
+++ b/src/main/java/com/buyer/pageObject/MyOrderPage.java
@@ -0,0 +1,11 @@
+package com.buyer.pageObject;
+
+import org.openqa.selenium.WebDriver;
+
+import com.essa.framework.BasePage;
+
+public class MyOrderPage extends BasePage {
+ public MyOrderPage(WebDriver driver) {
+ super(driver);
+ }
+}
diff --git a/src/main/java/com/buyer/pageObject/OrderPreviewPage.java b/src/main/java/com/buyer/pageObject/OrderPreviewPage.java
new file mode 100644
index 0000000..acb0573
--- /dev/null
+++ b/src/main/java/com/buyer/pageObject/OrderPreviewPage.java
@@ -0,0 +1,48 @@
+package com.buyer.pageObject;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.FindBy;
+
+import com.essa.framework.BasePage;
+
+/**
+ * @author Administrator
+ *订单预览页
+ */
+public class OrderPreviewPage extends BasePage {
+ public OrderPreviewPage(WebDriver driver) {
+ super(driver);
+ }
+
+ //是否授权:同意
+ @FindBy (xpath ="//*[@ng-checked='list.isAuthorExchange==1']")
+ WebElement agree;
+
+ //提交po
+ @FindBy (xpath ="//*[@id='react-orderConfirmation-submit']")
+ WebElement sendPO;
+
+ //弹框:确认
+ @FindBy (xpath ="//a[text()='Send PO']")
+ WebElement confirm;
+
+ /**
+ * 提交po
+ * @return PayDepositPage
+ */
+ public PayDepositPage submit() {
+// while(!(isVisibility(By.xpath("//*[@ng-checked='list.isAuthorExchange==1']")))) {
+// forceWait(1000);
+// }
+ dynamicWait(By.xpath("//*[@ng-checked='list.isAuthorExchange==1']"));
+ moveHeightScroll("50");
+ forceWait(500);
+ jsExecutorClick(agree);
+ click(sendPO);
+ forceWait(1000);
+ click(confirm);
+ return new PayDepositPage(driver);
+ }
+}
diff --git a/src/main/java/com/buyer/pageObject/PayDepositPage.java b/src/main/java/com/buyer/pageObject/PayDepositPage.java
new file mode 100644
index 0000000..44d3b9a
--- /dev/null
+++ b/src/main/java/com/buyer/pageObject/PayDepositPage.java
@@ -0,0 +1,69 @@
+package com.buyer.pageObject;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.FindBy;
+
+import com.essa.framework.BasePage;
+import com.essa.framework.Model;
+
+/**
+ * @author Administrator
+ *支付定金页
+ */
+public class PayDepositPage extends BasePage {
+ public PayDepositPage(WebDriver driver) {
+ super(driver);
+ }
+
+ //PO信息
+ @FindBy (xpath="//*[contains(text(),'PO information')]")
+ WebElement POInfo;
+
+ //查看资金详情---可用资金不足
+ @FindBy (xpath ="//button[@class='submit-payment-deposit-button btn btn-primary']")
+ WebElement FundDetail;
+
+ //免定金模式--确认按钮
+ @FindBy (xpath ="//*[@ng-click='submit()']")
+ WebElement ok;
+
+ //po单号
+ @FindBy (xpath ="//*[contains(text(),'PO number:')]/../../td[2]/span")
+ WebElement poNum;
+
+ /**
+ * 查看资金详情
+ * @return AssetManagementPage
+ */
+ public AssetManagementPage toAssetManagementPage() {
+ click(FundDetail);
+ return new AssetManagementPage(driver);
+ }
+
+ /**
+ * 确认PO
+ * @return MyOrderPage
+ */
+ public MyOrderPage confirm() {
+ click(ok);
+ return new MyOrderPage(driver);
+ }
+
+ public void operate() {
+ /*while (!(isVisibility(By.xpath("//*[contains(text(),'PO information')]")))) {
+ forceWait(1000);
+ }*/
+ dynamicWait(By.xpath("//*[contains(text(),'PO information')]"));
+ Model.setPoNum(poNum.getText());
+ if (isVisibility(By.xpath("//button[@class='submit-payment-deposit-button btn btn-primary']"))) {
+ //如果是可用资金不足,跳转到资金管理
+ toAssetManagementPage();
+ }else if (isVisibility(By.xpath("//*[@ng-click='submit()']"))) {
+ //免定金模式,确认po,跳转到我的订单列表
+ confirm();
+ }
+ forceWait(2000);
+ }
+}
diff --git a/src/main/java/com/buyer/pageObject/RegisterPage.java b/src/main/java/com/buyer/pageObject/RegisterPage.java
new file mode 100644
index 0000000..b99b48a
--- /dev/null
+++ b/src/main/java/com/buyer/pageObject/RegisterPage.java
@@ -0,0 +1,165 @@
+package com.buyer.pageObject;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.FindBy;
+
+import com.essa.framework.BasePage;
+import com.essa.framework.Model;
+import com.essa.framework.Tools;
+
+/**
+ * 采购商注册页
+ * @author Administrator
+ *
+ */
+public class RegisterPage extends BasePage {
+ public RegisterPage(WebDriver driver) {
+ super(driver);
+ }
+ /*
+ * 元素定位
+ */
+ //检查点-是否进入页面
+ @FindBy (xpath ="//*[contains(text(),' Own essa.cn account')]")
+ WebElement checkPoint;
+
+ //email
+ @FindBy (xpath ="//*[@id='email']")
+ WebElement email;
+
+ //password
+ @FindBy (xpath ="//*[@id='password']")
+ WebElement password;
+
+ //confirmPassword
+ @FindBy (xpath ="//*[@id='confirmPassword']")
+ WebElement confirmPassword;
+
+ //币种 currency
+ @FindBy (xpath ="//*[@id='currPlaceholder']")
+ WebElement currPlaceholder;
+
+ //CNY
+ @FindBy (xpath="//*[text()='CNY']")
+ WebElement CNY;
+
+ //companyName
+ @FindBy (xpath="//*[@id='companyName']")
+ WebElement companyName;
+
+ //空白的地方-用于关闭选项框
+ @FindBy (xpath ="//*[@class='register-right']")
+ WebElement blank;
+
+ //区域continent
+ @FindBy (xpath ="//*[@id='continentPlaceholder']")
+ WebElement continentPlaceholder;
+
+ //欧洲europe
+ @FindBy (xpath="//*[text()='Europe']")
+ WebElement Europe;
+
+ //country
+ @FindBy (xpath ="//*[@id='countryPlaceholder']")
+ WebElement country;
+
+ //俄罗斯Russian
+ @FindBy (xpath ="//*[text()='Russian federation']")
+ WebElement Russian;
+
+ //contactName
+ @FindBy (xpath ="//*[@id='contactName']")
+ WebElement contactName;
+
+ //phone
+ @FindBy (xpath ="//*[@id='phone']")
+ WebElement phone;
+
+ //purchaseQuantity
+ @FindBy (xpath ="//*[@id='purchaseQuantity']")
+ WebElement purchaseQuantity;
+
+ //quantity
+ @FindBy (xpath ="//*[contains(text(),'1 000 000 - 2 500 000 USD')]")
+ WebElement quantity;
+
+ //singleQuantity
+ @FindBy (xpath ="//*[@id='singleQuantity']")
+ WebElement singleQuantity;
+
+ //single
+ @FindBy (xpath ="//*[text()='30-49 ctn']")
+ WebElement single;
+
+ //select
+ @FindBy (xpath ="//*[text()='Select']")
+ WebElement select;
+
+ //toys1
+ @FindBy (xpath ="//*[@title='Animals&plants']")
+ WebElement toys1;
+
+ //toys2
+ @FindBy (xpath ="//*[text()='Dolls and accessories']")
+ WebElement toys2;
+
+ //toys3
+ @FindBy (xpath ="//*[text()='Bricks']")
+ WebElement toys3;
+
+ //referralCode
+ @FindBy (xpath ="//*[@id='referralCode']")
+ WebElement referralCode;
+
+ //checkBox
+ @FindBy (xpath ="//*[@id='protocol']")
+ WebElement checkbox;
+
+ //Register
+ @FindBy (xpath ="//*[@id='submit']")
+ WebElement register;
+
+ /*
+ * 页面方法
+ */
+ /**
+ * 注册
+ * @return IndexPage
+ */
+ public IndexPage register() {
+ SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmm");
+ String num = Tools.getTime();
+ sendKeys(email, Model.getEmail());
+ sendKeys(password, "essa123");
+ sendKeys(confirmPassword, "essa123");
+ click(currPlaceholder);
+ click(CNY);
+ sendKeys(companyName, "Auto"+num);
+ click(continentPlaceholder);
+ click(Europe);
+ click(Russian);
+ sendKeys(contactName, "Tester"+num);
+ sendKeys(phone, format.format(new Date()));
+ forceWait(500);
+ click(purchaseQuantity);
+ click(quantity);
+ forceWait(500);
+ click(singleQuantity);
+ click(single);
+ moveHeightScroll("100");
+ jsExecutorClick(select);
+ click(toys1);
+ click(toys2);
+ click(toys3);
+ click(blank);
+ sendKeys(referralCode, Model.getInvateCode());
+ jsExecutorClick(checkbox);
+ click(register);
+ forceWait(3000);
+ return new IndexPage(driver);
+ }
+}
diff --git a/src/main/java/com/buyer/pageObject/SettingMarksPage.java b/src/main/java/com/buyer/pageObject/SettingMarksPage.java
new file mode 100644
index 0000000..a97f9cf
--- /dev/null
+++ b/src/main/java/com/buyer/pageObject/SettingMarksPage.java
@@ -0,0 +1,46 @@
+package com.buyer.pageObject;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.FindBy;
+
+import com.essa.framework.BasePage;
+
+/**
+ * 设置唛头页
+ * @author Administrator
+ *
+ */
+public class SettingMarksPage extends BasePage {
+ public SettingMarksPage(WebDriver driver) {
+ super(driver);
+ }
+ //不应用唛头
+ @FindBy (xpath ="//*[@title='No shipping marks for these products']")
+ WebElement noNeedMarks;
+
+ //下一步
+ @FindBy (xpath ="//*[text()='Next step']")
+ WebElement next;
+
+ //弹框提示-确定
+ @FindBy (xpath ="//*[text()='OK']")
+ WebElement ok;
+
+ /**
+ * 设置唛头:不应用唛头
+ * @return SettingStickerPage
+ */
+ public SettingStickerPage setMarks() {
+ /*while(!(isVisibility(By.xpath("//*[@title='No shipping marks for these products']")))) {
+ forceWait(1000);
+ }*/
+ dynamicWait(By.xpath("//*[@title='No shipping marks for these products']"));
+ click(noNeedMarks);
+ click(next);
+ forceWait(500);
+ click(ok);
+ return new SettingStickerPage(driver);
+ }
+}
diff --git a/src/main/java/com/buyer/pageObject/SettingStickerPage.java b/src/main/java/com/buyer/pageObject/SettingStickerPage.java
new file mode 100644
index 0000000..cb97338
--- /dev/null
+++ b/src/main/java/com/buyer/pageObject/SettingStickerPage.java
@@ -0,0 +1,44 @@
+package com.buyer.pageObject;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.FindBy;
+
+import com.essa.framework.BasePage;
+
+/**
+ * @author Administrator
+ *设置贴纸页
+ */
+public class SettingStickerPage extends BasePage {
+ public SettingStickerPage(WebDriver driver) {
+ super(driver);
+ }
+ //不应用贴纸
+ @FindBy (xpath ="//*[@title='No stickers for these products']")
+ WebElement noNeedSticker;
+
+ //下一步
+ @FindBy (xpath ="//*[text()='Next step']")
+ WebElement next;
+
+ //弹框提示-确定
+ @FindBy (xpath ="//*[text()='OK']")
+ WebElement ok;
+
+ /**
+ * 设置贴纸:不应用贴纸
+ * @return OrderPreviewPage
+ */
+ public OrderPreviewPage setSticker() {
+ /*while (!(isVisibility(By.xpath("//*[@title='No stickers for these products']")))) {
+ forceWait(1000);
+ }*/
+ dynamicWait(By.xpath("//*[@title='No stickers for these products']"));
+ click(noNeedSticker);
+ click(next);
+ click(ok);
+ return new OrderPreviewPage(driver);
+ }
+}
diff --git a/src/main/java/com/buyer/pageObject/ShoppingCartPage.java b/src/main/java/com/buyer/pageObject/ShoppingCartPage.java
new file mode 100644
index 0000000..4057035
--- /dev/null
+++ b/src/main/java/com/buyer/pageObject/ShoppingCartPage.java
@@ -0,0 +1,81 @@
+package com.buyer.pageObject;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.FindBy;
+
+import com.essa.framework.BasePage;
+import com.essa.framework.Model;
+
+/**
+ * 购物车页
+ * @author Administrator
+ *
+ */
+public class ShoppingCartPage extends BasePage {
+ public ShoppingCartPage(WebDriver driver) {
+ super(driver);
+ }
+ /*
+ * 元素定位
+ */
+ //关键字查询框
+ @FindBy (xpath ="//*[@ng-model='keyword']")
+ WebElement keyword;
+
+ //查询按钮
+ @FindBy (xpath ="//*[contains(@ng-click,'search()')]")
+ WebElement searchButton;
+
+ //搜索结果的一个sku对应的复选框
+ @FindBy (xpath ="//*[contains(@class,'products-list ng-scope')]/div[2]/div[2]/span[1]/input")
+ WebElement checkbox;
+
+ //可拼柜
+ @FindBy (xpath="//*[text()='Consolidation allowed']")
+ WebElement consolidationAllowed;
+
+ //开始拼柜
+ @FindBy (xpath ="//button[contains(text(),' Start consolidation')]")
+ WebElement startConslidation;
+
+ //确认采购按钮
+ @FindBy (xpath = "//*[@class='products-list ng-scope']/div[2]/div/div[1]/div/span[5]/div/button")
+ WebElement confirmOrder;
+
+ /*
+ * 页面方法
+ */
+ /**
+ * 断言sku是否已经加入购物车
+ * @return true:已加入 false:未加入
+ */
+ public boolean isSucceed() {
+ mywait(keyword);
+ sendKeys(keyword, Model.getSkuNo());
+ click(searchButton);
+ mywait(checkbox);
+ forceWait(2000);
+ return isVisibility(By.xpath("//*[contains(text(),'"+Model.getSkuNo()+"')]"));
+ }
+ /**
+ * 开始拼柜
+ * @return ConslidationPage
+ */
+ public ConslidationPage startConslidation() {
+ mywait(keyword);
+ click(consolidationAllowed);
+ mywait(startConslidation);
+ click(startConslidation);
+ return new ConslidationPage(driver);
+ }
+
+ /**
+ * 确认采购
+ */
+ public void confirmOrder() {
+ dynamicLoad(By.xpath("//*[@class='products-list ng-scope']/div[2]/div/div[1]/div/span[5]/div/button"));
+ click(confirmOrder);
+ }
+}
diff --git a/src/main/java/com/buyer/testSuite/TestAddToCart.java b/src/main/java/com/buyer/testSuite/TestAddToCart.java
new file mode 100644
index 0000000..c9076f1
--- /dev/null
+++ b/src/main/java/com/buyer/testSuite/TestAddToCart.java
@@ -0,0 +1,65 @@
+package com.buyer.testSuite;
+
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.support.PageFactory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.testng.asserts.SoftAssert;
+
+import com.buyer.pageObject.IndexPage;
+import com.buyer.pageObject.KeywordResultPage;
+import com.buyer.pageObject.ShoppingCartPage;
+import com.essa.framework.Model;
+import com.essa.pageObject.BaseTest;
+
+/**
+ * @author Administrator
+ *测试用例:采购商平台采购流程
+ */
+public class TestAddToCart extends BaseTest {
+ WebDriver driver;
+
+ @BeforeClass
+ public void setUp() {
+ initBuyer();
+ loginBuyerValid(Model.getBuyerAccount(),Model.getBuyerPassword());
+// loginBuyerValid("buyer51551@essa.cn","essa123");
+// Model.setIsactivity(1);
+// Model.setSkuNo("");
+ }
+ @AfterClass
+ public void tearDown() {
+ driver.quit();
+ }
+
+ /**
+ * 关键字查询,并将搜到的结果加入购物车
+ */
+ @Test(description="关键字搜索,并将sku加入购物车",groups= {"first"})
+ public void keywordToCart() {
+ this.driver = getDriver();
+ IndexPage indexPage = PageFactory.initElements(driver, IndexPage.class);
+ indexPage.keywordSearch();
+ KeywordResultPage keywordResultPage = PageFactory.initElements(driver, KeywordResultPage.class);
+ keywordResultPage.addToCart();
+ //断言
+ ShoppingCartPage shoppingCartPage = PageFactory.initElements(driver, ShoppingCartPage.class);
+ boolean actual = shoppingCartPage.isSucceed();
+ SoftAssert softAssert = new SoftAssert();
+ softAssert.assertEquals(actual, true, "加入购物车失败!");
+ softAssert.assertAll();
+ }
+
+ /**
+ * 关键字查询,加入购物车,但不进入购物车,防止提示有人正在操作
+ */
+ @Test(description="将sku加入购物车")
+ public void addSku() {
+ this.driver = getDriver();
+ IndexPage indexPage = PageFactory.initElements(driver, IndexPage.class);
+ indexPage.keywordSearch();
+ KeywordResultPage keywordResultPage = PageFactory.initElements(driver, KeywordResultPage.class);
+ keywordResultPage.addSku();
+ }
+}
diff --git a/src/main/java/com/buyer/testSuite/TestConfirmBuy.java b/src/main/java/com/buyer/testSuite/TestConfirmBuy.java
new file mode 100644
index 0000000..3c5a363
--- /dev/null
+++ b/src/main/java/com/buyer/testSuite/TestConfirmBuy.java
@@ -0,0 +1,40 @@
+package com.buyer.testSuite;
+
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.support.PageFactory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import com.buyer.pageObject.IndexPage;
+import com.buyer.pageObject.ShoppingCartPage;
+import com.essa.framework.Model;
+import com.essa.pageObject.BaseTest;
+
+public class TestConfirmBuy extends BaseTest {
+
+ WebDriver driver;
+
+ @BeforeTest
+ public void setUp() {
+ initBuyer();
+ loginBuyerValid(Model.getBuyerAccount(),Model.getBuyerPassword());
+ }
+
+ @AfterClass
+ public void tearDown() {
+ driver.quit();
+ }
+
+ /**
+ * 登录采购商账号,确认订单
+ */
+ @Test(description="采购商确认采购")
+ public void confirmBuy() {
+ this.driver = getDriver();
+ IndexPage indexPage = PageFactory.initElements(driver, IndexPage.class);
+ indexPage.toShoppingCartPage();
+ ShoppingCartPage shoppingCartPage = PageFactory.initElements(driver, ShoppingCartPage.class);
+ shoppingCartPage.confirmOrder();
+ }
+}
diff --git a/src/main/java/com/buyer/testSuite/TestRegister.java b/src/main/java/com/buyer/testSuite/TestRegister.java
new file mode 100644
index 0000000..35573ce
--- /dev/null
+++ b/src/main/java/com/buyer/testSuite/TestRegister.java
@@ -0,0 +1,45 @@
+package com.buyer.testSuite;
+
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.support.PageFactory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.testng.asserts.SoftAssert;
+
+import com.buyer.pageObject.IndexPage;
+import com.buyer.pageObject.RegisterPage;
+import com.essa.pageObject.BaseTest;
+
+/**
+ * @author Administrator
+ *测试用例:采购商注册信息填写
+ */
+public class TestRegister extends BaseTest{
+ WebDriver driver;
+
+ @BeforeClass
+ public void setUp() {
+ initBuyer();
+ }
+
+ /**
+ * 注册buyer
+ */
+ @Test(description="填写注册采购商信息,注册采购商")
+ public void register() {
+ this.driver = getDriver();
+ IndexPage indexPage = PageFactory.initElements(driver, IndexPage.class);
+ indexPage.toRegisterPage();
+ RegisterPage registerPage = PageFactory.initElements(driver, RegisterPage.class);
+ registerPage.register();
+
+ SoftAssert softAssert = new SoftAssert();
+ softAssert.assertEquals(indexPage.isSucceed(), true, "采购商注册失败了!");
+ softAssert.assertAll();
+ }
+ @AfterClass
+ public void tearDown() {
+ driver.quit();
+ }
+}
diff --git a/src/main/java/com/buyer/testSuite/TestSendPO.java b/src/main/java/com/buyer/testSuite/TestSendPO.java
new file mode 100644
index 0000000..8c9bca7
--- /dev/null
+++ b/src/main/java/com/buyer/testSuite/TestSendPO.java
@@ -0,0 +1,64 @@
+package com.buyer.testSuite;
+
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.support.PageFactory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import com.buyer.pageObject.ConslidationPage;
+import com.buyer.pageObject.IndexPage;
+import com.buyer.pageObject.OrderPreviewPage;
+import com.buyer.pageObject.PayDepositPage;
+import com.buyer.pageObject.SettingMarksPage;
+import com.buyer.pageObject.SettingStickerPage;
+import com.buyer.pageObject.ShoppingCartPage;
+import com.essa.framework.Model;
+import com.essa.pageObject.BaseTest;
+
+/**
+ * @author Administrator
+ *测试用例:采购商平台采购流程
+ */
+public class TestSendPO extends BaseTest {
+ WebDriver driver;
+
+ @BeforeClass
+ public void setUp() {
+ initBuyer();
+ loginBuyerValid(Model.getBuyerAccount(),Model.getBuyerPassword());
+// loginBuyerValid("buyer51551@essa.cn","essa123");
+ }
+ @AfterClass
+ public void tearDown() {
+ driver.quit();
+ }
+
+ /**
+ * 开始拼柜
+ */
+ @Test(description="开始拼柜")
+ public void conslidation() {
+ this.driver = getDriver();
+ IndexPage indexPage = PageFactory.initElements(driver, IndexPage.class);
+ indexPage.toShoppingCartPage();
+ ShoppingCartPage shoppingCartPage = PageFactory.initElements(driver, ShoppingCartPage.class);
+ shoppingCartPage.startConslidation();
+ ConslidationPage conslidationPage = PageFactory.initElements(driver, ConslidationPage.class);
+ conslidationPage.conslidation();
+ }
+ /**
+ * 提交PO
+ */
+ @Test(description="设置贴纸唛头,提交PO")
+ public void sendPO() {
+ this.driver = getDriver();
+ SettingMarksPage settingMarksPage = PageFactory.initElements(driver, SettingMarksPage.class);
+ settingMarksPage.setMarks();
+ SettingStickerPage settingStickerPage = PageFactory.initElements(driver, SettingStickerPage.class);
+ settingStickerPage.setSticker();
+ OrderPreviewPage orderPreviewPage = PageFactory.initElements(driver, OrderPreviewPage.class);
+ orderPreviewPage.submit();
+ PayDepositPage payDepositPage = PageFactory.initElements(driver, PayDepositPage.class);
+ payDepositPage.operate();
+ }
+}
diff --git a/src/main/java/com/essa/framework/BasePage.java b/src/main/java/com/essa/framework/BasePage.java
new file mode 100644
index 0000000..a656e03
--- /dev/null
+++ b/src/main/java/com/essa/framework/BasePage.java
@@ -0,0 +1,700 @@
+package com.essa.framework;
+
+import java.awt.Robot;
+import java.awt.Toolkit;
+import java.awt.datatransfer.StringSelection;
+import java.awt.event.KeyEvent;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.openqa.selenium.Alert;
+import org.openqa.selenium.By;
+import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.NoSuchElementException;
+import org.openqa.selenium.OutputType;
+import org.openqa.selenium.TakesScreenshot;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+import org.openqa.selenium.support.ui.Select;
+import org.openqa.selenium.support.ui.WebDriverWait;
+
+import com.essa.framework.BasePage;
+import com.essa.framework.LogType;
+import com.essa.framework.Logger;
+import com.mysql.cj.jdbc.PreparedStatement;
+
+public class BasePage {
+
+ public static WebDriver driver;
+ public static String pageTitle;
+ public static String pageUrl;
+ public static String OutputFileName = getDateTimeByFormat(new Date(), "yyyyMMdd_HHmmss");
+
+ /**
+ * 构造方法
+ * @param driver
+ */
+ public BasePage(WebDriver driver) {
+ BasePage.driver = driver;
+ }
+
+ /**
+ * 在文本框内输入字符
+ * @param element
+ * @param text
+ */
+ protected void sendKeys(WebElement element, String text) {
+ try {
+ mywait(element);
+ if (element.isEnabled()) {
+ element.clear();
+ Logger.Output(LogType.LogTypeName.INFO, "清除文本框中已有字符:" + partialStr(element.toString(), "xpath:"));
+ element.sendKeys(text);
+ Logger.Output(LogType.LogTypeName.INFO, "输入的字符是:" + text);
+ }
+ } catch (Exception e) {
+ Logger.Output(LogType.LogTypeName.ERROR, element.toString()+"元素不存在");
+ }
+
+ }
+
+ /**
+ * 点击元素,这里指点击鼠标左键
+ * @param element
+ */
+ protected void click(WebElement element) {
+
+ try {
+ mywait(element);
+ if (element.isEnabled()) {
+ Logger.Output(LogType.LogTypeName.INFO, "点击元素:" + partialStr(element.toString(), "xpath:"));
+ element.click();
+ }
+ } catch (Exception e) {
+ Logger.Output(LogType.LogTypeName.ERROR, e.getMessage() + ".");
+ }
+
+ }
+
+ /**
+ * 在文本输入框执行清除操作
+ * @param element
+ */
+ protected void clear(WebElement element) {
+ try {
+ if (element.isEnabled()) {
+ element.clear();
+ Logger.Output(LogType.LogTypeName.INFO, "清除输入框中字符:" + partialStr(element.toString(), "xpath:") );
+ }
+ } catch (Exception e) {
+ Logger.Output(LogType.LogTypeName.ERROR, e.getMessage() + ".");
+ }
+
+ }
+
+ /**
+ * 判断一个页面元素是否显示在当前页面
+ * @param element
+ */
+ protected void verifyElementIsPresent(WebElement element) {
+
+ try {
+ if (element.isDisplayed()) {
+ Logger.Output(LogType.LogTypeName.INFO, "元素存在:" + partialStr(element.toString(), "xpath:").trim());
+
+ }
+ } catch (Exception e) {
+ Logger.Output(LogType.LogTypeName.ERROR, e.getMessage() + ".");
+ }
+ }
+
+ /**
+ * 获取页面的标题
+ * @return
+ */
+ protected String getCurrentPageTitle() {
+
+ pageTitle = driver.getTitle();
+ Logger.Output(LogType.LogTypeName.INFO, "当前页面的标题为:" + pageTitle);
+ return pageTitle;
+ }
+
+ /**
+ * 获取页面的url
+ * @return
+ */
+ public static String getCurrentPageUrl() {
+ pageUrl = driver.getCurrentUrl();
+ Logger.Output(LogType.LogTypeName.INFO, "当前页面的URL为:" + pageUrl);
+ return pageUrl;
+ }
+
+ /**
+ * 处理多窗口之间切换
+ */
+ protected void switchWindow() {
+
+ String currentWindow = driver.getWindowHandle();// 获取当前窗口句柄
+ Set handles = driver.getWindowHandles();// 获取所有窗口句柄
+ Logger.Output(LogType.LogTypeName.INFO, "当前窗口数量: " + handles.size());
+ Iterator it = handles.iterator();
+ while (it.hasNext()) {
+ if (currentWindow == it.next()) {
+ driver.close();
+ continue;
+ }
+ try {
+ // driver.close();// 关闭旧窗口
+ WebDriver window = driver.switchTo().window(it.next());// 切换到新窗口
+ Logger.Output(LogType.LogTypeName.INFO, "新窗口的标题为:" + window.getTitle());
+ } catch (Exception e) {
+ Logger.Output(LogType.LogTypeName.ERROR, "无法切换到新打开窗口" + e.getMessage());
+
+ }
+ // driver.close();//关闭当前焦点所在的窗口
+ }
+ // driver.switchTo().window(currentWindow);//回到原来页面
+ }
+
+ /**
+ * 处理多窗口之间切换
+ * 将会关闭当前的窗口
+ */
+ protected void switchMoreWindow() {
+
+ String handle = driver.getWindowHandle();
+ for(String temhandle : driver.getWindowHandles()) {
+ if (!temhandle.equals(handle)) {
+ driver.close();
+ driver.switchTo().window(temhandle);
+ }
+ }
+ }
+ /**
+ * 浏览器弹框操作,true确认弹框,false取消弹框
+ * @param isAccept
+ */
+ protected void alert(boolean isAccept) {
+ Alert alert = driver.switchTo().alert();
+ if (isAccept) {
+ Logger.Output(LogType.LogTypeName.INFO, "提示框内容为:" + alert.getText());
+ alert.accept();
+ Logger.Output(LogType.LogTypeName.INFO, "确认弹框");
+ } else {
+ Logger.Output(LogType.LogTypeName.INFO, "提示框内容为:" + alert.getText());
+ alert.dismiss();
+ Logger.Output(LogType.LogTypeName.INFO, "取消弹框");
+ }
+ }
+
+ /**
+ * 下拉框选择选项
+ * 元素必须可以使用select,input和button使用会报错
+ * @param element
+ * @param optionText
+ */
+ protected void selectElement(WebElement element, String optionText) {
+ Select select = new Select(element);
+ select.selectByVisibleText(optionText);
+ Logger.Output(LogType.LogTypeName.INFO, "选择选项:" + optionText);
+ }
+
+ /**
+ * 下拉框选择选项,通过选项中的value来定位
+ * @param element
+ * @param value
+ */
+ protected void selectElement(WebElement element, int value) {
+ Select select = new Select(element);
+ select.selectByIndex(value);
+ Logger.Output(LogType.LogTypeName.INFO, "选择选项:" + value);
+ }
+ /**
+ * 判断元素在页面中是否存在
+ * @param element
+ * @return boolean
+ */
+ protected boolean isElementExist(WebElement element) {
+ try {
+ Boolean bool = element.isDisplayed();
+
+ Logger.Output(LogType.LogTypeName.INFO, "检查元素是否存在:" +partialStr(element.toString(), "xpath:")+":"+ bool);
+ return bool;
+ } catch (NoSuchElementException e) {
+ takeScreenShot();
+ Logger.Output(LogType.LogTypeName.ERROR, "无法确认当前元素是否存在:" + e.getMessage());
+ return false;
+ }
+ }
+
+ /**
+ * 元素在页面上是否可见,不建议用此方法,有时会报错,找不出原因
+ * @param element
+ * @return boolean
+ */
+ protected boolean isVisibility(WebElement element) {
+ try {
+ if(ExpectedConditions.visibilityOf(element) != null) {
+ Logger.Output(LogType.LogTypeName.INFO, "元素在页面上可见");
+ return true;
+ }
+ } catch (NoSuchElementException e) {
+ Logger.Output(LogType.LogTypeName.ERROR, "无法页面上是否有此元素");
+ return false;
+ }
+ Logger.Output(LogType.LogTypeName.INFO, "元素在页面不可见");
+ return false;
+ }
+
+ /**
+ * 元素在页面上是否可见
+ * @param element
+ * @return
+ */
+ protected boolean isVisibility(By by) {
+ try {
+ Logger.Output(LogType.LogTypeName.INFO, "检查元素在页面上是否可见");
+ if(ExpectedConditions.visibilityOf(driver.findElement(by)) != null) {
+ Logger.Output(LogType.LogTypeName.INFO, "元素可见:"+by.toString());
+ return true;
+ }
+ } catch (NoSuchElementException e) {
+ }
+ Logger.Output(LogType.LogTypeName.INFO, "元素不可见:"+by.toString());
+ return false;
+ }
+
+
+ /**
+ * 获取元素的文本值
+ * @param element
+ */
+ protected String getText(WebElement element) {
+
+ try {
+ if (element.isEnabled()) {
+ Logger.Output(LogType.LogTypeName.INFO, "获取当前元素的文本值:" + element.getText());
+ return element.getText();
+ }
+ } catch (Exception e) {
+ Logger.Output(LogType.LogTypeName.ERROR, e.getMessage() + ".");
+ }
+ return null;
+ }
+
+ /**
+ * js的点击操作
+ * @param element
+ */
+ protected void jsExecutorClick(WebElement element) {
+ try {
+ mywait(element);
+ JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
+ jsExecutor.executeScript("arguments[0].click();", element);
+ Logger.Output(LogType.LogTypeName.INFO, "调用JavaScript点击元素:" + partialStr(element.toString(), "xpath:"));
+ } catch (Exception e) {
+ Logger.Output(LogType.LogTypeName.ERROR, e.getMessage() + ".");
+ }
+
+ }
+
+ /**
+ * js的删除操作
+ * @param webElement
+ * @param attribute
+ */
+ protected void jsExecutorRemoveAttribute(WebElement webElement, String attribute) {
+ try {
+ JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
+ jsExecutor.executeScript("arguments[0].removeAttribute('" + attribute + "');", webElement);
+ Logger.Output(LogType.LogTypeName.INFO, "调用JavaScript删除元素属性:" + attribute);
+ } catch (Exception e) {
+ Logger.Output(LogType.LogTypeName.ERROR, e.getMessage() + ".");
+ }
+
+ }
+
+ /**
+ * 获取js返回的值
+ * @param webElement
+ * @return
+ */
+ protected String jsExecutorGetAttributeValue(WebElement webElement) {
+ try {
+ JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
+ Logger.Output(LogType.LogTypeName.INFO, "调用JavaScript返回元素属性值");
+ return (String) jsExecutor.executeScript("return arguments[0].id;", webElement);
+ } catch (Exception e) {
+ Logger.Output(LogType.LogTypeName.ERROR, e.getMessage() + ".");
+ return null;
+ }
+ }
+
+ /**
+ * 读取excel中的数据
+ * @param filepath excel的路径地址
+ * @param filename excel的文件名
+ * @param SheetName excel的worksheet名
+ * @return
+ * @throws Exception
+ */
+ public static Object[][] readExcel(String filepath, String filename, String SheetName){
+ try {
+ File file = new File(filepath + "\\" + filename);
+ FileInputStream inputStream = new FileInputStream(file);
+ Workbook Workbook = null;
+ // 获取文件扩展名
+ String fileExtensionName = filename.substring(filename.indexOf("."));
+ Logger.Output(LogType.LogTypeName.INFO, "获取所要读取的文件");
+ // 判断是.xlsx还是.xls的文件并进行实例化
+ if (fileExtensionName.equals(".xlsx")) {
+ Workbook = new XSSFWorkbook(inputStream);
+ Logger.Output(LogType.LogTypeName.INFO, "文件为:.xlsx格式");
+ } else if (fileExtensionName.equals(".xls")) {
+ Workbook = new HSSFWorkbook(inputStream);
+ Logger.Output(LogType.LogTypeName.INFO, "文件为:.xls格式");
+ }
+ // 通过sheetName生成Sheet对象
+ Sheet Sheet = Workbook.getSheet(SheetName);
+ int rowCount = Sheet.getLastRowNum() - Sheet.getFirstRowNum();
+ List