How to populate the fields in browser using Java or C# - c#

As I have a web form I need to fill in repeatedly, can I construct a Java or C# program to populate the form automatically? For example below is a sample contact us form, I wish that when I click on the Java or C# program, the form could be filled in automatically. How to achieve this?

maybe you need to use some autotesting techology. For example: selenium (Java), watir (Ruby), watin (.net).
Those tool provide browser abstraction that help manipulate with page and controls on it.
There is little example:
package selenium.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class ExampleSearch {
public static void main(String[] args) {
WebDriver driver = new HtmlUnitDriver();
// Open Google
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("selenium best practices");
// Send form with element
element.submit();
}
}

JavaScript is a much better way to do this. Use the right tool for the right job.

Related

How do I add Hyperlinking in NUnit Test Output?

I want to be able to add hyperlinks to relevant data in the output for a unit test.
I have the following test:
using NUnit.Framework;
namespace BioFire.PanelSoftware.Service.Tests
{
[TestFixture]
public class SimpleTest
{
[Test]
public void Test1()
{
Console.WriteLine("www.google.com"); //not hyperlink
Console.WriteLine(#"C:\Program Files"); //not hyperlink
throw new Exception("My output window will somehow give me a hyperlink to here.");
}
}
}
According to this question, it isn't possible in C#. But it is clearly working for nUnit somehow:
This is very specific to the terminal you are using and I don't believe anything in C# can achieve clickable text. You can technically use Process.Start() from the System.Diagnostics namespace to trigger the default browser to open the webpage you want, but this isn't a hyperlink and would rather be triggered by your specifications
If you are running from within an IDE, you would have to look into the underlying shell and try to swap it out for a different profile (ex. this should be easy on VS Code but I'm unsure if Visual Studio can support it). If you are running from cmd line, then try using the new Windows Terminal App as it supports this functionality

Accessing ComInterface to VB6 OCX Control with win32 handle in c#

I’m at the moment automating the test for a legacy application developed in vb6, which uses a GridEx2000b Control from Janus Systems.
For doing this I’m using Ranorex as my favorite tool for developing the test automation, so that I can develop the test code using c#.
My problem now is to automate the GridEx 2000b control, which Ranorex out of-the-box don’t have any support for. Therefore I’m trying to figure out a solution where I can reference the GrixEx control using the Win32 handle I can find for the control, so I can use the ComInterface from the component to navigate the automate the control.
I have an idea of a solution but I cannot figure out how to do it, where I hope that you guys would be able help me.
The pseudo code for the problem:
using GridEX20;
class GridExWrapper
{
public GridEX20.GridEXClass Instance;
public GridExWrapper(IntPtr win32handle)
{
Instance = (GridEX20.GridEXClass)Win32ControlUtilities.GetControlReference(win32Handle);
}
}
class Win32ControlUtilities
{
public static SomeKindOfHandle GetControlReference(IntPtr win32Handle)
{
...
...
...
}
}
I’ll get the win32handle from Ranorex or some other spy tool.
Then I can use the GridExWrapper like this.
using NUnit.Framework;
class Program
{
[Test]
public void control_should_have_9_items()
{
/// Get win32 handle from Ranorex
IntPtr win32handle = XXXXXX;
int expectedItemCount = 9;
GridEXClass control = new GridExWrapper(win32handle);
Assert.AreEqual(expectedItemCount, control.ItemCount);
}
}
You could try the Microsoft UI Automation library (System.Windows.Automation) for identifying the properties of the control. Sometimes even if Ranorex fails, MSUIA manages to recognize the control as it looks into native properties of a control for identification. Not guaranteed but worth a try.Here is a link to a tutorial on using MSUIA.

MS Visio - Create/Insert a new Page/Tab in C#

I have searched nearly everywhere, but cannot find a way of creating/inserting a new Page/Tab in C# within a Visio document. I recorded a VB Macro of creating a new page within a document, and it is really simple there. However, I am using C# and cannot find the right commnands. Thanks in advance!
Writing in C# you will use the same COM API which VBA uses. A simple way to automate Visio using C# is to download and install the Primary Interop Assembly (PIA). Then include the reference Microsoft.Office.Interop.Visio in your project. Here is a simple example of using the PIA to manipulate the pages in a Visio document.
namespace VisioExample
{
using System;
using Microsoft.Office.Interop.Visio;
class Program
{
public static void Main(string[] args)
{
// Start Visio
Application app = new Application();
// Create a new document.
Document doc = app.Documents.Add("");
// The new document will have one page,
// get the a reference to it.
Page page1 = doc.Pages[1];
// Add a second page.
Page page2 = doc.Pages.Add();
// Name the pages. This is what is shown in the page tabs.
page1.Name = "Abc";
page2.Name = "Def";
// Move the second page to the first position in the list of pages.
page2.Index = 1;
}
}
}
To learn about developing solutions you can look at the Developing Visio Solutions book online. Download the Visio SDK, it contains a library of sample code in C#. You could look at "Visio 2003 Developer's Survival Pack" by Graham Wideman. As you found, the macro recorder can show you the API methods you need to call to achieve a task. The COM API used by VBA are the same API you will use in C#, the syntax of the code will differ obviously.

Loading a script from a cs file and accessing host methods, properties etc?

I'm just having a play with Roslyn but unsure on how to do the following.
To keep this simple, lets say I have a host program which has a method like so
public void DisplayMessage(string message)
{
MessageBox.Show(message);
}
Can I then have a script file called MyScript.csx and then somewhere in the script have something like
void Main()
{
Host.DisplayMessage("I am a script");
}
Then I have the host load the file and execute it.
If this sort of thing can't be done, is there a scripting system/engine based on c# that can do it?
These are the requirements
Host application can load script from a file.
Script file is written in c# and so can be written using VS2010 with syntax etc
Script file can access host public methods, properties etc
I wrote an Introduction to the Roslyn scripting API that covers most of what you're asking. The ScriptEngine type also has a ExecuteFile method that would be useful for what you're trying to do.
Disclaimer: I work for Microsoft on the Roslyn project.
Yes, you can do what you want using Roslyn.
First, create a public Host class that has a public DisplayMessage method (or use a existing class). Then create ScriptEngine, specifying the assembly that contains Host as a reference. After that, you can call ExecuteFile() on your file, with the Host object as another parameter:
var engine = new ScriptEngine(references: new[] { typeof(Host).Assembly });
engine.ExecuteFile("MyScript.csx", new Host());
The script files doesn't need any Main() method, and you call the method on the host object directly:
DisplayMessage("I am a script");

capturing a click event on Google Earth plugin

Using the Google Earth Plugin in C#, I want to get clicked position on the earth; how can I do this?
using GEPlugin;
m_ge = (IGEPlugin)pluginInstance;
KmlLookAtCoClass lookAt = m_ge.createLookAt("");
lookAt.set(35.337919, 33.321576, 0, m_ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 0, 5000);
m_ge.getView().setAbstractView(lookAt);
m_ge.getLayerRoot().enableLayerById(m_ge.LAYER_ROADS, 1);
Now I want to add Click Event listener that I want to get click event.
How can this be done?
EDIT
The GEWebBrowser inherits from the
standard
System.Windows.Forms.WebBrowser
control class and has the same base
members, methods, properties and
events.
Because of this, you'll need to manually create bi-directional communication between this control and your C# class.
See this article for how to wire up C# to javascript events in a browser control. http://support.microsoft.com/kb/312777
Also, you may find the following C# method useful for adding javascript events to the GEWebBrowser.
Void AddEventListener(object, string,
string)
Wrapper for the the google.earth.addEventListener method
Parameters
object: The target plug-in Api object
string: The event Id
string: The name of javascript callback function to use
example: GEWebBrowser.AddEventListener(object,"click","function(event){alert(event.getType());}");
src: http://code.google.com/p/winforms-geplugin-control-library/wiki/GEWebBrowser
Not entirely sure, but perhaps one of these links will help you out.
http://fraserchapman.blogspot.com/2008/08/google-earth-plug-in-and-c.html
http://groups.google.com/group/google-earth-browser-plugin/browse_thread/thread/90dfb80960094828?pli=1
http://interactiveearth.blogspot.com/2008/01/create-your-own-google-earth.html
http://www.xtremevbtalk.com/showthread.php?t=287038
The problem is that the standard event handlers are part of the google.earth namespace and are not directly accessible via managed code. You need to 'relay' the events to your application via javascript and a COM visible class.
I have developed a free control library that allows you to easily embed the google earth plugin into an application.
It supports the AddEventListner and RemoveEventListner functions that you are looking for
http://code.google.com/p/winforms-geplugin-control-library/wiki/AddEventListener
It is worth noting that it does not use, as in your example, the GEPlugin Type Library - rather the dynamic type in C#4.0. This means that it is not 'version dependent' on a particular version of the Google Earth Plugin
The main project is here
http://code.google.com/p/winforms-geplugin-control-library/

Categories

Resources