.net - Is it possible to use Selenium with C# windows Form that contains a WebBrowser object? -


i'm wondering if it's possible use selenium c# windows form contains webbrowser object.

i'm using selenium , i'm able create test cases selenium script record; i'm trying pinpoint whether or not can export c# code , have run within c# environment. appreciate thoughts or explanations.

update got point have selenium open winform contains webbrowser component. there test won't execute. looks doesn't understand selenium command. don't see error messages being thrown though. hmmm

the thing winformwithwebbrowsertest.exe opens winform webbrowser opened. nothing happens. below code 1 fires .exe

test code (selenium command)

namespace classlibrary1 {     class class2     {         private iselenium selenium;         private stringbuilder verificationerrors;          [setup]         public void setuptest()         {              selenium = new defaultselenium                 ("localhost", 4444, "*custom c:\\users\\m-tak\\documents\\visual studio 2010\\projects\\winformwithwebbrowsertest\\winformwithwebbrowsertest\\bin\\release\\winformwithwebbrowsertest.exe", "http://www.livemocha.com");              selenium.start();             verificationerrors = new stringbuilder();         }          [teardown]         public void teardowntest()         {             selenium.stop();         }          [test]         public void theuntitledtest()         {             //nothing here gets executed :(             console.writeline("foobar front");             selenium.open("/");             console.writeline("foobar");             selenium.waitforpagetoload("30000");             selenium.open("/users/logout");             selenium.open("/users/login");           }      } } 

.exe

namespace windowsformsapplication1 {     public partial class form1 : form     {         public form1()         {             initializecomponent();         }          private void webbrowser1_documentcompleted(object sender, webbrowserdocumentcompletedeventargs e)         {            //this gets executed always......             htmlelement head = webbrowser1.document.getelementsbytagname("body")[0];              htmlelement scriptone = webbrowser1.document.createelement("script");             ihtmlscriptelement element = (ihtmlscriptelement)scriptone.domelement;             element.text = "function sayhello() { " +                  "alert('hello');" +                 " }" ;             head.appendchild(scriptone);             webbrowser1.document.invokescript("sayhello");           }         //getter setter.....          public webbrowser getwebbrowser()          {             return this.webbrowser1;          }         public void setwebbrowser(webbrowser wb)          {             this.webbrowser1 = wb;         }          //just address bar         private void button1_click(object sender, eventargs e)         {             if (!string.isnullorempty(textbox1.text))             {                 webbrowser1.navigate(textbox1.text);             }         }          //just address bar         private void webbrowser1_navigated(object sender, webbrowsernavigatedeventargs e)         {             if (textbox1.text != e.url.tostring())             {                 textbox1.text = e.url.tostring();             }         }      } } 

update

i made test simple don't use nunit. i've created c# console app run c# .exe file. in console output "--1--" , "--2--" only..

using system; using system.collections.generic; using system.linq; using system.text; using system.web; using selenium;  namespace consoleapplication1 {     class program     {         static void main(string[] args)         {              console.writeline("-- 1---");             iselenium selenium;               selenium = new defaultselenium                 ("localhost", 4444, "*custom c:\\users\\m-takayashiki\\documents\\visual studio 2010\\projects\\winformwithwebbrowsertest\\winformwithwebbrowsertest\\bin\\release\\winformwithwebbrowsertest.exe", "http://www.livemocha.com");              console.writeline("-- 2---");              selenium.start();              console.writeline("-- 3---");               selenium.open("/");             selenium.waitforpagetoload("30000");             selenium.open("/users/logout");             selenium.open("/users/login");               console.writeline("test test test");              //tear down             selenium.stop();          }     } } 

update

i checked rc log:

15:40:35.379 debug [13] org.openqa.jetty.http.httpcontext - handler org.openqa.selenium.server.seleniumdriverresourcehandler in httpcontext[/selenium-server,/selenium-server] 15:40:35.380 debug [13] org.openqa.selenium.server.seleniumdriverresourcehandler - req: post /selenium-server/driver/ http/1.1 content-type: application/x-www-form-urlencoded; charset=utf-8 host: localhost:4444 content-length: 247 expect: 100-continue connection: keep-alive  15:40:45.408 debug [13] org.openqa.selenium.server.framegroupcommandqueueset - waiting window 'null' local frame 'null' 1790 more secs 15:40:45.408 debug [13] org.openqa.selenium.server.framegroupcommandqueueset - waiting condition 1000 more ms 15:40:45.945 debug [12] org.openqa.selenium.server.framegroupcommandqueueset - got condition? : false 

i haven't done selenium, did same thing watin when wanted automate infopath. approach took follows:

  1. kill off processes have name in case "infopath"

    foreach (process proc in process.getprocessesbyname("infopath")) {       proc.kill(); } 
  2. launch test application call process.getprocessesbyname process id's window handle of first there should 1 process running.

    process[] updatedinfopathprocesslist = process.getprocessesbyname("infopath"); if (updatedinfopathprocesslist[0].id == 0) {     throw new applicationexception("no infopath processes exist"); } infopathprocessid = updatedinfopathprocesslist[0].id; infopathhwnd = updatedinfopathprocesslist[0].mainwindowhandle; 
  3. now had window handle, ihtmldocument2 automate against watin.

    internalhtmldomdocument = iedom.iedomfromhwnd(this.hwnd); 

the real rubber hits road in iedom class ... code below ...

    namespace itin     {         public class iedom         {              internal static ihtmldocument2 iedomfromhwnd(intptr hwnd)             {                 guid iid_ihtmldocument2 = new guid("626fc520-a41e-11cf-a731-00a0c9082637");                  int32 lres = 0;                 int32 lmsg;                 int32 hr;                  //if (isietridentdlgframe(hwnd))                 //{                     if (!isieserverwindow(hwnd))                     {                         // 1st child ie server window                         hwnd = nativemethods.getchildwindowhwnd(hwnd, "internet explorer_server");                     }                      if (isieserverwindow(hwnd))                     {                         // register message                         lmsg = nativemethods.registerwindowmessage("wm_html_getobject");                         // object                         nativemethods.sendmessagetimeout(hwnd, lmsg, 0, 0, nativemethods.smto_abortifhung, 1000, ref lres);                         if (lres != 0)                         {                             // object lres                             ihtmldocument2 iedomfromhwnd = null;                             hr = nativemethods.objectfromlresult(lres, ref iid_ihtmldocument2, 0, ref iedomfromhwnd);                             if (hr != 0)                             {                                 throw new comexception("objectfromlresult has thrown exception", hr);                             }                             return iedomfromhwnd;                         }                     }                // }                 return null;             }              internal static bool isietridentdlgframe(intptr hwnd)             {                 return utilityclass.compareclassnames(hwnd, "internet explorer_tridentdlgframe");             }              private static bool isieserverwindow(intptr hwnd)             {                 return utilityclass.compareclassnames(hwnd, "internet explorer_server");             }         }     } 

sorry not selenium, how solved problem watin hope can help. code here http://itin.codeplex.com/, , think has been added watin well.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -