BrowserEmulator - nowind/UiDo GitHub Wiki

该类中的方法分成大类:

  • 原dagger的操作方法
  • 新增的用户操作方法
  • 新增派发到周边的方法
  • 表示流程顺序的方法 除了派发到周边和end方法外,其他的方法都返回this
  1. 2个实用的滚屏函数
        public BrowserEmulator scrollPageButtom()
	{
		getBrowserCore().executeScript("window.scrollTo(0,document.body.scrollHeight)");
		pause(500);
		return log("window scroll  page To Buttom");
	}
	public BrowserEmulator scrollPage()
	{
		getBrowserCore().executeScript("window.scrollTo(0,window.screen.height)");
		pause(500);
		return log("window scroll  one page down");
	}
  1. 显式超时等待 (隐式超时等待一般较长,用于可忍受的较长等待,显式等待则要处理比较急迫的情况)
       public BrowserEmulator wait4path(String path,long time)
	{
		new WebDriverWait(this.getBrowserCore(), time)
			.until(new ExpectedCondition<WebElement>() {
	            @Override
	            public WebElement apply(WebDriver d) {
	            	if(path.startsWith(".")||path.startsWith("#"))return d.findElement(By.cssSelector(path));
	        		if(path.startsWith("//"))return d.findElement(By.xpath(path));
	        		else return d.findElement(By.cssSelector(path));
	            }
	        });
		return this;
	}
  1. 显式截图,日志输出带截图
         public BrowserEmulator capture(){
		return log(_capture());
	}
	 String _capture(){
		return "screen to "+Utils.screenShot(driver);
	}
        public BrowserEmulator log(String format, Object ... args)
	{
		System.out.println(String.format(format, args));
		return this;
	}  
  1. 切换到其他tab(对应新开窗口情况,部分浏览器在新开tab后并非自动切换到新浏览器)
                public BrowserEmulator switchToOther() {
		ArrayList<String> handles=new ArrayList<String> (this.getBrowserCore().getWindowHandles());
		String curr=this.getBrowserCore().getWindowHandle();
		if(handles.size()<2)
		{
			System.err.println("one window can,no switch");
		}
		else
		{
			if(!handles.get(0).equals(curr))
				curr=handles.get(0);
			else
				curr=handles.get(1);
			this.getBrowserCore().switchTo().window(curr);
		}
		return this;
	}
  1. 兼容xpath和css选择器
	public BrowserEmulator legacy()
	{
		storeCss=this.getSelectorState();
		UseXpath();
		return this;
	}
	public BrowserEmulator resume()
	{
		if(storeCss)UseCss();
		else UseXpath();
		return this;
	}
  1. 派发到周边
        public Action action() {
		return Action.me();
	}
	public DBHelper db()
	{
		return DBHelper.me;
	}

db设计的时候就是全局单例,本身不继承BaseHelper而其他的一些周边都是线程变量都是继承BaseHelper

⚠️ **GitHub.com Fallback** ⚠️