禁用IE的知名度,同时使用华廷 [英] disable IE visibility while using WatiN

查看:148
本文介绍了禁用IE的知名度,同时使用华廷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用华廷,因为我需要在哪些用户需要支持Javascript后台打开某些网站。我不知道华廷是最适合这份工作,不过目前它需要很长时间,直到Internet Explorer中变得可见。我需要禁用弹出的Internet Explorer在使用华廷。用户并不需要看到站点的开口。是否有可能同时使用华廷访问一个网站没有显示的用户或我应该使用支持在客户端JS另一种选择?
我的code的时刻;

 公共静态无效visitURL()
       {
           IE iehandler =新的IE(http://www.isjavascriptenabled.com);           如果(iehandler.ContainsText(是))
               Console.WriteLine(关于JS);
           其他
               Console.WriteLine(js的关);
       }


解决方案

我用的正是这种把戏写单元测试(使用的 https://github.com/o2platform/FluentSharp_Fork.WatiN

例如<一个href=\"https://github.com/TeamMentor/Dev/blob/e8ee2cc24f49862c501f3cb7d0ddebc5ea3e9454/Source_$c$c/TM_UnitTests/TeamMentor.UnitTests.Cassini/_API_TeamMentor/IE_TeamMentor/IE_TeamMentor.cs#L16\"相对=nofollow>这里是如何我创建了一个辅助类(与配置的潜在价值)

 公共IE_TeamMentor(Webroot的字符串,字符串path_XmlLibraries,乌里siteUri,布尔startHidden)
    {
        this.ie =Test_IE_TeamMentor.popupWindow(1000,700,startHidden).add_IE();
        this.path_XmlLibraries = path_XmlLibraries;
        this.webRoot = Webroot的;
        this.siteUri = siteUri;
    }

,然后通过<消耗的href=\"https://github.com/TeamMentor/Dev/blob/master/Source_$c$c/TM_UnitTests/TeamMentor.UnitTests.QA/TeamMentor_QA_IE/Test_QA__Markdown_Editor.cs\"相对=nofollow>这个测试:

  [测试]公共无效View_Markdown_Article__Edit__Save()
    {
        VAR文章= tmProxy.editor_Assert()//断言编辑用户(或下方的通话将失败归因于安全需求)
                                      .library_New_Article_New()//创建新文章
                                      .assert_Not_Null();        变种ie​​TeamMentor = this.new_IE_TeamMentor_Hidden();
        无功即= ieTeamMentor.ie;
        ieTeamMentor.login_Default_Admin_Account(/条/ {0}格式(article.Metadata.Id)); //以管理员身份登录,然后重定向到文章页面        VAR original_Content = ie.element(guidanceItem)的innerText()assert_Not_Null()。 //获取引用当前内容
        ie.assert_Has_Link(降价编辑器)
          。.LINK(降价编辑器),点击(); //公开降价编辑器页面        ie.wait_For_Element_InnerHtml(内容)。assert_Not_Null()
          .element(内容)。innerHTML的()
                                                .assert_Is(original_Content); //确认内容匹配什么是视图页面上        VAR NEW_CONTENT =这是本文的新内容.add_5_Ra​​ndomLetters(); //新的考试内容        。ie.element(内容)to_Field()值(NEW_CONTENT); //放在降价编辑器的新内容
        ie.button(保存)点击()。 // 保存
        ie.wait_For_Element_InnerHtml(guidanceItem)。assert_Not_Null()
          .element(guidanceItem)。innerHTML的()
                                                     .assert_Is(&所述p为H.; {0}&下; / P&gt;中的格式(NEW_CONTENT)); //确认考试内容保存OK(并转化降价)        ieTeamMentor.close();
    }

下面是一些职位,可以帮助你了解我如何使用它:

I use watin, because I need to open some websites in the background for which the user needs to support Javascript. I don't know if WatiN is the best for this job, but at the moment it takes very long until Internet Explorer gets visible. I need to disable to popping up of Internet Explorer while using WatiN. User doesn't need to see the opening of sites. Is it possible while using WatiN to visit a website without showing it the user or should I use another alternative which supports JS on client side? My code at the moment;

    public static void visitURL()
       {
           IE iehandler = new IE("http://www.isjavascriptenabled.com");

           if (iehandler.ContainsText("Yes"))
               Console.WriteLine("js on");
           else
               Console.WriteLine("js off");
       }

解决方案

I use exactly that trick (of hiding IE) for writing UnitTests (using https://github.com/o2platform/FluentSharp_Fork.WatiN) that run in an hidden IE window

For example here is how I create a helper class (with an configurable hidden value)

    public IE_TeamMentor(string webRoot, string path_XmlLibraries, Uri siteUri, bool startHidden)
    {
        this.ie                = "Test_IE_TeamMentor".popupWindow(1000,700,startHidden).add_IE();            
        this.path_XmlLibraries = path_XmlLibraries;
        this.webRoot           = webRoot;
        this.siteUri           = siteUri;
    }

which is then consumed by this test:

   [Test] public void View_Markdown_Article__Edit__Save()
    {
        var article          = tmProxy.editor_Assert()                       // assert the editor user (or the calls below will fail due to security demands)
                                      .library_New_Article_New()             // create new article
                                      .assert_Not_Null(); 

        var ieTeamMentor     = this.new_IE_TeamMentor_Hidden();
        var ie               = ieTeamMentor.ie; 
        ieTeamMentor.login_Default_Admin_Account("/article/{0}".format(article.Metadata.Id));               // Login as admin and redirect to article page

        var original_Content = ie.element("guidanceItem").innerText().assert_Not_Null();                    // get reference to current content
        ie.assert_Has_Link("Markdown Editor")       
          .link           ("Markdown Editor").click();                                                      // open markdown editor page          

        ie.wait_For_Element_InnerHtml("Content").assert_Not_Null()
          .element                   ("Content").innerHtml()
                                                .assert_Is(original_Content);                               // confirm content matches what was on the view page

        var new_Content      = "This is the new content of this article".add_5_RandomLetters();             // new 'test content'

        ie.element("Content").to_Field().value(new_Content);                                                // put new content in markdown editor
        ie.button("Save").click();                                                                          // save 
        ie.wait_For_Element_InnerHtml("guidanceItem").assert_Not_Null()        
          .element                   ("guidanceItem").innerHtml()
                                                     .assert_Is("<P>{0}</P>".format(new_Content));         // confirm that 'test content' was saved ok (and was markdown transformed)            

        ieTeamMentor.close();
    }

Here are a number of posts that might help you to understand how I use it:

这篇关于禁用IE的知名度,同时使用华廷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