Calling C# selenium methods between classes
Page 1 of 1 • Share •
Calling C# selenium methods between classes
I have two classes.
1) Environment.cs - where I set up all sorts of general methods.
2) AboutPage.cs - actual test case.
I have AboutPage.cs pull methods from Environment.cs In this case it is page loading time. When I try to build it, it gives me an error: : An object reference is required for the non-static field, method, or property Environment.cs
I am new to C#. Does anyone know how to solve this problem? I am attaching source code for both methods below.
Thanks!
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
namespace OldVersion
{
[TestFixture]
public class Environment
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[Test]
public static void MeWaitForPageToLoad()
{
selenium.WaitForPageToLoad("30000");
}
}
}
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
namespace OldVersion
{
[TestFixture]
public class AboutPage
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://*******.com/");
selenium.Start();
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void FunctionsAboutPage()
{
selenium.Open("/en/default.aspx");
Environment.MeWaitForPageToLoad();
selenium.Click("ctl00_TopMenu1_About");
Environment.MeWaitForPageToLoad();
Assert.IsTrue(selenium.IsTextPresent("Software Development"));
Assert.IsTrue(selenium.IsTextPresent("Alliances"));
Assert.IsTrue(selenium.IsElementPresent("//img[@alt='Climate Savers']"));
Assert.IsTrue(selenium.IsElementPresent("//img[@alt='Novell']"));
Assert.IsTrue(selenium.IsElementPresent("//img[@alt='LANDesk']"));
Assert.IsTrue(selenium.IsElementPresent("//img[@alt='Microsoft']"));
Assert.IsFalse(selenium.IsTextPresent("asdfwc"));
}
}
}
1) Environment.cs - where I set up all sorts of general methods.
2) AboutPage.cs - actual test case.
I have AboutPage.cs pull methods from Environment.cs In this case it is page loading time. When I try to build it, it gives me an error: : An object reference is required for the non-static field, method, or property Environment.cs
I am new to C#. Does anyone know how to solve this problem? I am attaching source code for both methods below.
Thanks!
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
namespace OldVersion
{
[TestFixture]
public class Environment
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[Test]
public static void MeWaitForPageToLoad()
{
selenium.WaitForPageToLoad("30000");
}
}
}
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
namespace OldVersion
{
[TestFixture]
public class AboutPage
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://*******.com/");
selenium.Start();
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void FunctionsAboutPage()
{
selenium.Open("/en/default.aspx");
Environment.MeWaitForPageToLoad();
selenium.Click("ctl00_TopMenu1_About");
Environment.MeWaitForPageToLoad();
Assert.IsTrue(selenium.IsTextPresent("Software Development"));
Assert.IsTrue(selenium.IsTextPresent("Alliances"));
Assert.IsTrue(selenium.IsElementPresent("//img[@alt='Climate Savers']"));
Assert.IsTrue(selenium.IsElementPresent("//img[@alt='Novell']"));
Assert.IsTrue(selenium.IsElementPresent("//img[@alt='LANDesk']"));
Assert.IsTrue(selenium.IsElementPresent("//img[@alt='Microsoft']"));
Assert.IsFalse(selenium.IsTextPresent("asdfwc"));
}
}
}
mhroy- Posts: 3
Join date: 2010-08-27
Re: Calling C# selenium methods between classes
roy,
since it is public you are getting that problem. Use static class to make use of methods without creating objects from other classes.
use "public static class Environment" instead public class Environment
cheers
since it is public you are getting that problem. Use static class to make use of methods without creating objects from other classes.
use "public static class Environment" instead public class Environment
cheers
snookala- Posts: 4
Join date: 2010-09-03
Similar topics» Fitness classes in and around Cumbernauld
» Calling C# selenium methods between classes
» Calling application's js file inside selenium RC
» Selenium Coaching classes.
» Online Selenium Coaching Classes by QTPSELENIUM.COM
» Calling C# selenium methods between classes
» Calling application's js file inside selenium RC
» Selenium Coaching classes.
» Online Selenium Coaching Classes by QTPSELENIUM.COM
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
» sample webdriver code for php users
» which standalone server to use
» Dynamic Drop Down Selection
» It is possible to find list of all URL's exist in any web page in selenium ide
» It is possible to compare 2 same images in selenium IDE.
» how to compare 2 ULR's which is exist in same web page (View page source).
» Web Driver: Unable to click a link present inside the frame of a frameset
» Help me to get dynamicaly loaded options of dropdown in Selenium RC -Junit test case