How to use createRemoteWebDriver method of com.consol.citrus.selenium.endpoint.SeleniumBrowser class

Best Citrus code snippet using com.consol.citrus.selenium.endpoint.SeleniumBrowser.createRemoteWebDriver

Source:SeleniumBrowser.java Github

copy

Full Screen

...87 if (!isStarted()) {88 if (getEndpointConfiguration().getWebDriver() != null) {89 webDriver = getEndpointConfiguration().getWebDriver();90 } else if (StringUtils.hasText(getEndpointConfiguration().getRemoteServerUrl())) {91 webDriver = createRemoteWebDriver(getEndpointConfiguration().getBrowserType(), getEndpointConfiguration().getRemoteServerUrl());92 } else {93 webDriver = createLocalWebDriver(getEndpointConfiguration().getBrowserType());94 }95 if (!CollectionUtils.isEmpty(getEndpointConfiguration().getEventListeners())) {96 EventFiringWebDriver wrapper = new EventFiringWebDriver(webDriver);97 log.info("Add event listeners to web driver: " + getEndpointConfiguration().getEventListeners().size());98 for (WebDriverEventListener listener : getEndpointConfiguration().getEventListeners()) {99 wrapper.register(listener);100 }101 }102 } else {103 log.warn("Browser already started");104 }105 }106 /**107 * Stop the browser when started.108 */109 public void stop() {110 if (isStarted()) {111 log.info("Stopping browser " + webDriver.getCurrentUrl());112 try {113 log.info("Trying to close the browser " + webDriver + " ...");114 webDriver.quit();115 } catch (UnreachableBrowserException e) {116 // It happens for Firefox. It's ok: browser is already closed.117 log.warn("Browser is unreachable", e);118 } catch (WebDriverException e) {119 log.error("Failed to close browser", e);120 }121 webDriver = null;122 } else {123 log.warn("Browser already stopped");124 }125 }126 /**127 * Deploy resource object from resource folder and return path of deployed128 * file129 *130 * @param fileLocation Resource to deploy to temporary storage131 * @return String containing the filename to which the file is uploaded to.132 */133 public String storeFile(String fileLocation) {134 return storeFile(new PathMatchingResourcePatternResolver().getResource(fileLocation));135 }136 /**137 * Deploy resource object from resource folder and return path of deployed138 * file139 *140 * @param file Resource to deploy to temporary storage141 * @return String containing the filename to which the file is uploaded to.142 */143 public String storeFile(Resource file) {144 try {145 File newFile = new File(temporaryStorage.toFile(), file.getFilename());146 log.info("Store file " + file + " to " + newFile);147 FileUtils.copyFile(file.getFile(), newFile);148 return newFile.getCanonicalPath();149 } catch (IOException e) {150 throw new CitrusRuntimeException("Failed to store file: " + file, e);151 }152 }153 /**154 * Retrieve resource object155 *156 * @param filename Resource to retrieve.157 * @return String with the path to the resource.158 */159 public String getStoredFile(String filename) {160 try {161 File stored = new File(temporaryStorage.toFile(), filename);162 if (!stored.exists()) {163 throw new CitrusRuntimeException("Failed to access stored file: " + stored.getCanonicalPath());164 }165 return stored.getCanonicalPath();166 } catch (IOException e) {167 throw new CitrusRuntimeException("Failed to retrieve file: " + filename, e);168 }169 }170 /**171 * Creates local web driver.172 * @param browserType173 * @return174 */175 private WebDriver createLocalWebDriver(String browserType) {176 switch (browserType) {177 case BrowserType.FIREFOX:178 FirefoxProfile firefoxProfile = getEndpointConfiguration().getFirefoxProfile();179 /* set custom download folder */180 firefoxProfile.setPreference("browser.download.dir", temporaryStorage.toFile().getAbsolutePath());181 DesiredCapabilities defaults = DesiredCapabilities.firefox();182 defaults.setCapability(FirefoxDriver.PROFILE, firefoxProfile);183 return new FirefoxDriver(defaults);184 case BrowserType.IE:185 return new InternetExplorerDriver();186 case BrowserType.EDGE:187 return new EdgeDriver();188 case BrowserType.SAFARI:189 return new SafariDriver();190 case BrowserType.CHROME:191 return new ChromeDriver();192 case BrowserType.GOOGLECHROME:193 return new ChromeDriver();194 case BrowserType.HTMLUNIT:195 BrowserVersion browserVersion = null;196 if (getEndpointConfiguration().getVersion().equals("FIREFOX")) {197 browserVersion = BrowserVersion.FIREFOX_45;198 } else if (getEndpointConfiguration().getVersion().equals("INTERNET_EXPLORER")) {199 browserVersion = BrowserVersion.INTERNET_EXPLORER;200 } else if (getEndpointConfiguration().getVersion().equals("EDGE")) {201 browserVersion = BrowserVersion.EDGE;202 } else if (getEndpointConfiguration().getVersion().equals("CHROME")) {203 browserVersion = BrowserVersion.CHROME;204 }205 HtmlUnitDriver htmlUnitDriver;206 if (browserVersion != null) {207 htmlUnitDriver = new HtmlUnitDriver(browserVersion);208 } else {209 htmlUnitDriver = new HtmlUnitDriver();210 }211 htmlUnitDriver.setJavascriptEnabled(getEndpointConfiguration().isJavaScript());212 return htmlUnitDriver;213 default:214 throw new CitrusRuntimeException("Unsupported local browser type: " + browserType);215 }216 }217 /**218 * Creates remote web driver.219 * @param browserType220 * @param serverAddress221 * @return222 * @throws MalformedURLException223 */224 private RemoteWebDriver createRemoteWebDriver(String browserType, String serverAddress) {225 try {226 switch (browserType) {227 case BrowserType.FIREFOX:228 DesiredCapabilities defaultsFF = DesiredCapabilities.firefox();229 defaultsFF.setCapability(FirefoxDriver.PROFILE, getEndpointConfiguration().getFirefoxProfile());230 return new RemoteWebDriver(new URL(serverAddress), defaultsFF);231 case BrowserType.IE:232 DesiredCapabilities defaultsIE = DesiredCapabilities.internetExplorer();233 defaultsIE.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);234 return new RemoteWebDriver(new URL(serverAddress), defaultsIE);235 case BrowserType.CHROME:236 DesiredCapabilities defaultsChrome = DesiredCapabilities.chrome();237 defaultsChrome.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);238 return new RemoteWebDriver(new URL(serverAddress), defaultsChrome);...

Full Screen

Full Screen

createRemoteWebDriver

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.design.TestDesigner2import com.consol.citrus.dsl.design.TestDesignerSupport3import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner4import com.consol.citrus.selenium.endpoint.SeleniumBrowser5import org.openqa.selenium.remote.DesiredCapabilities6import org.openqa.selenium.remote.RemoteWebDriver7import org.springframework.beans.factory.annotation.Autowired8import org.springframework.beans.factory.annotation.Qualifier9import org.testng.annotations.Test10class SeleniumTest extends TestNGCitrusTestDesigner {11 @Qualifier("seleniumBrowser")12 void configure() {13 selenium().browser(seleniumBrowser)14 .start()15 selenium().browser(seleniumBrowser)16 selenium().browser(seleniumBrowser)17 .click("link=Documentation")18 selenium().browser(seleniumBrowser)19 .click("link=Reference Manual")20 selenium().browser(seleniumBrowser)21 .click("link=TestNG Support")22 selenium().browser(seleniumBrowser)23 .click("link=TestNG Citrus Test Designer")24 selenium().browser(seleniumBrowser)25 .stop()26 }27}

Full Screen

Full Screen

createRemoteWebDriver

Using AI Code Generation

copy

Full Screen

1import static com.consol.citrus.selenium.actions.SeleniumActionBuilder.*;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import com.consol.citrus.selenium.endpoint.SeleniumBrowser;4import org.openqa.selenium.By;5import org.openqa.selenium.remote.DesiredCapabilities;6import org.testng.annotations.Test;7public class SeleniumRemoteTest extends TestNGCitrusTestDesigner {8 public void configure() {9 selenium().browser(SeleniumBrowser.createRemoteWebDriver()10 .desiredCapabilities(DesiredCapabilities.chrome()))11 .start();12 selenium().element(By.name("q"))13 .type("Citrus Framework");14 selenium().element(By.name("btnK"))15 .click();16 selenium().stop();17 }18}19import static com.consol.citrus.selenium.actions.SeleniumActionBuilder.*;20import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;21import com.consol.citrus.selenium.endpoint.SeleniumBrowser;22import org.openqa.selenium.By;23import org.openqa.selenium.remote.DesiredCapabilities;24import org.testng.annotations.Test;25public class SeleniumRemoteTest extends TestNGCitrusTestDesigner {26 public void configure() {27 selenium().browser(SeleniumBrowser.createRemoteWebDriver()28 .desiredCapabilities(DesiredCapabilities.chrome()))29 .start();30 selenium().element(By.name("q"))31 .type("Citrus Framework");32 selenium().element(By.name("btnK"))33 .click();34 selenium().stop();35 }36}37Tip: If you are using the SeleniumBrowser.createRemoteWebDriver() method, you do not have to set the browserName property of the desired capabilities. This property is set

Full Screen

Full Screen

createRemoteWebDriver

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.selenium.endpoint.SeleniumBrowser2import com.consol.citrus.selenium.endpoint.SeleniumHeaders3SeleniumBrowser browser = new SeleniumBrowser()4browser.setBrowserName("chrome")5browser.setBrowserVersion("latest")6browser.setPlatform("WINDOWS")7browser.setCapability("enableVNC", true)8browser.setCapability("enableVideo", true)9browser.setCapability("enableLog", true)10browser.setCapability("enableNetwork", true)11browser.setCapability("enableTimeline", true)12WebDriver driver = browser.createRemoteWebDriver()13SeleniumHeaders headers = new SeleniumHeaders()14headers.setBrowserName("chrome")15headers.setBrowserVersion("latest")16headers.setPlatform("WINDOWS")17headers.setCapability("enableVNC", true)18headers.setCapability("enableVideo", true)19headers.setCapability("enableLog", true)20headers.setCapability("enableNetwork", true)21headers.setCapability("enableTimeline", true)22WebDriver driver = browser.createRemoteWebDriver(headers)23SeleniumHeaders headers = new SeleniumHeaders()24headers.setBrowserName("chrome")25headers.setBrowserVersion("latest")26headers.setPlatform("WINDOWS")27headers.setCapability("enableVNC", true)28headers.setCapability("enableVideo", true)29headers.setCapability("enableLog", true)30headers.setCapability("enableNetwork", true)31headers.setCapability("enableTimeline", true)32WebDriver driver = browser.createRemoteWebDriver(headers)33SeleniumHeaders headers = new SeleniumHeaders()34headers.setBrowserName("chrome")35headers.setBrowserVersion("latest")36headers.setPlatform("WINDOWS")37headers.setCapability("enableVNC", true)38headers.setCapability("enableVideo", true)39headers.setCapability("enableLog", true)40headers.setCapability("enableNetwork", true)41headers.setCapability("enableTimeline", true)42WebDriver driver = browser.createRemoteWebDriver(headers)43SeleniumHeaders headers = new SeleniumHeaders()44headers.setBrowserName("chrome

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful