博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#中模拟用户登陆SharePoint网站
阅读量:6994 次
发布时间:2019-06-27

本文共 1531 字,大约阅读时间需要 5 分钟。

自动化测试一个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网站。

转载地址:http://oeivl.baihongyu.com/

你可能感兴趣的文章
django笔记
查看>>
BZOJ5285 & 洛谷4424 & UOJ384:[HNOI/AHOI2018]寻宝游戏——题解
查看>>
GitHub上受欢迎的Android UI Library
查看>>
转载: 做螺丝太久了,看不到全貌,期待的好文:分布式架构的前世今生...
查看>>
[转] pytorch指定GPU
查看>>
MemoryStream和FileStream
查看>>
R语言 机器学习包
查看>>
BIOS与EC之间关系
查看>>
杀手-科大讯飞18.09.07校招笔试
查看>>
函数概述
查看>>
WinForm DataGridView 中的小bug.
查看>>
python虚拟环境--virtualenv
查看>>
螺旋数组
查看>>
js中return;、return true、return false;区别
查看>>
python 基础复习 05
查看>>
那些恶心人的Screen基本概念
查看>>
Windows Live Writer配置步骤
查看>>
[转]为什么不读顶级会议论文?
查看>>
策略模式(Strategy Pattern)
查看>>
Java程序基本概念
查看>>