How to use clientFactory method of com.intuit.karate.Runner class

Best Karate code snippet using com.intuit.karate.Runner.clientFactory

Source:Runner.java Github

copy

Full Screen

...162 List<Feature> features;163 String relativeTo;164 final Collection<RuntimeHook> hooks = new ArrayList();165 RuntimeHookFactory hookFactory;166 HttpClientFactory clientFactory;167 boolean forTempUse;168 boolean backupReportDir = true;169 boolean outputHtmlReport = true;170 boolean outputJunitXml;171 boolean outputCucumberJson;172 boolean dryRun;173 boolean debugMode;174 Map<String, String> systemProperties;175 Map<String, Object> callSingleCache;176 Map<String, ScenarioCall.Result> callOnceCache;177 SuiteReports suiteReports;178 JobConfig jobConfig;179 Map<String, DriverRunner> drivers;180 // synchronize because the main user is karate-gatling181 public synchronized Builder copy() {182 Builder b = new Builder();183 b.classLoader = classLoader;184 b.optionsClass = optionsClass;185 b.env = env;186 b.workingDir = workingDir;187 b.buildDir = buildDir;188 b.configDir = configDir;189 b.threadCount = threadCount;190 b.timeoutMinutes = timeoutMinutes;191 b.reportDir = reportDir;192 b.scenarioName = scenarioName;193 b.tags = tags;194 b.paths = paths;195 b.features = features;196 b.relativeTo = relativeTo;197 b.hooks.addAll(hooks); // final198 b.hookFactory = hookFactory;199 b.clientFactory = clientFactory;200 b.forTempUse = forTempUse;201 b.backupReportDir = backupReportDir;202 b.outputHtmlReport = outputHtmlReport;203 b.outputJunitXml = outputJunitXml;204 b.outputCucumberJson = outputCucumberJson;205 b.dryRun = dryRun;206 b.debugMode = debugMode;207 b.systemProperties = systemProperties;208 b.callSingleCache = callSingleCache;209 b.callOnceCache = callOnceCache;210 b.suiteReports = suiteReports;211 b.jobConfig = jobConfig;212 b.drivers = drivers;213 return b;214 }215 public List<Feature> resolveAll() {216 if (classLoader == null) {217 classLoader = Thread.currentThread().getContextClassLoader();218 }219 if (clientFactory == null) {220 clientFactory = HttpClientFactory.DEFAULT;221 }222 if (systemProperties == null) {223 systemProperties = new HashMap(System.getProperties());224 } else {225 systemProperties.putAll(new HashMap(System.getProperties()));226 }227 // env228 String tempOptions = StringUtils.trimToNull(systemProperties.get(Constants.KARATE_OPTIONS));229 if (tempOptions != null) {230 LOGGER.info("using system property '{}': {}", Constants.KARATE_OPTIONS, tempOptions);231 Main ko = Main.parseKarateOptions(tempOptions);232 if (ko.tags != null) {233 tags = ko.tags;234 }235 if (ko.paths != null) {236 paths = ko.paths;237 }238 dryRun = ko.dryRun || dryRun;239 }240 String tempEnv = StringUtils.trimToNull(systemProperties.get(Constants.KARATE_ENV));241 if (tempEnv != null) {242 LOGGER.info("using system property '{}': {}", Constants.KARATE_ENV, tempEnv);243 env = tempEnv;244 } else if (env != null) {245 LOGGER.info("karate.env is: '{}'", env);246 }247 // config dir248 String tempConfig = StringUtils.trimToNull(systemProperties.get(Constants.KARATE_CONFIG_DIR));249 if (tempConfig != null) {250 LOGGER.info("using system property '{}': {}", Constants.KARATE_CONFIG_DIR, tempConfig);251 configDir = tempConfig;252 }253 if (workingDir == null) {254 workingDir = FileUtils.WORKING_DIR;255 }256 if (configDir == null) {257 try {258 ResourceUtils.getResource(workingDir, "classpath:karate-config.js");259 configDir = "classpath:"; // default mode260 } catch (Exception e) {261 configDir = workingDir.getPath();262 }263 }264 if (configDir.startsWith("file:") || configDir.startsWith("classpath:")) {265 // all good266 } else {267 configDir = "file:" + configDir;268 }269 if (configDir.endsWith(":") || configDir.endsWith("/") || configDir.endsWith("\\")) {270 // all good271 } else {272 configDir = configDir + File.separator;273 }274 if (buildDir == null) {275 buildDir = FileUtils.getBuildDir();276 }277 if (reportDir == null) {278 reportDir = buildDir + File.separator + Constants.KARATE_REPORTS;279 }280 // hooks281 if (hookFactory != null) {282 hook(hookFactory.create());283 }284 // features285 if (features == null) {286 if (paths != null && !paths.isEmpty()) {287 if (relativeTo != null) {288 paths = paths.stream().map(p -> {289 if (p.startsWith("classpath:")) {290 return p;291 }292 if (!p.endsWith(".feature")) {293 p = p + ".feature";294 }295 return relativeTo + "/" + p;296 }).collect(Collectors.toList());297 }298 } else if (relativeTo != null) {299 paths = new ArrayList();300 paths.add(relativeTo);301 }302 features = ResourceUtils.findFeatureFiles(workingDir, paths);303 }304 if (scenarioName != null) {305 for (Feature feature : features) {306 feature.setCallName(scenarioName);307 }308 }309 if (callSingleCache == null) {310 callSingleCache = new HashMap();311 }312 if (callOnceCache == null) {313 callOnceCache = new HashMap();314 }315 if (suiteReports == null) {316 suiteReports = SuiteReports.DEFAULT;317 }318 if (drivers != null) {319 Map<String, DriverRunner> customDrivers = drivers;320 drivers = DriverOptions.driverRunners();321 drivers.putAll(customDrivers); // allows override of Karate drivers (e.g. custom 'chrome')322 } else {323 drivers = DriverOptions.driverRunners();324 }325 if (jobConfig != null) {326 reportDir = jobConfig.getExecutorDir();327 if (threadCount < 1) {328 threadCount = jobConfig.getExecutorCount();329 }330 timeoutMinutes = jobConfig.getTimeoutMinutes();331 }332 if (threadCount < 1) {333 threadCount = 1;334 }335 return features;336 }337 protected T forTempUse() {338 forTempUse = true;339 return (T) this;340 }341 //======================================================================342 //343 public T configDir(String dir) {344 this.configDir = dir;345 return (T) this;346 }347 public T karateEnv(String env) {348 this.env = env;349 return (T) this;350 }351 public T systemProperty(String key, String value) {352 if (systemProperties == null) {353 systemProperties = new HashMap();354 }355 systemProperties.put(key, value);356 return (T) this;357 }358 public T workingDir(File value) {359 if (value != null) {360 this.workingDir = value;361 }362 return (T) this;363 }364 public T buildDir(String value) {365 if (value != null) {366 this.buildDir = value;367 }368 return (T) this;369 }370 public T classLoader(ClassLoader value) {371 classLoader = value;372 return (T) this;373 }374 public T relativeTo(Class clazz) {375 relativeTo = "classpath:" + ResourceUtils.toPathFromClassPathRoot(clazz);376 return (T) this;377 }378 /**379 * @see com.intuit.karate.Runner#builder()380 * @deprecated381 */382 @Deprecated383 public T fromKarateAnnotation(Class<?> clazz) {384 KarateOptions ko = clazz.getAnnotation(KarateOptions.class);385 if (ko != null) {386 LOGGER.warn("the @KarateOptions annotation is deprecated, please use Runner.builder()");387 if (ko.tags().length > 0) {388 tags = Arrays.asList(ko.tags());389 }390 if (ko.features().length > 0) {391 paths = Arrays.asList(ko.features());392 }393 }394 return relativeTo(clazz);395 }396 public T path(String... value) {397 path(Arrays.asList(value));398 return (T) this;399 }400 public T path(List<String> value) {401 if (value != null) {402 if (paths == null) {403 paths = new ArrayList();404 }405 paths.addAll(value);406 }407 return (T) this;408 }409 public T tags(List<String> value) {410 if (value != null) {411 if (tags == null) {412 tags = new ArrayList();413 }414 tags.addAll(value);415 }416 return (T) this;417 }418 public T tags(String... tags) {419 tags(Arrays.asList(tags));420 return (T) this;421 }422 public T features(Collection<Feature> value) {423 if (value != null) {424 if (features == null) {425 features = new ArrayList();426 }427 features.addAll(value);428 }429 return (T) this;430 }431 public T features(Feature... value) {432 return features(Arrays.asList(value));433 }434 public T reportDir(String value) {435 if (value != null) {436 this.reportDir = value;437 }438 return (T) this;439 }440 public T scenarioName(String name) {441 this.scenarioName = name;442 return (T) this;443 }444 public T timeoutMinutes(int timeoutMinutes) {445 this.timeoutMinutes = timeoutMinutes;446 return (T) this;447 }448 public T hook(RuntimeHook hook) {449 if (hook != null) {450 hooks.add(hook);451 }452 return (T) this;453 }454 public T hooks(Collection<RuntimeHook> hooks) {455 if (hooks != null) {456 this.hooks.addAll(hooks);457 }458 return (T) this;459 }460 public T hookFactory(RuntimeHookFactory hookFactory) {461 this.hookFactory = hookFactory;462 return (T) this;463 }464 public T clientFactory(HttpClientFactory clientFactory) {465 this.clientFactory = clientFactory;466 return (T) this;467 }468 // don't allow junit 5 builder to run in parallel469 public Builder threads(int value) {470 threadCount = value;471 return this;472 }473 public T outputHtmlReport(boolean value) {474 outputHtmlReport = value;475 return (T) this;476 }477 public T backupReportDir(boolean value) {478 backupReportDir = value;479 return (T) this;...

