/// <summary> /// Creates the and navigate to. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="webDriver">The web driver.</param> /// <param name="baseUrl">The base URL.</param> /// <param name="suppressLanguageParameter">Supresses the language parameter</param> /// <param name="hashTagParams">hash tag parameters</param> /// <param name="furtherUrlParameters"> /// The further URL param after the lng param. /// The example input value "cpn=2553 would navigate us to: www.hotel.de?lng=de&cpn=2553 /// </param> /// <returns>A PageObject, navigated to the PageUrl.</returns> public static T CreateAndNavigateTo <T>(IWebDriver webDriver, string baseUrl, bool suppressLanguageParameter = false, string[] hashTagParams = null, params string[] furtherUrlParameters) where T : BasePageObject { T pageObject = CreatePageObject <T>(webDriver); Type type = typeof(T); PagePropsAttribute pageAttribute = (PagePropsAttribute)type.GetCustomAttribute(typeof(PagePropsAttribute), true); string pageUrl = baseUrl; if (!pageUrl.EndsWith("/")) { pageUrl = pageUrl + "/"; } if (pageObject.PageSettings.IsSeoRoute) { pageUrl = CreateSeoRoute(pageUrl, pageAttribute, furtherUrlParameters); } else { pageUrl = CreateRoute(pageUrl, pageAttribute, suppressLanguageParameter, furtherUrlParameters); } if (hashTagParams != null) { pageUrl = string.Concat(pageUrl, "#?", string.Join("&", hashTagParams)); } TestLog.AddWithoutTime("<br><b>>>>" + type.Name + "</b>"); TestLog.Add("CreateAndNavigate: " + type.Name + " -> " + pageUrl); webDriver.Navigate().GoToUrl(pageUrl); return(pageObject); }
private static string CreateRoute(string pageUrl, PagePropsAttribute pageAttribute, bool suppressLanguageParameter = false, params string[] furtherUrlParameters) { string returnUrl = string.Concat(pageUrl, pageAttribute != null && pageAttribute.PageUrl != null ? pageAttribute.PageUrl : string.Empty); returnUrl = string.Concat(returnUrl, GetUrlParams(furtherUrlParameters)); if (!suppressLanguageParameter) { returnUrl = string.Concat(returnUrl, string.Format("&lng={0}", Thread.CurrentThread.CurrentUICulture.Name)); } return(returnUrl); }
private static string CreateSeoRoute(string pageUrl, PagePropsAttribute pageAttribute, params string[] furtherUrlParameters) { string seoRoute = pageAttribute != null && pageAttribute.PageUrl != null?pageAttribute.PageUrl.ToLower() : string.Empty; List <string> remainingParams = new List <string>(); foreach (string param in furtherUrlParameters) { string key = param.Split('=')[0].ToLower(); string value = param.Split('=')[1]; if (seoRoute.Contains("{" + key + "}")) { seoRoute = seoRoute.Replace("{" + key + "}", value); } else { remainingParams.Add(param); } } return(string.Concat(pageUrl, Thread.CurrentThread.CurrentUICulture.Name, "/", seoRoute, GetUrlParams(remainingParams.ToArray()))); }