Ejemplo n.º 1
0
Archivo: Go.cs Proyecto: vik542/atata
        private static T To <T>(T pageObject, GoOptions options)
            where T : PageObject <T>
        {
            if (AtataContext.Current == null)
            {
                AtataContext.Build().SetUp();
            }

            if (AtataContext.Current.PageObject == null)
            {
                pageObject = pageObject ?? ActivatorEx.CreateInstance <T>();
                AtataContext.Current.PageObject = pageObject;

                if (!string.IsNullOrWhiteSpace(options.Url))
                {
                    ToUrl(options.Url);
                }

                pageObject.NavigateOnInit = options.Navigate;
                pageObject.Init();
                return(pageObject);
            }
            else
            {
                IPageObject currentPageObject = (IPageObject)AtataContext.Current.PageObject;
                T           newPageObject     = currentPageObject.GoTo(pageObject, options);
                AtataContext.Current.PageObject = newPageObject;
                return(newPageObject);
            }
        }
Ejemplo n.º 2
0
Archivo: Go.cs Proyecto: vik542/atata
        /// <summary>
        /// Navigates to the specified URL.
        /// </summary>
        /// <param name="url">The URL.</param>
        public static void ToUrl(string url)
        {
            if (AtataContext.Current == null)
            {
                AtataContext.Build().SetUp();
            }

            Uri absoluteUri;

            if (!Uri.TryCreate(url, UriKind.Absolute, out absoluteUri))
            {
                if (!AtataContext.Current.IsNavigated && AtataContext.Current.BaseUrl == null)
                {
                    if (string.IsNullOrWhiteSpace(url))
                    {
                        throw new InvalidOperationException("Cannot navigate to empty or null URL. AtataContext.Current.BaseUrl can be set with base URL.");
                    }
                    else
                    {
                        throw new InvalidOperationException($"Cannot navigate to relative URL \"{url}\". AtataContext.Current.BaseUrl can be set with base URL.");
                    }
                }

                if (AtataContext.Current.BaseUrl == null)
                {
                    Uri currentUri = new Uri(AtataContext.Current.Driver.Url, UriKind.Absolute);

                    string domainPart = currentUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.UserInfo, UriFormat.Unescaped);
                    Uri    domainUri  = new Uri(domainPart);

                    absoluteUri = new Uri(domainUri, url);
                }
                else
                {
                    absoluteUri = ConcatWithBaseUrl(url);
                }
            }

            Navigate(absoluteUri);
        }