Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» Geting issues in identifying the elsements in webdriver
Fri Feb 17, 2017 4:41 pm by janbaskt

» WebDriver - why not to use a singlton for it?
Fri Feb 17, 2017 4:40 pm by janbaskt

» WebDriver session when using testng annotation to invoke driver instance
Fri Feb 17, 2017 4:39 pm by janbaskt

» Selenium fails to launch Chrome
Fri Feb 17, 2017 4:39 pm by janbaskt

» why do i get this error
Fri Feb 17, 2017 4:38 pm by janbaskt

» Selenium Tutorial
Thu Feb 16, 2017 5:21 pm by Rahul

» When to use Selenium IDE, RC and WebDriver
Mon Feb 13, 2017 2:35 pm by azharuddin

» How to integrate selenium with ZAPI-Zephyr
Sat Feb 11, 2017 2:25 am by gseera002c

» Selenium Webdriver
Sat Feb 04, 2017 6:47 pm by soumyamishrav@gmail.com

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Calling C# selenium methods between classes

View previous topic View next topic Go down

Calling C# selenium methods between classes

Post by mhroy on Mon Aug 30, 2010 11:43 pm

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"));
}
}
}

mhroy

Posts : 3
Join date : 2010-08-27

Back to top Go down

Re: Calling C# selenium methods between classes

Post by snookala on Fri Sep 03, 2010 10:21 pm

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

snookala

Posts : 4
Join date : 2010-09-03

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum