C#中類比使用者登陸SharePoint網站

來源:互聯網
上載者:User

標籤:

自動化測試一個SharePoint網站,首先要登陸,我們今天就類比一下使用者登陸SharePoint網站的過程,這一過程可以通過其他方式完成類比,比如通過Coded UI Test錄製指令碼會更方便,但是這裡主要介紹通過API結合Selenium2.0來實現這個過程:

首先我們要建立一個C#的Project,什麼類型的都可以,這裡拿控制台程式舉例,程式如下:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using OpenQA.Selenium;using OpenQA.Selenium.IE;using OpenQA.Selenium.Support;using OpenQA.Selenium.Support.UI;using Selenium;using mySelenium;using System.Runtime.InteropServices;namespace mySelenium{    class Program    {        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]        public static extern IntPtr GetForegroundWindow();        static void Main(string[] args)        {            IWebDriver driver = new InternetExplorerDriver();            INavigation navigation = driver.Navigate();            navigation.GoToUrl("SharePoint網站url");            driver.FindElement(By.Id("overridelink")).Click();            IntPtr myPtr = GetForegroundWindow();            //IntPtr hWnd = FindWindow(null, "abc");            if (myPtr != IntPtr.Zero)             {                //Send message to the window.                System.Windows.Forms.SendKeys.SendWait("使用者名稱");                System.Windows.Forms.SendKeys.SendWait("{TAB}");                System.Windows.Forms.SendKeys.SendWait("密碼");                System.Windows.Forms.SendKeys.SendWait("{ENTER}");            }           }    }}

PS:這裡需要引入Selenium 2.0的幾個dll檔案,添加引用:

並引入IEDriverServer.exe,這個過程可以點這裡查看。

然後按F5運行程式即可自動登陸SharePoint網站。

C#中類比使用者登陸SharePoint網站

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.