public void Default()
        {
            AtataContextBuilder builder = AtataContext.Configure().
                                          ApplyJsonConfig();

            builder.BuildingContext.BaseUrl.Should().EndWith("atata");
        }
        public void Multiple_ViaSingleConfig()
        {
            AtataContextBuilder builder = AtataContext.Configure().
                                          ApplyJsonConfig("Configs/LogConsumers");

            LogConsumerInfo[] expected =
            {
                new LogConsumerInfo(new DebugLogConsumer  {
                    Separator = " - "
                }),
                new LogConsumerInfo(new TraceLogConsumer(), LogLevel.Trace, true)
                {
                    MessageNestingLevelIndent = "_ ",
                    MessageStartSectionPrefix = "S:",
                    MessageEndSectionPrefix   = "E:",
                },
                new LogConsumerInfo(new NUnitTestContextLogConsumer(), LogLevel.Info, false),
                new LogConsumerInfo(new NLogConsumer      {
                    LoggerName = "somelogger"
                }, LogLevel.Warn, false),
                new LogConsumerInfo(new CustomLogConsumer {
                    IntProperty = 15
                }, LogLevel.Error)
            };

            AssertLogConsumers(expected, builder.BuildingContext.LogConsumers);

            JsonConfig.Current.LogConsumers.Count.Should().Be(expected.Length);
        }
        public void Default_WithAlias()
        {
            AtataContextBuilder builder = AtataContext.Configure().
                                          ApplyJsonConfig(environmentAlias: "QA");

            builder.BuildingContext.BaseUrl.Should().EndWith("atata.qa");
        }
Exemple #4
0
        public void Global()
        {
            AtataContextBuilder builder = AtataContext.Configure().
                                          ApplyJsonConfig("Configs/Attributes/Global");

            var result = builder.BuildingContext.Attributes.Global;

            result.Should().HaveCount(4);

            var attribute1 = result[0].Should().BeOfType <TermFindSettingsAttribute>().Subject;

            attribute1.Case.Should().Be(TermCase.LowerMerged);
            attribute1.TargetTypes.Should().Equal(typeof(Field <,>));
            attribute1.TargetAttributeTypes.Should().Equal(typeof(FindByIdAttribute));
            attribute1.ExcludeTargetTypes.Should().Equal(typeof(CheckBox <>));

            var attribute2 = result[1].Should().BeOfType <FindSettingsAttribute>().Subject;

            attribute2.Visibility.Should().Be(Visibility.Any);
            attribute2.TargetTypes.Should().Equal(typeof(Table <,>), typeof(Table <, ,>));
            attribute2.TargetAttributeTypes.Should().Equal(typeof(FindByClassAttribute), typeof(FindByFieldSetAttribute), typeof(FindByLabelAttribute));
            attribute2.ExcludeTargetNames.Should().Equal("a", "b");
            attribute2.ExcludeTargetParentTypes.Should().Equal(typeof(Frame <>));

            var attribute3 = result[2].Should().BeOfType <FindByIdAttribute>().Subject;

            attribute3.Values.Should().Equal("some-id");

            var attribute4 = result[3].Should().BeOfType <FindByNameAttribute>().Subject;

            attribute4.Values.Should().Equal("name1", "name2");
        }
        private static Subject <List <EventSubscriptionItem> > CreateSutForConfig(string configName)
        {
            AtataContextBuilder builder = AtataContext.Configure().
                                          ApplyJsonConfig(BuildConfigPath(configName));

            return(builder.BuildingContext.EventSubscriptions.ToSutSubject());
        }
Exemple #6
0
        public void Remote_WithOptions()
        {
            var context = RemoteDriverAtataContextBuilderOverride.Context;

            using (context.UseNullDriver())
            {
                AtataContextBuilder builder = AtataContext.Configure().
                                              ApplyJsonConfig(@"Configs/RemoteChrome.json");

                builder.BuildingContext.DriverFactoryToUse.Create();
            }

            ICapabilities capabilities = context.Capabilities;

            capabilities.GetCapability(CapabilityType.BrowserName).Should().Be(DriverAliases.Chrome);

            var chromeCapabilities = (Dictionary <string, object>)capabilities.GetCapability(ChromeOptions.Capability);

            chromeCapabilities.Should().Equal(new Dictionary <string, object>
            {
                ["detach"] = true,
                ["cap1"]   = true,
                ["cap2"]   = 5,
                ["cap3"]   = "str"
            });
        }
        public void SetUp()
        {
            consumerBuilder = ConfigureBaseAtataContext().
                              AddScreenshotFileSaving();

            foldersToDelete = new List <string>();
        }
        public void FolderPath()
        {
            string filePath = AppDomain.CurrentDomain.BaseDirectory;

            AtataContextBuilder builder = AtataContext.Configure().
                                          ApplyJsonConfig(filePath);

            builder.BuildingContext.BaseUrl.Should().EndWith("atata");
        }
        public void AbsolutePath_WithAlias()
        {
            string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Simple.json");

            AtataContextBuilder builder = AtataContext.Configure().
                                          ApplyJsonConfig(filePath, "QA");

            builder.BuildingContext.BaseUrl.Should().EndWith("simple.qa");
        }
        public void FileName()
        {
            string filePath = "Simple.json";

            AtataContextBuilder builder = AtataContext.Configure().
                                          ApplyJsonConfig(filePath);

            builder.BuildingContext.BaseUrl.Should().EndWith("simple");
        }
