设为首页 收藏本站
查看: 1094|回复: 0

[经验分享] SharePoint网站测试数据自动化系列——通过Coded UI录制脚本自动化创建SharePoint Designer Reusable Workflow

[复制链接]

尚未签到

发表于 2015-9-24 10:09:50 | 显示全部楼层 |阅读模式
  Coded UI非常好,我开始还在想,怎么样能让一个通过SharePoint Designer创建的Workflow publish三百五十次?想不到一个好的方法,也不知道SharePoint Designer里那个publish按钮调用的是什么方法,想来想去还是用Coded UI尝试了一下,发现也挺好,在资源允许的情况下,就这样完成了SPD Workflow的自动化创建:
  1. 首先,你得有个SPD Workflow
DSC0000.png
  2. 通过我第一次录制的脚本发现,SharePoint本身有个bug,就是如果你在Publish完这个Reusable Workflow之后如果不去SharePoint List的Workflow Settings页面刷新一下的话,这个Publish的版本根本就没有创建成功,于是我第二次录制的脚本中有多了一步,就是在Publish Workflow之后要去往Workflow Settings页面刷新一下,这样就能确保Workflow每次Publish都是成功的:
DSC0001.png
  
  具体的脚本流程如下(Coded UI具体用法详见我之前发表的一篇文章里有介绍),其实和你操作SharePoint Designer Publish Workflow的步骤是一样的,只不过在最后两步——Publish Workflow和刷新Workflow Settings页面这里我加了一个循环,以达到自动化创建欲达到的次数,就是这样(过程详见我注释行括号中加的汉语):



public void RecordedMethod()
{
#region Variable Declarations
WinButton uIItem30828CI1Button = this.UIHttpmgluca10000sitesWindow.UIItem30828CI1ListItem.UIItem30828CI1Button;
WinButton uIWorkflowsButton = this.UIHttpmgluca10000sitesWindow.UIWorkflowsListItem.UIWorkflowsButton;
WinListItem uIRe10ListItem = this.UIHttpmgluca10000sitesWindow.UIItemWindow1.UIItemList.UIRe10ListItem;
WinButton uIPublishButton = this.UIHttpmgluca10000sitesWindow.UIItemWindow.UISaveToolBar.UIPublishButton;
WinEdit uIAddressEdit = this.UIMsnWindowsInternetExWindow.UIItemWindow.UIAddressBarClient.UIAddressEdit;
BrowserWindow uIMsnWindowsInternetExWindow = this.UIMsnWindowsInternetExWindow;
HtmlHyperlink uIShareHyperlink = this.UIMsnWindowsInternetExWindow.UIWorkflowSettingsDocument.UIShareHyperlink;
HtmlDocument uIWorkflowSettingsDocument = this.UIMsnWindowsInternetExWindow.UIWorkflowSettingsDocument;
#endregion
// Launch '%ProgramW6432%\Microsoft Office\Office15\SPDESIGN.EXE'(打开SPD)
ApplicationUnderTest sPDESIGNApplication = ApplicationUnderTest.Launch(this.RecordedMethod4Params.ExePath, this.RecordedMethod4Params.AlternateExePath);
// Click '30828CI1' button(点击相应的站点)
Mouse.Click(uIItem30828CI1Button, new Point(48, 10));
// Click 'Workflows' button(点击Workflows)
Mouse.Click(uIWorkflowsButton, new Point(54, 7));
// Click 're10' list item(点击相应的Workflow)
Mouse.Click(uIRe10ListItem, new Point(35, 13));
// Click 'Publish' button(点击Publish按钮)
Mouse.Click(uIPublishButton, new Point(13, 31));
// Go to web page 'http://go.microsoft.com/fwlink/p/?LinkId=255141' using new browser instance(打开浏览器)
this.UIMsnWindowsInternetExWindow.LaunchUrl(new System.Uri(this.RecordedMethod4Params.UIMsnWindowsInternetExWindowUrl));
// Click 'Address' text box(点击浏览器地址栏)
Mouse.Click(uIAddressEdit, new Point(216, 2));
// Go to web page 'http://mglu-ca:10000/sites/30828CI1/_layouts/15/WrkSetng.aspx?List={C9B1EDD4-8B24-4115-9753-3113D02BE3C1}'(输入Workflow Settings页面的地址)
uIMsnWindowsInternetExWindow.NavigateToUrl(new System.Uri(this.RecordedMethod4Params.UIMsnWindowsInternetExWindowUrl1));
// Set flag to allow play back to continue if non-essential actions fail. (For example, if a mouse hover action fails.)
Playback.PlaybackSettings.ContinueOnError = true;
// Mouse hover 'Share' link at (8, 3)
Mouse.Hover(uIShareHyperlink, new Point(8, 3));
// Reset flag to ensure that play back stops if there is an error.
Playback.PlaybackSettings.ContinueOnError = false;
int i=0;
while (i < 350)
{
// Click 'Publish' button(点击Publish按钮)
Mouse.Click(uIPublishButton, new Point(23, 31));
// Type '{F5}' in 'Workflow Settings' document(刷新Workflow Settings页面)
Keyboard.SendKeys(uIWorkflowSettingsDocument, this.RecordedMethod4Params.UIWorkflowSettingsDocumentSendKeys, ModifierKeys.None);
}
}
  就这样,一个自动化创建SPD Workflow的任务就完成了,还挺快的,一分钟差不多创建10个SPD Workflow左右,半个小时左右弄完。
  不过这是通过最接近用户操作的方法实现的,却不是通过直接调用相关API实现的。
  还希望有大神能给出直接调用相关API实现Publish SPD Workflow的方法,共同学习,共同进步。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-118074-1-1.html 上篇帖子: 我们该用怎么样的系统思维来了解SharePoint及其价值 下篇帖子: 用色彩区分 SharePoint 2010 Calendar 的日历项
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表