Uyisebenzisa kanjani i-WebDriver kwimo engenintloko

Uyisebenzisa kanjani iWebDriver kwimowudi engenentloko? Oku kunokufuneka ukuba isixhobo sakho se-CI, umzekelo, iJenkins ayixhasi i-UI.

Ukuqhutywa kovavanyo oluzenzekelayo lweWebDriver kwimowudi engenentloko kunika izibonelelo ngokubhekisele kwisantya sokwenziwa kovavanyo kunye nokudityaniswa ngokulula kumbhobho weCI.

Kule tutorial, siya kusebenzisa i-PhantomJS kunye ne-ChromeDriver ukuqhuba iimvavanyo zeSelenium WebDriver kwimowudi engenentloko.




PhantomJS

Ukuqhuba iimvavanyo zeSelenium WebDriver kwimowudi engenentloko usebenzisa iPhomomJS, kufuneka kuqala ukhuphele Ifayile yeFantomJS ephumelelayo kwaye uyigcine kwindawo, o.k.t. ifolda yezixhobo zeprojekthi yakho.

Kumzekelo ongezantsi, ndibeke i-PhantomJS ephunyeziweyo kwi-src / test / resources / phantomjs


Uya kudinga ukuxhomekeka kwabaqhubi besiporho:

com.github.detro.ghostdriver phantomjsdriver 1.0.1

Kwaye iklasi yakho yeJava:

import org.openqa.selenium.phantomjs.PhantomJSDriver; import org.openqa.selenium.phantomjs.PhantomJSDriverService; import org.openqa.selenium.remote.DesiredCapabilities; public class WebDriverBase {
static protected WebDriver driver;

public static void setup() {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true); // not really needed: JS enabled by default
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, 'src/test/resources/phantomjs');

driver = new PhantomJSDriver(caps);
}

public static void main(String[] args) {
WebDriverBase.setup();
driver.get('https://devqa.io');
} }


ChromeDriver

Ukuqhuba iimvavanyo zeWebDriver kwimowudi engenentloko usebenzisa iChannelDriver, kuyakufuneka ukongeze ukuxhomekeka okufanelekileyo kwifayile yakho ye-pom.xml:


org.seleniumhq.selenium
selenium-chrome-driver
${selenium.version}
org.seleniumhq.selenium
selenium-server
${selenium.version}
org.seleniumhq.selenium
selenium-java
${selenium.version}
io.github.bonigarcia
webdrivermanager
${webdrivermanager.version}

Emva koko, siyalela umphathi weWebDriver ukuba asungule umqhubi we-chrome kwimowudi engenentloko


import io.github.bonigarcia.wdm.ChromeDriverManager; import org.openqa.selenium.chrome.ChromeDriver; public class WebDriverBase {
static protected WebDriver driver;
public static void setup() {
ChromeDriverManager.getInstance().setup();
ChromeOptions chromeOptions = new ChromeOptions();

chromeOptions.addArguments('--headless');
driver = new ChromeDriver(chromeOptions);
}
public static void main(String[] args) {
WebDriverBase.setup();
driver.get('https://devqa.io');
} }