1

Hi I am using Selenium for the first time and I was doing the following code. It runs fine but after opening firefox it wont output to console as the code says it should it will do all of it after all the steps in the code are complete.

So my question is how do I make that text output to console while its actually running the step?

        var ProxyIP = "xxx.xxx.xx.xxx:80";

        RtbConsole.AppendText("Setting Up Firefox\n");

        //Firefox driver + proxy setup
        FirefoxProfile profile = new FirefoxProfile();
        String PROXY = ProxyIP;
        OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
        proxy.HttpProxy = PROXY;
        proxy.FtpProxy = PROXY;
        proxy.SslProxy = PROXY;
        profile.SetProxyPreferences(proxy);

        RtbConsole.AppendText("Launching Firefox\n");
        FirefoxDriver driver = new FirefoxDriver(profile);

        RtbConsole.AppendText("Navigating to http://whatsmyip.net/ \n");
        driver.Navigate().GoToUrl("http://whatsmyip.net/");


        IWebElement ip = driver.FindElement(By.XPath("/html/body/div/div/h1/span"));
        var myIP = ip.Text;

        RtbConsole.AppendText("Checking IP for Proxy\n");
        if (ProxyIP == myIP + ":80") {
            RtbConsole.AppendText("Proxy Test: Success\n");
        } else {
            RtbConsole.AppendText("Proxy Test: Failed\n");
        }

        //Close the browser
        driver.Quit();
Someone
  • 894
  • 3
  • 22
  • 43
  • Just if anyone was interested in the answer to this, its really not possible doing it like I was trying to I ended up running the driver parts in a separate thread and then using a delegate function to apply console updates. – Someone Oct 29 '14 at 15:31

1 Answers1

0

I'm new to this site, so i apologize if this is not helpful. However, when i am writing selenium(webdriver) tests in C#, i generally do not use the append command. Try approaching the console differently, such as

Console.WriteLine("Text you wish to be outputted to the Console"); 
//OR MAYBE 
Console.Write("Text you wish to be outputted to the Console"); 

In addition, i am not sure that simultaneously executing two commands is actually possible, however, you can make the output contingent upon other chosen code executing, using if statements, or maybe try catch etc.

Hope that this helps! Cheers!

newITguy
  • 155
  • 1
  • 11
  • I was waiting for an answer for a while I will give it a try. thanks – Someone Sep 06 '12 at 15:33
  • 1
    Nah it didn't really work I think I need to find a way to run it in a separate thread or something and monitor the thread. – Someone Sep 11 '12 at 18:01