예제 #1
0
 public void search(string textToSearch)
 {
     WebActions.sendTextToElement(inputSearch, textToSearch, true);
     WebActions.waitVisible("//ul[@role='listbox']", 30, true);
     WebActions.clickElement(imgGoogle, false);
     WebActions.clickElement(btnGoogleSearch, true);
 }
 /// <summary>
 /// This is generic method for click on Menu items
 /// </summary>
 /// <param name="webActions"></param>
 /// <param name="MainMenu"></param>
 /// <param name="SubMenu"></param>
 public static void ClickMenu(this WebActions webActions, By MainMenu, By SubMenu)
 {
     System.Threading.Thread.Sleep(2000);
     webActions.Click(MainMenu);
     System.Threading.Thread.Sleep(2000);
     webActions.Click(SubMenu);
 }
예제 #3
0
 /*
  *  Function: PostAction(WebActions, WWWForm, ReturnTypes, function)
  *
  *  Submits an action to the server
  *
  *  Parameters:
  *
  *  action - The desired action
  *  form - The WWWForm to submit to the server
  *  returnType - The type of data that needs to be returned
  *  callback - A function pointer to the method that will manage the returned data
  *
  *  See Also:
  *
  *  - <PostAction(WebActions, function)>
  *  - <PostAction(WebActions, ReturnTypes, function)>
  *  - <PostAction(WebActions, WWWForm)>
  *  - <PostAction(WebActions, WWWForm, function)>
  */
 public void PostAction(WebActions action, WWWForm form, ReturnTypes returnType, Action <Hashtable> callback)
 {
     if ((int)action < Actions.Length && action >= 0)
     {
         if (_online)
         {
             if (useDev)
             {
                 loadURL(devURL + Actions[(int)action], form, returnType, callback);
             }
             else
             {
                 loadURL(baseURL + Actions[(int)action], form, returnType, callback);
             }
         }
         else
         {
             postOfflineAction(action, form, returnType, callback);
         }
     }
     else
     {
         Hashtable returnData = new Hashtable();
         returnData["error"] = "Action " + action + " doesn't exist.";
         callback(returnData);
     }
 }
        /// <summary>
        /// This extension method will close all the workflow window, better to place this at the end of script execution
        /// </summary>
        /// <param name="webActions"></param>
        //public static void CloseAllWorkFlowWindows(this WebActions webActions)
        //{
        //    retry:
        //    IReadOnlyCollection<string> allHandles = webActions.GetWindowHandles();
        //    try
        //    {
        //        foreach (string handle in allHandles)
        //        {
        //            webActions.SwitchToWindow(handle);
        //            if (webActions.GetWindowTitle().Contains(CommonObjects.wndWorkFlowTitle))
        //            {
        //                webActions.CloseBrowser();
        //            }
        //        }

        //        webActions.SwitchToFirstOrDefaultWindow();
        //    }
        //    catch (Exception ex)
        //    {
        //        System.Threading.Thread.Sleep(3000);
        //        goto retry;
        //    }
        //}

        /// <summary>
        /// Generic extension method to get the x y co ordinates of the web element
        /// </summary>
        /// <param name="webActions"></param>
        /// <param name="ByLocater"></param>
        /// <returns></returns>
        public static Tuple <int, int> GetElementXYCoordinates(this WebActions webActions, By ByLocater)
        {
            int x = webActions.FindElement(ByLocater).Location.X;
            int y = webActions.FindElement(ByLocater).Location.Y;

            return(Tuple.Create(x, y));
        }
