Пример #1
0
        /// <summary>
        /// Sets session status to mark test as passed/failed in Browserstack.
        /// </summary>
        /// <param name="status">Test status.</param>
        /// <param name="reason">Reason if the status.</param>
        public static void SetSessionStatus(string status, string reason = null)
        {
            if (SettingsHelper.GetValue(SettingsValues.Environment).ToLower() != "remote")
            {
                throw new ArgumentException("Webdriver is not set up as remote. Check run.xml to configure remote run properly");
            }

            var driver         = (RemoteWebDriver)Browser.GetDriver();
            var requestData    = Encoding.UTF8.GetBytes(new JObject(new JProperty("status", status), new JProperty("reason", reason)).ToString());
            var uri            = new Uri(string.Format(BrowserstackSessionConfigUrl, driver.SessionId));
            var webRequest     = WebRequest.Create(uri);
            var httpWebRequest = (HttpWebRequest)webRequest;

            webRequest.ContentType   = "application/json";
            webRequest.Method        = WebRequestMethods.Http.Put;
            webRequest.ContentLength = requestData.Length;

            using (var st = webRequest.GetRequestStream())
            {
                st.Write(requestData, 0, requestData.Length);
            }

            var networkCredential = new NetworkCredential(SettingsHelper.GetValue("bsUser"), SettingsHelper.GetValue("bsKey"));
            var credentialCache   = new CredentialCache {
                { uri, "Basic", networkCredential }
            };

            httpWebRequest.PreAuthenticate = true;
            httpWebRequest.Credentials     = credentialCache;
            webRequest.GetResponse().Close();
        }
Пример #2
0
        /// <summary>
        /// Gets test data from google spreadsheet directly or from exported locally in .xlsx file.
        /// </summary>
        /// <param name="range">Range of data to get (e.g. "Tab!A3:A3").</param>
        /// <param name="spreadSheetId">Spreadsheet Id.</param>
        /// <param name="apiUser">User to establish connection.</param>
        /// <returns>Data as string.</returns>
        public static string GetData(string range, string spreadSheetId, GoogleApiUser apiUser)
        {
            var firstSymbol = range.IndexOf("!", StringComparison.Ordinal) + 1;
            var lastSymbol  = range.IndexOf(":", StringComparison.Ordinal) - firstSymbol;
            var cell        = range.Substring(firstSymbol, lastSymbol);
            var sheetName   = range.Substring(0, range.IndexOf("!", StringComparison.Ordinal));

            return(SettingsHelper.GetValue(SettingsValues.UseLocalData) == "yes"
                                ? SettingsHelper.GetXlsValue(sheetName, cell)
                                : GetDataDirectly(range, spreadSheetId, apiUser));
        }