Full Screen

Full Screen

Source:TestUtils.java Github

copy

Full Screen

...48 Feature feature = toFeature("* print 'test'");49 FeatureRuntime fr = FeatureRuntime.of(feature);50 return new ScenarioIterator(fr).first();51 }52 public static ScenarioRuntime runScenario(HttpClientFactory clientFactory, String... lines) {53 return run(clientFactory, toFeature(lines));54 }55 public static ScenarioRuntime run(HttpClientFactory clientFactory, Feature feature) {56 Runner.Builder builder = Runner.builder();57 builder.clientFactory(clientFactory);58 String configDir = System.getProperty("karate.config.dir");59 if (configDir != null) {60 builder.configDir = configDir;61 }62 FeatureRuntime fr = FeatureRuntime.of(new Suite(builder), feature);63 ScenarioRuntime sr = new ScenarioIterator(fr).first();64 sr.run();65 return sr;66 }67 public static FeatureRuntime runFeature(String path) {68 return runFeature(path, null);69 }70 public static FeatureRuntime runFeature(String path, String configDir) {71 Map<String, DriverRunner> customDrivers = new HashMap<>();...

Full Screen

Full Screen

clientFactory

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.Runner;2import com.intuit.karate.Results;3import com.intuit.karate.Runner.Builder;4import com.intuit.karate.netty.FeatureServer;5import java.util.List;6import java.util.Map;7import java.util.HashMap;8import java.util.ArrayList;9import java.util.Arrays;10import java.util.Collections;11import java.util.concurrent.Callable;12import java.util.concurrent.Future;13import java.util.concurrent.ExecutorService;14import java.util.concurrent.Executors;15import java.util.concurrent.TimeUnit;16import java.util.concurrent.ExecutionException;17import com.intuit.karate.netty.FeatureClient;18import com.intuit.karate.netty.FeatureClientFactory;19import com.intuit.karate.netty.FeatureClientConfig;20import com.intuit.karate.netty.FeatureClientConfigBuilder;21import org.slf4j.Logger;22import org.slf4j.LoggerFactory;23import java.util.concurrent.atomic.AtomicInteger;24import java.util.concurrent.atomic.AtomicLong;25import java.util.concurrent.atomic.AtomicBoolean;26import java.util.concurrent.atomic.AtomicReference;27import java.util.concurrent.locks.ReentrantLock;28import java.util.concurrent.locks.Lock;29import java.util.concurrent.locks.Condition;30import java.util.concurrent.Semaphore;31import java.util.concurrent.CountDownLatch;32import java.util.concurrent.CyclicBarrier;33import java.util.concurrent.Phaser;34import java.util.concurrent.ThreadLocalRandom;35import java.util.concurrent.ThreadFactory;36import java.util.concurrent.ThreadPoolExecutor;37import java.util.concurrent.RejectedExecutionHandler;38import java.util.concurrent.Executors;39import java.util.concurrent.ExecutorService;40import java.util.concurrent.Executor;41import java.util.concurrent.Callable;42import java.util.concurrent.Future;43import java.util.concurrent.TimeUnit;44import java.util.concurrent.TimeoutException;45import java.util.concurrent.ExecutionException;46import java.util.concurrent.atomic.AtomicBoolean;47import java.util.concurrent.atomic.AtomicInteger;48import java.util.concurrent.atomic.AtomicLong;49import java.util.concurrent.atomic.AtomicReference;50import java.util.concurrent.locks.ReentrantLock;51import java.util.concurrent.locks.Lock;52import java.util.concurrent.locks.Condition;53import java.util.concurrent.Semaphore;54import java.util.concurrent.CountDownLatch;55import java.util.concurrent.CyclicBarrier;56import java.util.concurrent.Phaser;57import java.util.concurrent.ThreadLocalRandom;58import java.util.concurrent.ThreadFactory;59import java.util.concurrent.ThreadPoolExecutor;60import java.util.concurrent.RejectedExecutionHandler;61import java.util.concurrent.Executors;62import java.util.concurrent.ExecutorService;63import java.util.concurrent.Executor;64import java.util.concurrent.Callable;65import java.util

Full Screen

Full Screen

clientFactory

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.Runner;2import com.intuit.karate.Results;3import com.intuit.karate.Runner.Builder;4import java.util.List;5import java.util.ArrayList;6public class 4 {7 public static void main(String[] args) {8 List<String> tags = new ArrayList<String>();9 tags.add("api");10 Builder builder = Runner.builder();11 builder.tags(tags);12 builder.outputCucumberJson(true);13 Results results = Runner.parallel(builder, 1, "classpath:com/intuit/karate/demo");14 System.exit(results.getFailCount());15 }16}17import com.intuit.karate.Runner;18import com.intuit.karate.Results;19import com.intuit.karate.Runner.Builder;20import java.util.List;21import java.util.ArrayList;22public class 5 {23 public static void main(String[] args) {24 List<String> tags = new ArrayList<String>();25 tags.add("api");26 Builder builder = Runner.builder();27 builder.tags(tags);28 builder.outputCucumberJson(true);29 Results results = Runner.parallel(builder, 2, "classpath:com/intuit/karate/demo");30 System.exit(results.getFailCount());31 }32}33import com.intuit.karate.Runner;34import com.intuit.karate.Results;35import com.intuit.karate.Runner.Builder;36import java.util.List;37import java.util.ArrayList;38public class 6 {39 public static void main(String[] args) {40 List<String> tags = new ArrayList<String>();41 tags.add("api");42 Builder builder = Runner.builder();43 builder.tags(tags);44 builder.outputCucumberJson(true);45 Results results = Runner.parallel(builder, 3, "classpath:com/intuit/karate/demo");46 System.exit(results.getFailCount());47 }48}49import com.intuit.karate.Runner;50import com.intuit.karate.Results;51import com.intuit.karate.Runner.Builder;52import java.util.List;53import java.util.ArrayList;54public class 7 {55 public static void main(String

Full Screen

Full Screen

clientFactory

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.Runner;2import com.intuit.karate.Results;3import java.io.File;4import java.util.ArrayList;5import java.util.Collection;6import java.util.List;7import java.util.Map;8import java.util.HashMap;9import java.util.concurrent.ConcurrentHashMap;10import java.util.concurrent.ConcurrentMap;11import org.slf4j.Logger;12import org.slf4j.LoggerFactory;13import org.apache.commons.io.FileUtils;14import org.apache.commons.io.filefilter.WildcardFileFilter;15import org.apache.commons.io.filefilter.FileFilterUtils;16import org.apache.commons.io.filefilter.TrueFileFilter;17import org.apache.commons.io.filefilter.SuffixFileFilter;18import org.apache.commons.io.filefilter.IOFileFilter;19import java.io.File;20import java.io.IOException;21import java.util.ArrayList;22import java.util.Collection;23import java.util.List;24import org.apache.commons.io.FileUtils;25import org.apache.commons.io.filefilter.WildcardFileFilter;26import org.apache.commons.io.filefilter.FileFilterUtils;27import org.apache.commons.io.filefilter.TrueFileFilter;28import org.apache.commons.io.filefilter.SuffixFileFilter;29import org.apache.commons.io.filefilter.IOFileFilter;30public class 4 {31 private static final Logger logger = LoggerFactory.getLogger(4.class);32 public static void main(String[] args) {33 String path = "C:\\Users\\karate\\Desktop\\karate\\karate-demo";34 String reportsPath = "C:\\Users\\karate\\Desktop\\karate\\karate-demo\\target\\surefire-reports";35 String logsPath = "C:\\Users\\karate\\Desktop\\karate\\karate-demo\\target\\surefire-reports\\logs";36 String htmlPath = "C:\\Users\\karate\\Desktop\\karate\\karate-demo\\target\\surefire-reports\\html";37 String xmlPath = "C:\\Users\\karate\\Desktop\\karate\\karate-demo\\target\\surefire-reports\\xml";

Full Screen

Full Screen

clientFactory

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.Runner;2import com.intuit.karate.Runner.Builder;3import org.junit.jupiter.api.Test;4import org.junit.jupiter.api.TestInstance;5import org.junit.jupiter.api.TestInstance.Lifecycle;6@TestInstance(Lifecycle.PER_CLASS)7public class 4 {8public void testParallel() {9Builder builder = Runner.builder();10builder.path("classpath:4.feature");11builder.clientFactory(null);12builder.outputCucumberJson(true);13builder.outputJunitXml(true);14Runner runner = builder.build();15runner.run();16}17}18 * def response = client.get("/api/v1/4")19 * match response == { "4": "4" }20import com.intuit.karate.Runner;21import com.intuit.karate.Runner.Builder;22import org.junit.jupiter.api.Test;23import org.junit.jupiter.api.TestInstance;24import org.junit.jupiter.api.TestInstance.Lifecycle;25@TestInstance(Lifecycle.PER_CLASS)26public class 5 {27public void testParallel() {28Builder builder = Runner.builder();29builder.path("classpath:5.feature");30builder.clientFactory(null);31builder.outputCucumberJson(true);32builder.outputJunitXml(true);33Runner runner = builder.build();34runner.run();35}36}37 * def response = client.get("/api/v1/5")38 * match response == { "5": "5" }39import com.intuit.karate.Runner;40import com.intuit.karate.Runner.Builder;41import org.junit.jupiter.api.Test;42import org.junit.jupiter.api.TestInstance;43import org.junit.jupiter.api.TestInstance.Lifecycle;44@TestInstance(Lifecycle.PER_CLASS)45public class 6 {46public void testParallel() {47Builder builder = Runner.builder();48builder.path("classpath:6.feature");49builder.clientFactory(null);50builder.outputCucumberJson(true);51builder.outputJunitXml(true);52Runner runner = builder.build();53runner.run();54}55}

Full Screen

Full Screen

clientFactory

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.Runner;2import com.intuit.karate.Results;3import com.intuit.karate.Runner.Builder;4import com.intuit.karate.netty.FeatureServer;5import com.intuit.karate.netty.FeatureServer.Builder;6import java.util.Collection;7import java.util.Map;8import org.junit.jupiter.api.Test;9import static org.junit.jupiter.api.Assertions.*;10public class 4 {11 public void testParallel() {12 Builder builder = Runner.builder();13 builder.path("classpath:4.feature");14 Results results = Runner.parallel(4, builder);15 assertTrue(results.getFailCount() == 0, results.getErrorMessages());16 }17}

Full Screen

Full Screen

clientFactory

Using AI Code Generation

copy

Full Screen

1package com.intuit.karate;2import org.junit.jupiter.api.Test;3class TestRunner {4void testParallel() {5 String karateOutputPath = "target/surefire-reports";6 Runner.parallel(getClass(), 5, karateOutputPath);7}8}9package com.intuit.karate;10import org.junit.jupiter.api.Test;11class TestRunner {12void testParallel() {13 String karateOutputPath = "target/surefire-reports";14 Runner.parallel(getClass(), 5, karateOutputPath);15}16}17package com.intuit.karate;18import org.junit.jupiter.api.Test;19class TestRunner {20void testParallel() {21 String karateOutputPath = "target/surefire-reports";22 Runner.parallel(getClass(), 5, karateOutputPath);23}24}25package com.intuit.karate;26import org.junit.jupiter.api.Test;27class TestRunner {28void testParallel() {29 String karateOutputPath = "target/surefire-reports";30 Runner.parallel(getClass(), 5, karateOutputPath);31}32}33package com.intuit.karate;34import org.junit.jupiter.api.Test;35class TestRunner {36void testParallel() {37 String karateOutputPath = "target/surefire-reports";38 Runner.parallel(getClass(), 5, karateOutputPath);39}40}41package com.intuit.karate;42import org.junit.jupiter.api.Test;43class TestRunner {44void testParallel() {45 String karateOutputPath = "target/surefire-reports";46 Runner.parallel(getClass(), 5, karateOutputPath);47}48}49package com.intuit.karate;50import org.junit.jupiter

Full Screen

Full Screen

clientFactory

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.KarateOptions;2import com.intuit.karate.Results;3import com.intuit.karate.Runner;4import com.intuit.karate.netty.FeatureServer;5import java.util.HashMap;6import java.util.Map;7@KarateOptions(features = "classpath:4.feature")8public class 4 {9 public static void main(String[] args) {10 Map<String, Object> serverConfig = new HashMap<>();11 serverConfig.put("port", 0);12 FeatureServer server = FeatureServer.start("classpath:4.feature", serverConfig, false);13 int port = server.getPort();14 System.out.println("port = " + port);15 Map<String, Object> clientConfig = new HashMap<>();16 clientConfig.put("url", url);17 Map<String, Object> response = Runner.clientFactory(clientConfig).get("/hello");18 System.out.println("response = " + response);19 Results results = Runner.path("classpath:4.feature").tags("~@ignore").outputCucumberJson(true).parallel(1);20 server.stop();21 }22}23 * def client = karate.client(url)24 * def response = client.get("/hello")25 * def client = karate.client(url)26 * def response = client.get("/hello")27 * def client = karate.client(url)28 * def response = client.get("/hello")29 * def client = karate.client(url)30 * def response = client.get("/hello")

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful