disable IE visibility while using WatiN

為{幸葍}努か 提交于 2019-12-29 09:27:10

问题


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");
       }

回答1:


The WatIn.Core.IE class has a Visible property, you can initialize the object like that:
new WatiN.Core.IE() { Visible = true }

This way the IE will just blink on the screen when it's created, and then it will get hidden. You can later control the visibility of the IE with the ShowWindow method of WatiN.Core.IE class - I mean you can show it on the screen if you need, or you can hide again.




回答2:


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:

  • https://github.com/TeamMentor/Dev/tree/master/Source_Code/TM_UnitTests/TeamMentor.UnitTests.QA/TeamMentor_QA_IE
  • http://blog.diniscruz.com/2014/07/how-to-debug-cassini-hosted-website-and.html
  • http://blog.diniscruz.com/2014/07/using-watin-and-embedded-cassini-to-run.html
  • http://blog.diniscruz.com/search/label/WatiN


来源:https://stackoverflow.com/questions/27429361/disable-ie-visibility-while-using-watin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!