Can we use White for Web App?

Jan 10, 2011 at 12:40 PM

Hi !

I have tried to use White for a WinForm Application and I know it works. So I tried also for a web application , I can launch the page but I don't how to get the window?

Please suggest if you have an idea. Thanks .

___________

Here is my code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using White.Core;
using White.Core.UIItems;
using White.Core.Factory;
using White.Core.UIItems.WindowItems;
using White.Core.UIItems.WindowStripControls;
using White.Core.UIItems.MenuItems;
using White.Core.UIItems.ListBoxItems;
using White.Core.UIItems.TreeItems;
using White.Core.UIItems.Finders;
using White.Core.WindowsAPI;

namespace WebTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = @"http://localhost:51107/Default.aspx";
            Application application = Application.Launch(path);
          //  Window window = application.GetWindow("What can I write here?")
        }
    }
}

Jan 10, 2011 at 1:08 PM

Hi

is this a silverlight application?

For Silverlight there is an other workflow, as I know.

If not, try

 

List<Window> windows = application.GetWindows();

and have a look what elements are in the list.

Throndorin

Jan 10, 2011 at 1:17 PM

Hi Throndorin , thanks for the reply :)

It is a simple web app without silverlight.

I am just trying to  open the web page et write in the textbox of the web application.

I tried this  but there is a exception : "Object reference not set to an instance of an object." for 

 windows = application.GetWindows();

 

namespace WebTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = @"http://localhost:51107/Default.aspx";
            Application application = Application.Launch(path);
            List<Window> windows = new List<Window>();
            windows = application.GetWindows();
            foreach (Window w in windows)
            {
               // TextBox tNom = w.Get<TextBox>(SearchCriteria.ByAutomationId("TextBox1"));
               // tNom.Text = "test";
            }
            
        }
    }
}

Jan 10, 2011 at 1:21 PM

 

Ah ok , then the application object is null

"Application application = Application.Launch(path)" starts the application??

Maybe a better solution is to start the application first with full path to the executable.

than enter the address in the application address field

 

 

 

Jan 10, 2011 at 1:26 PM
Edited Jan 10, 2011 at 1:32 PM

Do you mean :

Application application = Application.Launch("path_to_firefox"); for exqmple, but how to get the address field then? I don't know the field name contrqry to form I create.

My problem is that I understand how it works for WinForm application but not for web because it doesn't use only my code :s 

For example , in my WinForm I just have to do 
TextBox tNom = window.Get<TextBox>("textBox1");
and then 
tNom.Text = name;

otherwise here I don't know how to access to the adresse field
Jan 10, 2011 at 1:36 PM

 

is the same for all applications, if not silverlight

 

use a tool like UISpy or AUIVerify to find out the automation id or name of a control, step over the control hierarchy, to get the correct Control

 

the address field is an edit field with a name, without an automation ID

 

So try

 

Window firefox = application.GetWindow("title") // the actual title 
TextBox address = firefox.Get<TextBox> SearchCriteria.ByText("the address field name from UISpy "); // in German "Lesezeichen und Chronik durchsuchen"
address.BulkText =@"http://localhost:51107/Default.aspx";
firefox.Keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.ENTER); 

 

 

Throndorin

 

 

 

Jan 10, 2011 at 1:41 PM

Ok thanks a lot Throndorin :) 

I understand better now, I will try that !

Jan 10, 2011 at 2:26 PM
Edited Jan 10, 2011 at 3:07 PM

There was a small mistake in your code Throndorin,

firefox.Get<TextBox>(SearchCriteria.ByText("the address field name from UISpy "));

But It doesn't work for the moment :( I test with textBox and combobox because Uispy says it is a combobox.

Identification    

ClassName: ""    

ControlType: "ControlType.ComboBox"    

Culture: "(null)"    

AutomationId: ""    

LocalizedControlType: "combo box"    

Name: "Search Bookmarks and History"    

Here is what I have : http://img202.imageshack.us/i/screenshotstudiocapturez.png/

I found the name was "Search Bookmarks and History" so I have tried this :

 

 

namespace WebTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = @"C:\Program Files\Mozilla Firefox\firefox.exe";
            Application application = Application.Launch(path);
            Window firefox = application.GetWindow("Google - Mozilla Firefox"); // title when ff is launched
            ComboBox address = firefox.Get<ComboBox>(SearchCriteria.ByText("Search Bookmarks and History")); // in German "Lesezeichen und Chronik durchsuchen"
            address.SetValue(@"http://localhost:51107/Default.aspx");
            firefox.Keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.BACKSPACE); 
            
            
            
        }
    }
}

 

EDIT : I have this error message http://img171.imageshack.us/i/screenshotstudiocapturef.png/

Jan 10, 2011 at 3:22 PM
Edited Jan 10, 2011 at 3:41 PM

I found a way like that but it is not really what I wanted to do :s

namespace WebTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = @"C:\Program Files\Internet Explorer\iexplore.exe";
            Application application = Application.Launch(path);
            Window ie = application.GetWindow("Blank Page - Windows Internet Explorer"); // title when ff is launched
            ie.Keyboard.Enter(@"http://localhost:51107/");
            
            /*TextBox address = ie.Get<TextBox>(SearchCriteria.ByText("")); // in German "Lesezeichen und Chronik durchsuchen"
            address.SetValue(@"http://localhost:51107/Default.aspx");*/

            ie.Keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.RETURN); 
            
            
            
        }
    }
}


But now, How can I write into my textbox ? I tried this but same bug, null reference exception 

TextBox t1 = ie.Get<TextBox>(SearchCriteria.ByAutomationId("TextBox1"));                       
t1.Text = "test";                        
Jan 11, 2011 at 6:13 AM

Hi

1. there is an edit box in the next layer (under the comboBox with the same name as the combobox (Firefox)

 

in the last problem try the following

 

AutomationElement element = ie.GetElement(SearchCriteria.ByAutomationId("TextBox1"));

 

is the element null?

 

if not

 

TextBox box = new TextBox(element, ie.ActionListener);

box.BulkText = "test";

 

 

Throndorin

 

 

Jan 11, 2011 at 8:30 AM

Hi ,

 

I don't find how to use Automation Element,

 

I tried with q reference in system32 but it doesn't work :s

using System;
using System.Collections.Generic;
using System.Linq;

using White.Core;
using White.Core.UIItems;
using White.Core.UIItems.WindowItems;
using White.Core.UIItems.WindowStripControls;
using White.Core.UIItems.MenuItems;
using White.Core.UIItems.Custom;
using White.Core.UIItems.ListBoxItems;
using White.Core.UIItems.TreeItems;
using White.Core.UIItems.Finders;
using White.Core.WindowsAPI;


using UIAutomationClient;
using UIAutomationCrossBitnessHookLib;

Jan 11, 2011 at 8:43 AM

 

you should reference all .Net Libraries starting with UIAutomation

and use:

 

using System.Windows.Automation;
Jan 11, 2011 at 8:57 AM
Edited Jan 11, 2011 at 9:11 AM

I think it is not normal that using System.Windows.Automation doesn't work ? I am looking for informations on the web :s Do you have an idea? 

I can add System.Windows.Form but not automation !

Sorry for all these questions!

Jan 11, 2011 at 9:13 AM
Edited Jan 11, 2011 at 9:19 AM

What is the problem?

do you use Visual Studio?

 

my references:

 

WindowsBase
System.Core
System.Data
System.Data.DataSetExtensions
System.Drawing
System.Xml
System.Xml.Linq
UIAutomationClient
UIAutomationClientsideProviders
UIAutomationProvider
UIAutomationTypes
White.Core
White.NUnit
System
System.configuration
nunit.framework

Jan 11, 2011 at 9:19 AM

Yep 2010 professinal version for the work.

I add some references and now using System.Windows.Automation; works but AutomationElement is still not recognized. 

Jan 11, 2011 at 11:59 AM

mmh strange,

 

clean and rebuild don't help?

Jan 11, 2011 at 12:45 PM
Edited Jan 11, 2011 at 12:46 PM

Not really :/ I will try again if I have to, because I have an other work to do on White now using simple winform here