Exemple #11
0
        /// <summary>
        /// Use the driver pool with optionally restricting the pool with <paramref name="poolScopeObject"/>.
        /// </summary>
        /// <param name="builder">An <see cref="AtataContextBuilder"/>.</param>
        /// <param name="poolScopeObject">
        /// The pool scope object.
        /// Is optional.
        /// Mostly can be a fixture class object.
        /// When is <see langword="null"/> then will use whole global common pool;
        /// otherwise will use separate pool for particular scope object.
        /// </param>
        /// <returns>The same <see cref="AtataContextBuilder"/> instance.</returns>
        public static AtataContextBuilder UseDriverPool(this AtataContextBuilder builder, object poolScopeObject = null)
        {
            IDriverFactory driverFactory = builder.BuildingContext.DriverFactoryToUse;

            IWebDriver driver = DriverPool.Acquire(driverFactory, poolScopeObject);

            return(builder.UseDriver(driver)
                   .EventSubscriptions.Add <AtataContextCleanUpEvent>(ReleaseCurrentDriver));
        }
        public void NotFound()
        {
            AtataContextBuilder builder = AtataContext.Configure();

            var exception = Assert.Throws <ConfigurationException>(() =>
                                                                   builder.ApplyJsonConfig("Configs/EnvironmentVariables"));

            exception.Message.Should().Contain(Variable1Name);
        }
        /// <summary>
        /// Use the driver pool with optionally resricting the pool with <paramref name="poolScopeObject"/>.
        /// </summary>
        /// <param name="builder">An <see cref="AtataContextBuilder"/>.</param>
        /// <param name="poolScopeObject">
        /// The pool scope object.
        /// Is optional.
        /// Mostly can be a fixture class object.
        /// When is <see langword="null"/> then will use whole global common pool;
        /// otherwise will use separate pool for particular scope object.
        /// </param>
        /// <returns></returns>
        public static AtataContextBuilder UseDriverPool(this AtataContextBuilder builder, object poolScopeObject = null)
        {
            IDriverFactory driverFactory = builder.BuildingContext.DriverFactoryToUse;

            RemoteWebDriver driver = DriverPool.Acquire(driverFactory, poolScopeObject);

            return(builder.UseDriver(driver).
                   OnCleanUp(ReleaseCurrentDriver));
        }
        public void FileName_WithAlias_WithoutExtension()
        {
            string filePath = "Simple";

            AtataContextBuilder builder = AtataContext.Configure().
                                          ApplyJsonConfig(filePath, "QA");

            builder.BuildingContext.BaseUrl.Should().EndWith("simple.qa");
        }
        public void Found()
        {
            Environment.SetEnvironmentVariable(Variable1Name, "https://example.org", EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable(Variable2Name, "test", EnvironmentVariableTarget.Process);

            AtataContextBuilder builder = AtataContext.Configure()
                                          .ApplyJsonConfig("Configs/EnvironmentVariables");

            builder.BuildingContext.BaseUrl.Should().Be("https://example.org/test");
        }
Exemple #16
0
        public void Multiple()
        {
            AtataContextBuilder builder = AtataContext.Configure().
                                          ApplyJsonConfig(@"Configs/MultipleDrivers.json");

            builder.BuildingContext.DriverFactories.Should().HaveCount(2);
            builder.BuildingContext.DriverFactories[0].Alias.Should().Be(DriverAliases.Firefox);
            builder.BuildingContext.DriverFactories[1].Alias.Should().Be(DriverAliases.Chrome);
            builder.BuildingContext.DriverFactoryToUse.Alias.Should().Be(DriverAliases.Chrome);
        }
Exemple #17
0
        public void SetUp()
        {
            AtataContextBuilder contextBuilder = AtataContext.Configure();

            if (ReuseDriver && PreservedDriver != null)
            {
                contextBuilder = contextBuilder.UseDriver(PreservedDriver);
            }

            contextBuilder.Build();
        }
Exemple #18
0
        public void Firefox()
        {
            var context = FirefoxAtataContextBuilderOverride.Context;

            using (context.UseNullDriver())
            {
                AtataContextBuilder builder = AtataContext.Configure().
                                              ApplyJsonConfig(@"Configs/Firefox.json");

                builder.BuildingContext.DriverFactoryToUse.Create();
            }

            var capabilities        = context.Options.ToCapabilities();
            var optionsCapabilities = (Dictionary <string, object>)capabilities.GetCapability("moz:firefoxOptions");

            optionsCapabilities.Should().Contain(new Dictionary <string, object>
            {
                ["cap1"] = true,
                ["cap2"] = 5,
                ["cap3"] = "str"
            });

            capabilities.GetCapability("globalcap1").Should().Be(true);
            capabilities.GetCapability("globalcap2").Should().Be(5);
            capabilities.GetCapability("globalcap3").Should().Be("str");

            context.Options.Proxy.Kind.Should().Be(ProxyKind.ProxyAutoConfigure);

            ((List <object>)optionsCapabilities["args"]).Should().Equal("--start-maximized");

            // TODO: Review Firefox profileDirectory setting.
            ////typeof(FirefoxProfile).GetField("sourceProfileDir", BindingFlags.NonPublic | BindingFlags.Instance)
            ////    ?.GetValue(context.Options.Profile).Should().Be("dir");

            // TODO: Review Firefox profile setting.
            ////typeof(FirefoxProfile).GetField("deleteSource", BindingFlags.NonPublic | BindingFlags.Instance)
            ////    ?.GetValue(context.Options.Profile).Should().Be(true);

            ////context.Options.Profile.EnableNativeEvents.Should().BeTrue();

            ((Dictionary <string, object>)optionsCapabilities["prefs"]).Should().Equal(new Dictionary <string, object>
            {
                ["pref1"] = true,
                ["pref2"] = 5,
                ["pref3"] = "str"
            });

            context.Options.LogLevel.Should().Be(FirefoxDriverLogLevel.Warn);

            context.Service.Host.Should().Be("127.0.0.5");

            context.CommandTimeout.Should().Be(TimeSpan.FromSeconds(0.95));
        }
Exemple #19
0
        public void Remote_WithTypelessOptions()
        {
            var context = RemoteDriverAtataContextBuilderOverride.Context;

            using (context.UseNullDriver())
            {
                AtataContextBuilder builder = AtataContext.Configure().
                                              ApplyJsonConfig(@"Configs/RemoteTypeless.json");

                Assert.Throws <ArgumentNullException>(() =>
                                                      builder.BuildingContext.DriverFactoryToUse.Create());
            }
        }
Exemple #20
0
        public void Component()
        {
            AtataContextBuilder builder = AtataContext.Configure().
                                          ApplyJsonConfig("Configs/Attributes/Component");

            var result = builder.BuildingContext.Attributes.ComponentMap;

            result.Should().HaveCount(1);

            result[typeof(OrdinaryPage)].Should().ContainSingle()
            .Which.Should().BeOfType <UrlAttribute>()
            .Which.Url.Should().Be("/some-url");
        }
Exemple #21
0
        public void Remote()
        {
            var context = RemoteDriverAtataContextBuilderOverride.Context;

            using (context.UseNullDriver())
            {
                AtataContextBuilder builder = AtataContext.Configure().
                                              ApplyJsonConfig(@"Configs/Remote.json");

                builder.BuildingContext.DriverFactoryToUse.Create();
            }

            context.RemoteAddress.Should().Be("http://127.0.0.1:8888/wd/hub");
            context.CommandTimeout.Should().Be(TimeSpan.FromSeconds(100));
        }
 protected virtual AtataContextBuilder ConfigureAtataContext(AtataContextBuilder builder)
 {
     if (DriverPoolUsage == DriverPoolUsage.Fixture)
     {
         return(builder.UseDriverPool(this));
     }
     else if (DriverPoolUsage == DriverPoolUsage.Global)
     {
         return(builder.UseDriverPool());
     }
     else
     {
         return(builder);
     }
 }
Exemple #23
0
        public void Default()
        {
            string     jsonContent = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Configs/CustomSettings.json"));
            JsonConfig config      = JsonConvert.DeserializeObject <JsonConfig>(jsonContent);

            AtataContextBuilder builder = AtataContext.Configure().
                                          ApplyJsonConfig(config);

            JsonConfig.Current.Should().BeNull();

            config.BaseUrl.Should().Be("https://demo.atata.io/");

            builder.BuildingContext.DriverFactories.Should().HaveCount(1);
            builder.BuildingContext.BaseUrl.Should().Be("https://demo.atata.io/");
        }
        protected AtataContext CreateContext()
        {
            AtataContextBuilder contextBuilder = AtataContext.Configure()
                                                 .EventSubscriptions.Add <AtataContextCleanUpEvent>(e => Contexts.Remove(e.Context));

            if (AtataContext.Current != null)
            {
                contextBuilder.UseTestName($"{AtataContext.Current.TestName}[{Contexts.Count}]");
            }

            AtataContext context = contextBuilder.Build();

            Contexts.Add(context);

            return(context);
        }
Exemple #25
0
        public void Remote_WithoutType()
        {
            var context = RemoteDriverAtataContextBuilderOverride.Context;

            using (context.UseNullDriver())
            {
                AtataContextBuilder builder = AtataContext.Configure().
                                              ApplyJsonConfig(@"Configs/RemoteFirefox.json");

                builder.BuildingContext.DriverFactoryToUse.Create();
            }

            ICapabilities capabilities = context.Capabilities;

            capabilities.GetCapability(CapabilityType.BrowserName).Should().Be(DriverAliases.Firefox);
        }
Exemple #26
0
        public void Property()
        {
            AtataContextBuilder builder = AtataContext.Configure().
                                          ApplyJsonConfig("Configs/Attributes/Property");

            var result = builder.BuildingContext.Attributes.PropertyMap;

            result.Should().HaveCount(2);

            result[new TypePropertyNamePair(typeof(OrdinaryPage), "Prop1")].Should().ContainSingle()
            .Which.Should().BeOfType <FindByIdAttribute>()
            .Which.Values.Should().Equal("some-id");

            result[new TypePropertyNamePair(typeof(OrdinaryPage), "Prop2")].Should().ContainSingle()
            .Which.Should().BeOfType <FindByNameAttribute>()
            .Which.Values.Should().Equal("some-name");
        }
Exemple #27
0
        public void Chrome()
        {
            var context = ChromeAtataContextBuilderOverride.Context;

            using (context.UseNullDriver())
            {
                AtataContextBuilder builder = AtataContext.Configure().
                                              ApplyJsonConfig(@"Configs/Chrome.json");

                builder.BuildingContext.DriverFactoryToUse.Create();
            }

            VerifyChromeOptions(context.Options);
            VerifyChromeService(context.Service);

            context.CommandTimeout.Should().Be(TimeSpan.FromMinutes(1));
        }
Exemple #28
0
        public void Custom()
        {
            string           jsonContent = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Configs/CustomSettings.json"));
            CustomJsonConfig config      = JsonConvert.DeserializeObject <CustomJsonConfig>(jsonContent);

            AtataContextBuilder builder = AtataContext.Configure().
                                          ApplyJsonConfig(config);

            CustomJsonConfig.Current.Should().BeNull();

            config.BaseUrl.Should().Be("https://demo.atata.io/");
            config.IntProperty.Should().Be(5);
            config.StringArrayValues.Should().Equal(new[] { "str1", "str2", "str3" });

            builder.BuildingContext.DriverFactories.Should().HaveCount(1);
            builder.BuildingContext.BaseUrl.Should().Be("https://demo.atata.io/");
        }
Exemple #29
0
        public void SetUp()
        {
            AtataContextBuilder contextBuilder = ConfigureBaseAtataContext();

            if (ReuseDriver && PreservedDriver != null)
            {
                contextBuilder = contextBuilder.UseDriver(PreservedDriver);
            }

            contextBuilder.Build();

            if (ReuseDriver && PreservedDriver == null)
            {
                PreservedDriver = AtataContext.Current.Driver;
            }

            OnSetUp();
        }
Exemple #30
0
        protected AtataContext CreateContext()
        {
            AtataContext context = null;

            AtataContextBuilder contextBuilder = AtataContext.Configure()
                                                 .OnCleanUp(() => Contexts.Remove(context));

            if (AtataContext.Current != null)
            {
                contextBuilder.UseTestName($"{AtataContext.Current.TestName}[{Contexts.Count}]");
            }

            context = contextBuilder.Build();

            Contexts.Add(context);

            return(context);
        }