zoukankan      html  css  js  c++  java
  • C#中模拟用户登陆SharePoint网站

    自动化测试一个SharePoint网站,首先要登陆,我们今天就模拟一下用户登陆SharePoint网站的过程,这一过程可以通过其他方式完成模拟,比如通过Coded UI Test录制脚本会更方便,但是这里主要介绍通过API结合Selenium2.0来实现这个过程:

    首先我们要创建一个C#的Project,什么类型的都可以,这里拿控制台程序举例(需要引入System.Windows.Forms包),程序如下:

    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网站。

  • 相关阅读:
    微信小程序 使用async await
    CSS currentColor 变量的使用
    wn.run万能命令
    (13)浮动布局(控制盒模型在页面的什么位置 什么是清浮动)
    (0)前端总结(HTML + CSS + JQ)
    (12)页面的布局(浮动布局)
    (11)盒模型
    (10)背景图片操作
    (9)字体操作
    (8)伪类选择器和鼠标悬停动画效果
  • 原文地址:https://www.cnblogs.com/LanTianYou/p/4522099.html
Copyright © 2011-2022 走看看