holmos.webtest.element.tool.SeleniumElementExist Maven / Gradle / Ivy
package holmos.webtest.element.tool;
import holmos.webtest.Allocator;
import holmos.webtest.element.locator.Locator;
import holmos.webtest.element.locator.LocatorValue;
import holmos.webtest.struct.Collection;
import holmos.webtest.struct.Frame;
import holmos.webtest.struct.Page;
import java.util.ArrayList;
import com.thoughtworks.selenium.Selenium;
public class SeleniumElementExist extends WebElementExist{
private String currentLocator;
private ArrayListlocators=new ArrayList();
private Selenium selenium=(Selenium) Allocator.getInstance().currentWindow.getDriver().getEngine();
public SeleniumElementExist(LocatorValue webElement){
super(webElement);
}
@Override
public boolean isElementExistForCheckOnce(){
LocatorValue lastNode=infoChain.getInfoNodes().get(infoChain.getInfoNodes().size()-1);
if(lastNode instanceof Page || lastNode instanceof Frame){
return findOneLevelElement(1);
}else{
return findMuiltiLevelElement(1);
}
}
@Override
public boolean isElementExist(int waitCount) {
initComment();
LocatorValue lastNode=infoChain.getInfoNodes().get(infoChain.getInfoNodes().size()-1);
if(lastNode instanceof Page || lastNode instanceof Frame){
return findOneLevelElement(waitCount);
}else{
return findMuiltiLevelElement(waitCount);
}
}
private boolean findMuiltiLevelElement(int waitCount) {
for(int i=0;i1;startLevel--){
if(infoChain.getInfoNodes().get(startLevel) instanceof Frame){
//找到Frame层级,跳到下一层
startLevel++;
break;
}
}
infoChain.addNode(webElement);
getAllLocaors(startLevel,"");
for(int i=0;i=infoChain.getInfoNodes().size())return;
if(level==infoChain.getInfoNodes().size()-1){
if(locator.getLocatorById()!=null&&locator.getLocatorById()!=""){
locatorTemp+=(locator.getXpathFromId());
locators.add(locatorTemp);
}if(locator.getLocatorByName()!=null&&locator.getLocatorByName()!=""){
locatorTemp+=locator.getXpathFromName();
locators.add(locatorTemp);
}if(locator.getLocatorByXpath()!=null&&locator.getLocatorByXpath()!=""){
locatorTemp+=locator.getLocatorByXpath();
locators.add(locatorTemp);
}if(locator.getLocatorByLinkText()!=null&&locator.getLocatorByLinkText()!=""){
locatorTemp+=locator.getXpathFromLinkText();
locators.add(locatorTemp);
}if(locator.getLocatorByPartialLinkText()!=null&&locator.getLocatorByPartialLinkText()!=""){
locatorTemp+=locator.getXpathFromPartialLinkText();
locators.add(locatorTemp);
}
}else{
Locator locatorCurrent=infoChain.getInfoNodes().get(level).getLocator();
if(locatorCurrent.getLocatorById()!=null&&locatorCurrent.getLocatorById()!=""){
locatorTemp=locatorTemp+locator.getXpathFromId();
if(infoChain.getInfoNodes().get(level) instanceof Collection){
locatorTemp+="["+((Collection)infoChain.getInfoNodes().get(level)).getIndex()+"]";
}
getAllLocaors(level+1,locatorTemp);
}if(locatorCurrent.getLocatorByName()!=null&&locatorCurrent.getLocatorByName()!=""){
locatorTemp=locatorTemp+locator.getXpathFromName();
if(infoChain.getInfoNodes().get(level) instanceof Collection){
locatorTemp+="["+((Collection)infoChain.getInfoNodes().get(level)).getIndex()+"]";
}
getAllLocaors(level+1,locatorTemp);
}if(locatorCurrent.getLocatorByXpath()!=null&&locatorCurrent.getLocatorByXpath()!=""){
locatorTemp=locatorTemp+locator.getLocatorByXpath();
if(infoChain.getInfoNodes().get(level) instanceof Collection){
locatorTemp+="["+((Collection)infoChain.getInfoNodes().get(level)).getIndex()+"]";
}
getAllLocaors(level+1,locatorTemp);
}if(locatorCurrent.getLocatorByLinkText()!=null&&locatorCurrent.getLocatorByLinkText()!=""){
locatorTemp=locatorTemp+locator.getXpathFromLinkText();
if(infoChain.getInfoNodes().get(level) instanceof Collection){
locatorTemp+="["+((Collection)infoChain.getInfoNodes().get(level)).getIndex()+"]";
}
getAllLocaors(level+1,locatorTemp);
}if(locatorCurrent.getLocatorByPartialLinkText()!=null&&locatorCurrent.getLocatorByPartialLinkText()!=""){
locatorTemp=locatorTemp+locator.getXpathFromPartialLinkText();
if(infoChain.getInfoNodes().get(level) instanceof Collection){
locatorTemp+="["+((Collection)infoChain.getInfoNodes().get(level)).getIndex()+"]";
}
getAllLocaors(level+1,locatorTemp);
}
}
}
private boolean findOneLevelElement(int waitCount) {
for(int i=0;i