예제 #5
0
        // Получить клиентов (всех или с фильтром по городу)
        public IActionResult Index(int?CityID)
        {
            IEnumerable <City> CitiesList = WebActions.GetCities().Result;

            ViewData["Cities"] = new SelectList(CitiesList, "Id", "Name");

            if (!CityID.HasValue)
            {
                var Model = WebActions.GetClients().Result;
                ViewData["HeaderPage"] = "Клиенты";

                return(View(Model));
            }
            else
            {
                var Model = WebActions.GetClientsFromCity(CityID).Result;

                if (Model.Count() != 0)
                {
                    ViewData["HeaderPage"] = $"Клиенты из города {Model.ElementAtOrDefault(0).City}";
                    return(View(Model));
                }
                else
                {
                    return(NotFound($"Клиенты из города {CitiesList.FirstOrDefault(c => c.Id == CityID).Name} не найдены."));
                }
            }
        }
 public CommonActions(WebEnvironment testEnvironment)
 {
     TestEnvironment = testEnvironment;
     Waits           = new WebWaits(testEnvironment);
     Actions         = new WebActions(testEnvironment);
     Driver          = new DriverManager();
     Verify          = new WebVerify(testEnvironment);
     Logger          = new Logger();
 }
예제 #7
0
 public IActionResult DeleteClient(int?ClientID)
 {
     if (ClientID.HasValue)
     {
         WebActions.DeleteClient(ClientID);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(BadRequest());
     }
 }
        /// <summary>
        /// generic method to search and match string and click on any table row
        /// </summary>
        /// <param name="webActions"></param>
        /// <param name="tableLocater"></param>
        /// <param name="searchCriteria"></param>
        public static void ClickTableRowWithSearchCriteria(this WebActions webActions, By tableLocater, string searchCriteria)
        {
            IList <IWebElement> lstTrElem = webActions.FindElement(tableLocater).FindElements(By.TagName("tr"));

            System.Threading.Thread.Sleep(3000);
            IWebElement row = lstTrElem.Where(item => item.Text.Contains(searchCriteria)).FirstOrDefault();

            System.Threading.Thread.Sleep(1000);
            IList <IWebElement> cells = row.FindElements(By.TagName("td"));
            IWebElement         cell  = cells.Where(item => item.Text.Contains(searchCriteria)).FirstOrDefault();

            cell.Click();
            System.Threading.Thread.Sleep(3000);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="webActions"></param>
        /// <param name="rowNumber"></param>
        public static string ClickTableAtRowAndCellNumber(this WebActions webActions, By tableLocater, int rowNumber, int cellNumber)
        {
            string InvestigationID        = string.Empty;
            IList <IWebElement> lstTrElem = webActions.FindElement(tableLocater).FindElements(By.TagName("tr"));
            IWebElement         row       = lstTrElem[rowNumber];//for selecting first row
            IList <IWebElement> cells     = row.FindElements(By.TagName("td"));
            IWebElement         cell      = cells[cellNumber];

            InvestigationID = cell.Text;
            cell.Click();
            System.Threading.Thread.Sleep(3000);

            return(InvestigationID);
        }
예제 #10
0
 // Получить определённого клиента
 public IActionResult EditClient(int?ClientID)
 {
     if (ClientID.HasValue)
     {
         var Model = WebActions.GetClient(ClientID);
         IEnumerable <City> CitiesList = WebActions.GetCities().Result;
         ViewData["Cities"] = new SelectList(CitiesList, "Id", "Name");
         return(View("ClientView", Model.Result));
     }
     else
     {
         IEnumerable <City> CitiesList = WebActions.GetCities().Result;
         ViewData["Cities"] = new SelectList(CitiesList, "Id", "Name");
         ClientView NewClient = new ClientView();
         return(View("ClientView", NewClient));
     }
 }
 /// <summary>
 /// This click element is an extension to web action, it tried to supress the tiem out exception in login cases
 /// </summary>
 /// <param name="webActions"></param>
 /// <param name="locater"></param>
 public static bool ClickLogin(this WebActions webActions, By locater)
 {
     try
     {
         webActions.Click(locater);
         System.Threading.Thread.Sleep(3000);
         return(true);
     }
     catch (TimeoutException ex)
     {
         return(false);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
예제 #12
0
    /*
     *  Function: postOfflineAction
     *
     *  Handles actions if module is offline.
     *
     *  Parameters:
     *
     *  action - The desired action
     *  form - The WWWForm to submit to the server
     *  returnType - The type of data that needs to be returned
     *  callback - A function pointer to the method that will manage the returned data
     *
     *  See Also:
     *
     *  - <GoOffline>
     *  - <PostAction(WebActions, WWWForm, ReturnTypes, function)>
     */
    private void postOfflineAction(WebActions action, WWWForm form, ReturnTypes returnType, Action <Hashtable> callback)
    {
        if (offline == null)
        {
            offline = new Offline();
        }

        switch (action)
        {
        case WebActions.GetQuestions:
            TextAsset questionsXML = (TextAsset)Resources.Load(Assets.Resources.Data.Questions);
            Hashtable data         = GetQuestionDataFromXML(questionsXML.text);
            callback(data);
            break;

        default:
            Hashtable temp = new Hashtable();
            temp["data"] = true;
            callback(temp);
            break;
        }
    }
예제 #13
0
 public IActionResult SaveClient(ClientView CurrenClient)
 {
     if (ModelState.IsValid)
     {
         if (CurrenClient.Id == 0)
         {
             //post client
             WebActions.AddClient(CurrenClient);
             return(RedirectToAction("Index"));
         }
         else
         {
             //put client
             WebActions.EditClient(CurrenClient);
             return(RedirectToAction("Index"));
         }
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
예제 #14
0
        public static void Main()
        {
            Console.WriteLine("Hello World!");

            WebActions.launchWebApp("Chrome", "http://www.google.com");

            /*WebActions.Driver.FindElement(By.Name("q")).SendKeys("The name of the wind");
             * Thread.Sleep(8000);
             * WebActions.Driver.FindElement(By.XPath("//img[@alt='Google']")).Click();
             * WebActions.Driver.FindElement(By.XPath("//div[@class='FPdoLc VlcLAe']//input[@name='btnK']")).Click();
             * Console.Read();*/

            GoogleHome googleHome = new GoogleHome();

            PageFactory.InitElements(WebActions.Driver, googleHome);
            googleHome.search("The name of the wind");

            //PageFactory.InitElements(webActions.Driver, googleHome);
            Console.Read();
            WebActions.closeWebApp();

            //GoogleHome googleHome = PageFactory.initElements
        }
        /// <summary>
        /// Dynamic switching with the help of window handles and element
        /// </summary>
        /// <param name="webActions"></param>
        /// <param name="locater"></param>
        public static void SwitchToWindowWithElement(this WebActions webActions, By locater)
        {
            bool found   = false;
            int  counter = 0;

reAttempt:

            IReadOnlyCollection <string> allHandles = webActions.GetWindowHandles();

            foreach (string handle in allHandles)
            {
                webActions.SwitchToWindow(handle);
                if (webActions.IsElementPresent(locater))
                {
                    found = true;
                    break;
                }
            }

            if (!found && counter < 3)
            {
                goto reAttempt;
            }
        }
        /// <summary>
        /// This is an common extension method to wait for the APS update progess image to disappear
        /// </summary>
        /// <param name="webActions"></param>
        /// <param name="Locater">By locater for the update image</param>
        public static void WaitForUpdateProgressBar(this WebActions webActions, By Locater)
        {
            int  counter   = 0;
            bool Invisible = false;

retry:

            if (webActions.IsDisplayed(Locater))
            {
                counter++;
                System.Threading.Thread.Sleep(2000);
                Invisible = false;
            }
            else
            {
                Invisible = true;
            }


            if (counter < 30 && !Invisible)
            {
                goto retry;
            }
        }
 public CommonFunctions(WebEnvironment testEnvironment)
 {
     TestEnvironment = testEnvironment;
     Waits = new WebWaits(testEnvironment);
     Actions = new WebActions(testEnvironment);
 }
예제 #18
0
 public void TypeSearch(string textToSearch)
 {
     WebActions.sendTextToElement(inputSearchField, "google search field", textToSearch, false);
 }
예제 #19
0
 public void CloseSearchList()
 {
     WebActions.waitVisible(ulSuggestionList, "suggestion list", new TimeSpan(0, 0, 30), true);
     WebActions.clickElement(imgGoogle, "google logo", false);
 }
예제 #20
0
 /*
  *  Function: PostAction(WebActions, WWWForm, function)
  *
  *  Submits an action to the server
  *
  *  Parameters:
  *
  *  action - The desired action
  *  form - The WWWForm to submit to the server
  *  callback - A function pointer to the method that will manage the returned data
  *
  *  See Also:
  *
  *  - <PostAction(WebActions, function)>
  *  - <PostAction(WebActions, ReturnTypes, function)>
  *  - <PostAction(WebActions, WWWForm)>
  *  - <PostAction(WebActions, WWWForm, ReturnTypes, function)>
  */
 public void PostAction(WebActions action, WWWForm form, Action <Hashtable> callback)
 {
     PostAction(action, form, ReturnTypes.StringValue, callback);
 }
예제 #21
0
 /*
  *  Function: PostAction(WebActions, WWWForm)
  *
  *  Submits an action to the server
  *
  *  Parameters:
  *
  *  action - The desired action
  *  form - The WWWForm to submit to the server
  *
  *  See Also:
  *
  *  - <PostAction(WebActions, function)>
  *  - <PostAction(WebActions, ReturnTypes, function)>
  *  - <PostAction(WebActions, WWWForm, function)>
  *  - <PostAction(WebActions, WWWForm, ReturnTypes, function)>
  */
 void PostAction(WebActions action, WWWForm form)
 {
     PostAction(action, form, ReturnTypes.StringValue, DoNothing);
 }
예제 #22
0
 /*
  *  Function: PostAction(WebActions, ReturnTypes, function)
  *
  *  Submits an action to the server
  *
  *  Parameters:
  *
  *  action - The desired action
  *  returnType - The type of data that needs to be returned
  *  callback - A function pointer to the method that will manage the returned data
  *
  *  See Also:
  *
  *  - <PostAction(WebActions, function)>
  *  - <PostAction(WebActions, WWWForm)>
  *  - <PostAction(WebActions, WWWForm, function)>
  *  - <PostAction(WebActions, WWWForm, ReturnTypes, function)>
  */
 public void PostAction(WebActions action, ReturnTypes returnType, Action <Hashtable> callback)
 {
     PostAction(action, new WWWForm(), returnType, callback);
 }
예제 #23
0
 /*
  *  Function: PostAction(WebActions, function)
  *
  *  Submits an action to the server
  *
  *  Parameters:
  *
  *  action - The desired action
  *  callback - A function pointer to the method that will manage the returned data
  *
  *  See Also:
  *
  *  - <PostAction(WebActions, ReturnTypes, function)>
  *  - <PostAction(WebActions, WWWForm)>
  *  - <PostAction(WebActions, WWWForm, function)>
  *  - <PostAction(WebActions, WWWForm, ReturnTypes, function)>
  */
 private void PostAction(WebActions action, Action <Hashtable> callback)
 {
     PostAction(action, new WWWForm(), ReturnTypes.StringValue, callback);
 }
예제 #24
0
 public bool IsSuggestionListVisible()
 {
     return(WebActions.isVisible(ulSuggestionList, "suggestion list", new TimeSpan(0, 0, 30), true));
 }
예제 #25
0
 public void PressSearchButton()
 {
     WebActions.clickElement(btnGoogleSearch, "google search button", false);
 }
예제 #26
0
 public bool CheckPage()
 {
     return(WebActions.isVisible(btnGoogleSearch2, "google search button", new TimeSpan(0, 0, 30), true));
 }
예제 #27
0
 public void ClickOnelementFromSuggestionList(int elementPosition)
 {
     WebActions.clickElement(ulSearchSuggestionElements.ElementAt(elementPosition), "element '"
                             .Concat(string.Format((elementPosition + 1).ToString()))
                             .Concat("' from suggestion list").ToString(), false);
 }
예제 #28
0
 public bool checkPage()
 {
     return(WebActions.isVisible(opcAllResults2, "all results option", new TimeSpan(0, 0, 30), true));
 }
예제 #29
0
 public string getResult(int position)
 {
     return(WebActions.getTextFromElement(lnkResults.ElementAt(position), " search result", false));
 }
예제 #30
0
 public void clickFirstResult(int position)
 {
     WebActions.clickElement(lnkResults.ElementAt(position), " search result", false);
 }