Best Atata code snippet using Atata.AtataContextBuilder.UseDriver
AtataContextBuilder.cs
Source:AtataContextBuilder.cs
...92 /// </summary>93 /// <typeparam name="TDriverBuilder">The type of the driver builder.</typeparam>94 /// <param name="driverBuilder">The driver builder.</param>95 /// <returns>The <typeparamref name="TDriverBuilder"/> instance.</returns>96 public TDriverBuilder UseDriver<TDriverBuilder>(TDriverBuilder driverBuilder)97 where TDriverBuilder : AtataContextBuilder, IDriverFactory98 {99 driverBuilder.CheckNotNull(nameof(driverBuilder));100101 BuildingContext.DriverFactories.Add(driverBuilder);102 BuildingContext.DriverFactoryToUse = driverBuilder;103104 return driverBuilder;105 }106107 /// <summary>108 /// Sets the alias of the driver to use.109 /// </summary>110 /// <param name="alias">The alias of the driver.</param>111 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>112 public AtataContextBuilder UseDriver(string alias)113 {114 alias.CheckNotNullOrWhitespace(nameof(alias));115116 IDriverFactory driverFactory = BuildingContext.GetDriverFactory(alias);117118 if (driverFactory != null)119 BuildingContext.DriverFactoryToUse = driverFactory;120 else if (UsePredefinedDriver(alias) == null)121 throw new ArgumentException($"No driver with \"{alias}\" alias defined.", nameof(alias));122123 return this;124 }125126 /// <summary>127 /// Use specified driver instance.128 /// </summary>129 /// <param name="driver">The driver to use.</param>130 /// <returns>The <see cref="CustomDriverAtataContextBuilder"/> instance.</returns>131 public CustomDriverAtataContextBuilder UseDriver(IWebDriver driver)132 {133 driver.CheckNotNull(nameof(driver));134135 return UseDriver(() => driver);136 }137138 /// <summary>139 /// Use custom driver factory method.140 /// </summary>141 /// <param name="driverFactory">The driver factory method.</param>142 /// <returns>The <see cref="CustomDriverAtataContextBuilder"/> instance.</returns>143 public CustomDriverAtataContextBuilder UseDriver(Func<IWebDriver> driverFactory)144 {145 driverFactory.CheckNotNull(nameof(driverFactory));146147 return UseDriver(new CustomDriverAtataContextBuilder(BuildingContext, driverFactory));148 }149150 private IDriverFactory UsePredefinedDriver(string alias)151 {152 switch (alias.ToLowerInvariant())153 {154 case DriverAliases.Chrome:155 return UseChrome();156 case DriverAliases.Firefox:157 return UseFirefox();158 case DriverAliases.InternetExplorer:159 return UseInternetExplorer();160 case DriverAliases.Safari:161 return UseSafari();162 case DriverAliases.Opera:163 return UseOpera();164 case DriverAliases.Edge:165 return UseEdge();166 default:167 return null;168 }169 }170171 /// <summary>172 /// Sets the driver initialization stage.173 /// The default value is <see cref="AtataContextDriverInitializationStage.Build"/>.174 /// </summary>175 /// <param name="stage">The stage.</param>176 /// <returns>The <see cref="AtataContextBuilder"/> instance.</returns>177 public AtataContextBuilder UseDriverInitializationStage(AtataContextDriverInitializationStage stage)178 {179 BuildingContext.DriverInitializationStage = stage;180 return this;181 }182183 /// <summary>184 /// Creates and returns a new builder for <see cref="ChromeDriver"/>185 /// with default <see cref="DriverAliases.Chrome"/> alias.186 /// Sets this builder as a one to use for a driver creation.187 /// </summary>188 /// <returns>The <see cref="ChromeAtataContextBuilder"/> instance.</returns>189 public ChromeAtataContextBuilder UseChrome() =>190 UseDriver(new ChromeAtataContextBuilder(BuildingContext));191192 /// <summary>193 /// Creates and returns a new builder for <see cref="FirefoxDriver"/>194 /// with default <see cref="DriverAliases.Firefox"/> alias.195 /// Sets this builder as a one to use for a driver creation.196 /// </summary>197 /// <returns>The <see cref="FirefoxAtataContextBuilder"/> instance.</returns>198 public FirefoxAtataContextBuilder UseFirefox() =>199 UseDriver(new FirefoxAtataContextBuilder(BuildingContext));200201 /// <summary>202 /// Creates and returns a new builder for <see cref="InternetExplorerDriver"/>203 /// with default <see cref="DriverAliases.InternetExplorer"/> alias.204 /// Sets this builder as a one to use for a driver creation.205 /// </summary>206 /// <returns>The <see cref="InternetExplorerAtataContextBuilder"/> instance.</returns>207 public InternetExplorerAtataContextBuilder UseInternetExplorer() =>208 UseDriver(new InternetExplorerAtataContextBuilder(BuildingContext));209210 /// <summary>211 /// Creates and returns a new builder for <see cref="EdgeDriver"/>212 /// with default <see cref="DriverAliases.Edge"/> alias.213 /// Sets this builder as a one to use for a driver creation.214 /// </summary>215 /// <returns>The <see cref="EdgeAtataContextBuilder"/> instance.</returns>216 public EdgeAtataContextBuilder UseEdge() =>217 UseDriver(new EdgeAtataContextBuilder(BuildingContext));218219 /// <summary>220 /// Creates and returns a new builder for <see cref="OperaDriver"/>221 /// with default <see cref="DriverAliases.Opera"/> alias.222 /// Sets this builder as a one to use for a driver creation.223 /// </summary>224 /// <returns>The <see cref="OperaAtataContextBuilder"/> instance.</returns>225 public OperaAtataContextBuilder UseOpera() =>226 UseDriver(new OperaAtataContextBuilder(BuildingContext));227228 /// <summary>229 /// Creates and returns a new builder for <see cref="SafariDriver"/>230 /// with default <see cref="DriverAliases.Safari"/> alias.231 /// Sets this builder as a one to use for a driver creation.232 /// </summary>233 /// <returns>The <see cref="SafariAtataContextBuilder"/> instance.</returns>234 public SafariAtataContextBuilder UseSafari() =>235 UseDriver(new SafariAtataContextBuilder(BuildingContext));236237 /// <summary>238 /// Creates and returns a new builder for <see cref="RemoteWebDriver"/>239 /// with default <see cref="DriverAliases.Remote"/> alias.240 /// Sets this builder as a one to use for a driver creation.241 /// </summary>242 /// <returns>The <see cref="RemoteDriverAtataContextBuilder"/> instance.</returns>243 public RemoteDriverAtataContextBuilder UseRemoteDriver() =>244 UseDriver(new RemoteDriverAtataContextBuilder(BuildingContext));245246 /// <summary>247 /// Returns an existing or creates a new builder for <see cref="ChromeDriver"/> by the specified alias.248 /// </summary>249 /// <param name="alias">250 /// The driver alias.251 /// The default value is <see cref="DriverAliases.Chrome"/>.252 /// </param>253 /// <returns>The <see cref="ChromeAtataContextBuilder"/> instance.</returns>254 public ChromeAtataContextBuilder ConfigureChrome(string alias = DriverAliases.Chrome) =>255 ConfigureDriver(256 alias,257 () => new ChromeAtataContextBuilder(BuildingContext).WithAlias(alias));258
...
AtataContextBuilderExtensions.cs
Source:AtataContextBuilderExtensions.cs
...15 /// When is <see langword="null"/> then will use whole global common pool;16 /// otherwise will use separate pool for particular scope object.17 /// </param>18 /// <returns>The same <see cref="AtataContextBuilder"/> instance.</returns>19 public static AtataContextBuilder UseDriverPool(this AtataContextBuilder builder, object poolScopeObject = null)20 {21 IDriverFactory driverFactory = builder.BuildingContext.DriverFactoryToUse;22 IWebDriver driver = DriverPool.Acquire(driverFactory, poolScopeObject);23 return builder.UseDriver(driver)24 .EventSubscriptions.Add<AtataContextCleanUpEvent>(ReleaseCurrentDriver);25 }26 private static void ReleaseCurrentDriver(AtataContextCleanUpEvent eventData)27 {28 DriverPool.Release(eventData.Context.Driver);29 }30 }31}...
UITestFixture.cs
Source:UITestFixture.cs
...18 public void SetUp()19 {20 AtataContextBuilder contextBuilder = AtataContext.Configure();21 if (ReuseDriver && PreservedDriver != null)22 contextBuilder = contextBuilder.UseDriver(PreservedDriver);23 contextBuilder.Build();24 }25 [TearDown]26 public void TearDown()27 {28 AtataContext.Current?.CleanUp(!ReuseDriver);29 }30 [OneTimeTearDown]31 public void TearDownFixture()32 {33 if (PreservedDriver != null)34 {35 PreservedDriver.Dispose();36 PreservedDriver = null;...
UseDriver
Using AI Code Generation
1using Atata;2using NUnit.Framework;3{4 {5 public void SetUp()6 {7 Build();8 }9 public void TearDown()10 {11 AtataContext.Current?.CleanUp();12 }13 }14}15using Atata;16using NUnit.Framework;17{18 {19 public void SetUp()20 {21 Build();22 }23 public void TearDown()24 {25 AtataContext.Current?.CleanUp();26 }27 }28}29using Atata;30using NUnit.Framework;31{32 {33 public void SetUp()34 {35 Build();36 }37 public void TearDown()38 {39 AtataContext.Current?.CleanUp();40 }41 }42}43using Atata;44using NUnit.Framework;45{46 {47 public void SetUp()48 {
UseDriver
Using AI Code Generation
1using Atata;2using NUnit.Framework;3{4 {5 public void OneTimeSetUp()6 {7 Build();8 }9 public void OneTimeTearDown()10 {11 AtataContext.Current.CleanUp();12 }13 }14}15using Atata;16using NUnit.Framework;17{18 {19 public void OneTimeSetUp()20 {21 Build();22 }23 public void OneTimeTearDown()24 {25 AtataContext.Current.CleanUp();26 }27 }28}29using Atata;30using NUnit.Framework;31{32 {33 public void OneTimeSetUp()34 {35 Build();36 }37 public void OneTimeTearDown()38 {39 AtataContext.Current.CleanUp();40 }41 }42}43using Atata;44using NUnit.Framework;45{46 {47 public void OneTimeSetUp()48 {
UseDriver
Using AI Code Generation
1public void Setup()2{3 AtataContext.Configure()4 .UseDriver(new ChromeDriver())5 .UseCulture("en-us")6 .UseAllNUnitFeatures()7 .Build();8}9public void Setup()10{11 AtataContext.Configure()12 .UseDriver(new FirefoxDriver())13 .UseCulture("en-us")14 .UseAllNUnitFeatures()15 .Build();16}17public void Setup()18{19 AtataContext.Configure()20 .UseDriver(new EdgeDriver())21 .UseCulture("en-us")22 .UseAllNUnitFeatures()23 .Build();24}25public void Setup()26{27 AtataContext.Configure()28 .UseDriver(new InternetExplorerDriver())29 .UseCulture("en-us")30 .UseAllNUnitFeatures()31 .Build();32}33public void Setup()34{35 AtataContext.Configure()36 .UseDriver(new SafariDriver())37 .UseCulture("en-us")38 .UseAllNUnitFeatures()39 .Build();40}41public void Setup()42{43 AtataContext.Configure()44 .UseDriver(new OperaDriver())45 .UseCulture("en-us")46 .UseAllNUnitFeatures()47 .Build();48}49public void Setup()50{51 AtataContext.Configure()52 .UseDriver(new PhantomJSDriver())
UseDriver
Using AI Code Generation
1AtataContext.Configure()2 .UseDriver(new ChromeDriver())3 .UseCulture("en-US")4 .UseNUnitTestName()5 .UseAllNUnitFeatures()6 .Build();7AtataContext.Configure()8 .UseDriver(new FirefoxDriver())9 .UseCulture("en-US")10 .UseNUnitTestName()11 .UseAllNUnitFeatures()12 .Build();13AtataContext.Configure()14 .UseDriver(new InternetExplorerDriver())15 .UseCulture("en-US")16 .UseNUnitTestName()17 .UseAllNUnitFeatures()18 .Build();19AtataContext.Configure()20 .UseDriver(new EdgeDriver())21 .UseCulture("en-US")22 .UseNUnitTestName()23 .UseAllNUnitFeatures()24 .Build();25AtataContext.Configure()26 .UseDriver(new OperaDriver())27 .UseCulture("en-US")28 .UseNUnitTestName()29 .UseAllNUnitFeatures()30 .Build();31AtataContext.Configure()32 .UseDriver(new SafariDriver())33 .UseCulture("en-US")34 .UseNUnitTestName()35 .UseAllNUnitFeatures()36 .Build();37AtataContext.Configure()38 .UseDriver(new PhantomJSDriver())39 .UseCulture("en-US")40 .UseNUnitTestName()
UseDriver
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NUnit.Framework;7using Atata;8{9 {10 public void SetUp()11 {12 AtataContext.Configure()13 .UseDriver(new ChromeDriver())14 .UseCulture("en-us")15 .UseAllNUnitFeatures()16 .UseNUnitTestName()17 .LogNUnitError()18 .Build();19 }20 public void TearDown()21 {22 AtataContext.Current?.CleanUp();23 }24 public void Test()25 {26 Go.To<HomePage>()27 .SignIn.ClickAndGo()28 .SignInAs("john", "12345")29 .UserPanel.Should.Exist();30 }31 }32}33using System;34using System.Collections.Generic;35using System.Linq;36using System.Text;37using System.Threading.Tasks;38using NUnit.Framework;39using Atata;40{41 {42 public void SetUp()43 {44 AtataContext.Configure()45 .UseDriver(new ChromeDriver())46 .UseCulture("en-us")47 .UseAllNUnitFeatures()48 .UseNUnitTestName()49 .LogNUnitError()50 .Build();51 }52 public void TearDown()53 {54 AtataContext.Current?.CleanUp();55 }56 public void Test()57 {58 Go.To<HomePage>()59 .SignIn.ClickAndGo()60 .SignInAs("john", "12345")61 .UserPanel.Should.Exist();62 }63 }64}65using System;66using System.Collections.Generic;67using System.Linq;68using System.Text;69using System.Threading.Tasks;70using NUnit.Framework;71using Atata;72{73 {74 public void SetUp()
UseDriver
Using AI Code Generation
1using Atata;2using NUnit.Framework;3{4 {5 static void Main(string[] args)6 {7 Build();8 }9 }10}11using Atata;12using NUnit.Framework;13{14 {15 static void Main(string[] args)16 {17 Build();18 }19 }20}21using Atata;22using NUnit.Framework;23{24 {25 static void Main(string[] args)26 {27 Build();28 }29 }30}31using Atata;32using NUnit.Framework;33{34 {35 static void Main(string[] args)36 {37 Build();38 }39 }40}41using Atata;42using NUnit.Framework;43{44 {45 static void Main(string[] args)46 {47 Build();48 }49 }50}
UseDriver
Using AI Code Generation
1using Atata;2using NUnit.Framework;3{4 {5 public void Setup()6 {7 Build();8 }9 public void Test1()10 {11 Go.To<GooglePage>();12 }13 }14}15using Atata;16using NUnit.Framework;17{18 {19 public void Setup()20 {21 Build();22 }23 public void Test1()24 {25 Go.To<GooglePage>();26 }27 }28}29using Atata;30using NUnit.Framework;31{32 {33 public void Setup()34 {35 Build();36 }37 public void Test1()38 {39 Go.To<GooglePage>();40 }41 }42}43using Atata;44using NUnit.Framework;45{46 {47 public void Setup()48 {49 Build();50 }51 public void Test1()52 {53 Go.To<GooglePage>();54 }55 }56}57using Atata;58using NUnit.Framework;59{
UseDriver
Using AI Code Generation
1using Atata;2using NUnit.Framework;3{4 {5 public void SetUp()6 {7 Build();8 }9 }10}
UseDriver
Using AI Code Generation
1using System;2using Atata;3using NUnit.Framework;4{5 {6 public void Test()7 {8 Build();9 }10 }11}12using System;13using Atata;14using NUnit.Framework;15{16 {17 public void Test()18 {19 Build();20 }21 }22}23using System;24using Atata;25using NUnit.Framework;26{27 {28 public void Test()29 {30 Build();31 }32 }33}34using System;35using Atata;36using NUnit.Framework;37{38 {39 public void Test()40 {41 Build();42 }43 }44}
UseDriver
Using AI Code Generation
1using Atata;2using OpenQA.Selenium.Chrome;3{4 {5 protected override void OnSetUp()6 {7 AtataContext.Configure()8 .UseDriver<ChromeDriver>()9 .Build();10 }11 }12}13using Atata;14using OpenQA.Selenium.Chrome;15{16 {17 protected override void OnSetUp()18 {19 AtataContext.Configure()20 .UseDriver<ChromeDriver>()21 .Build();22 }23 }24}25using Atata;26using OpenQA.Selenium.Chrome;27{28 {29 protected override void OnSetUp()30 {31 AtataContext.Configure()32 .UseDriver<ChromeDriver>()33 .UseCulture("en-US")34 .Build();35 }36 }37}38using Atata;39using OpenQA.Selenium.Chrome;40{41 {42 protected override void OnSetUp()43 {44 AtataContext.Configure()45 .UseDriver<ChromeDriver>()46 .UseCulture("en-US")47 .UseNUnitTestName()48 .Build();49 }50 }51}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!