WebDriver Yakajeka, Yakajeka uye Inonzwisisika Mirira Mienzaniso

Ndeupi musiyano uripo pakati pekumirira izere, kujekesa kumirira uye kutsetsenura kumirira muWebDriver? Zvikurukuru, chii chiri hukama pakati peWebDriverWait neFluentWait?

Heino mienzaniso yekushandisa yega nzira yekumirira muWebDriver neJava.

Zvese Mirira

An kumirira ndeyekuudza WebDriver kuti aongorore iyo DOM kune imwe nguva yenguva kana uchiedza kutsvaga chinhu kana zvinhu kana zvikasanowanikwa ipapo. Iyo yekumisikidza yekugadzika iri 0. Kana yangoiswa, iyo isingamiriri inomirira yakagadzirirwa hupenyu hweWebDriver chinhu semuenzaniso.

Muenzaniso wekushandisa zvachose kumirira

WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get('http://somedomain/slow_loading_url'); WebElement dynamicElement = driver.findElement(By.id('dynamicElement'));

Tinofanira kushandisa riini kumirira?

Kazhinji, hazvikurudzirwe kushandisa zvirevo zvakamirira, apo isu patinogona kushandisa yakajeka kumirira kana kutsetsenura kumirira.



Yakajeka Mirira

An kujekesa kumirira kodhi iyo iwe yaunotsanangudza kumirira kuti imwe mamiriro ezvinhu iitwe usati waenderera kumberi mune iyo kodhi. WebDriverWait nekumira inodaidza iyo InotarisirwaCondition yega yega ma500 milliseconds kusvikira yadzoka zvinobudirira.

Semuenzaniso wekushandisa yakajeka kumirira

WebDriver driver = new FirefoxDriver(); driver.get('http://somedomain/someurl'); WebElement dynamicElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.id('dynamicElement')));

Tinofanira kushandisa riinhi kumirira?

Isu tinowanzo shandisa yakajeka kumirira kana chinhu chikatora nguva yakareba kurongedza. Isu takashandisawo yakajeka kumirira kutarisa CSS chivakwa chechinhu (kuvapo, kubatika. Nezvimwewo) izvo zvinogona kuchinja muAjax kunyorera.

Kunzwisisa Mirira

Kana tichishandisa iyo FluentWait semuenzaniso, tinogona kudoma:

  • Iyo frequency iyo FluentWait inofanirwa kutarisa mamiriro akatsanangurwa.
  • Regedza chaiwo marudzi ekusarudzika akamirira senge NoSuchElementExceptions uchitsvaga chinhu pane peji.
  • Iyo yakanyanya kuwanda nguva yekumirira mamiriro

Semuenzaniso wekushandisa FluentWait

// Waiting 30 seconds for an element to be present on the page, checking // for its presence once every 5 seconds. Wait wait = new FluentWait(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class); WebElement foo = wait.until(new Function() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id('foo')); } });

Tinofanira kushandisa rini FluentWait?

Paunoyedza kuyedza kuvepo kwechimwe chinhu chinogona kuoneka mushure memasekondi / maminetsi ega ega.

Musiyano Pakati peWebDriverWait uye FluentWait

WebDriverWait chidimbu cheFluentWait. MuFluentWait iwe une dzimwe sarudzo dzekumisikidza, pamwe neyakanyanya nguva yekumirira, senge nguva yekuvhota, kunze kwekuregeredza nezvimwe.

Saka, pachinzvimbo chekumirira wozoshandisa findElement:

WebDriverWait wait = new WebDriverWait(driver, 18); wait.until(ExpectedConditions.elementToBeClickable(By.linkText('Account'))); WebElement element = driver.findElement(By.linkText('Account')); element.sendKeys(Keys.CONTROL); element.click();

tinogona kushandisa:

WebElement element = wait.until(
ExpectedConditions.elementToBeClickable(By.linkText('Account')));

Kuenderera mberi nekuverenga: