BasePage

package com.mushishi.Imooc.page;

import java.util.Set;

import org.apache.log4j.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import com.mushishi.Imooc.util.ProUtil;

public class BasePage {
	public WebDriver driver;
	static Logger logger = Logger.getLogger(BasePage.class);

	public BasePage(WebDriver driver) {
		this.driver = driver;
	}
	
	public WebElement GetElement(String key) {
		boolean flag=true;
		int i =0;
		WebElement Element=null;
		while(flag) {
			try {
				Element = driver.findElement(this.GetByLocal(key));
				flag=false;
				
			}
			catch(Exception e) {
				i=i+1;
				if(i ==10) {
					flag=false;
				}
			}
		}
		return Element;

	}
	
	public By GetByLocal(String key) {
		ProUtil pro = new ProUtil("element.properties");
		logger.debug("你得定位信息得key为:"+key);
		String Locator = pro.GetPro(key); //username=name>email
		String LocatorBy = Locator.split(">")[0];
		String LocatorValue = Locator.split(">")[1];
		logger.debug("你得定位方式为:"+LocatorBy);
		logger.debug("你得定位值为:"+LocatorValue);
		
		if(LocatorBy.equals("id")) {
			return By.id(LocatorValue);
		}else if(LocatorBy.equals("name")) {
			return By.name(LocatorValue);
		}else if(LocatorBy.equals("className")) {
			return By.className(LocatorValue);
		}else {
			return By.xpath(LocatorValue);
		}
	}
	
	public void MoveToElement(WebElement ToElement) {
		Actions  MoseActions = new Actions(driver);
		MoseActions.moveToElement(ToElement).perform();
	}
	
	
	public boolean GetCookie(String key) {
		boolean flag = false;
		Set<Cookie> cookies = driver.manage().getCookies();
		for(Cookie cookie:cookies) {
			if(cookie.getName().equals(key)) {
				flag = true;
			}
		}
		return flag;
	}
	

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值