disable IE visibility while using WatiN

前端 未结 2 1802
北荒
北荒 2020-12-22 00:40

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 t

相关标签:
2条回答
  • 2020-12-22 01:21

    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
    0 讨论(0)
  • 2020-12-22 01:24

    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.

    0 讨论(0)
提交回复
热议问题