Search
 
 

Display results as :
 


Rechercher Advanced Search

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Can't Pass IWebDriver to other functions?

View previous topic View next topic Go down

Can't Pass IWebDriver to other functions?

Post by NaviQA on Mon Jul 16, 2012 8:42 pm

I created a static class where I have a login/logout function that is used for all of my selenium tests that are called by a main class. When I pass the driver from the main class to the test that I'm running, then to the login method everything is ok. I then pass the same driver from the test class to the log out method and it says the connection was refused.

I am very confused and am wondering if anyone can shed some light on this?

thanks,

NaviQA

Posts : 6
Join date : 2012-07-16

Back to top Go down

Re: Can't Pass IWebDriver to other functions?

Post by popsha on Tue Jul 17, 2012 9:15 am

Since I am unclear about the context. Let me explain in two ways.
1.Within the same class
Construct a method after the @Test annotation so that, the method can be called inside @Test annotation whenever required. It should be like this

@Before
public void setUp() throws Exception
{
//......Coding
}
@Test
public void testName() throws Exception
{
//......Coding
methodForLogin(pass the value here);
//........Coding
}
public void methodForLogin(String get the value here) throws Exception
{
//your code for login and logout
}
@After
{
//.........

}

2. From another class

In this case, hard code your method in main class and extend it in your required class


Hope this would help you.

popsha
Amateur
Amateur

Posts : 60
Join date : 2012-04-14

Back to top Go down

Re: Can't Pass IWebDriver to other functions?

Post by NaviQA on Tue Jul 17, 2012 7:59 pm

#2 is what I am trying to do, first I wanted to have class 1 call all the test classes, then the test class call the login/out class (more like a module).

If I put the driver as a class level variable in this C# console app, it cant see it in the Main, or in the other methods that I have in the first class.

EDIT: I tried making the driver variable public at the class level, that didn't seem to work, making it static did make it visible to all methods in the main class. However I still get the same error:
Page title is: Time Warner Cable Business Class - Cloud Services - Home

Code:
OpenQA.Selenium.WebDriverException: Unexpected error.
System.Net.WebException: Unable to connect to the remote server ---> System.Net.
Sockets.SocketException: No connection could be made because the target machine
actively refused it 127.0.0.1:7055
  at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre
ss socketAddress)
  at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Sock
et s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state,
IAsyncResult asyncResult, Int32 timeout, Exception& exception)
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
  at System.Net.HttpWebRequest.GetRequestStream()
  at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecut
e) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\HttpCommandExecuto
r.cs:line 91
  at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Execute(Command comma
ndToExecute) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Firefox\Interna
l\ExtensionConnection.cs:line 128
  at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecu
te, Dictionary`2 parameters) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver
\Remote\RemoteWebDriver.cs:line 799
  at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response erro
rResponse) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebD
river.cs:line 1002
  at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecu
te, Dictionary`2 parameters) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver
\Remote\RemoteWebDriver.cs:line 809
  at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, Strin
g value) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDri
ver.cs:line 840
  at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id) in c:\Pr
ojects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 435
  at OpenQA.Selenium.By.<>c__DisplayClass2.<Id>b__0(ISearchContext context) in
c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\By.cs:line 102
  at OpenQA.Selenium.By.FindElement(ISearchContext context) in c:\Projects\WebD
river\trunk\dotnet\src\WebDriver\By.cs:line 306
  at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by) in c:\Projects\W
ebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line 293
  at TWC_Smoke_Tests.Smoke_Test_Driver.LogOut_Staging() in D:\Users\ahouck\Desk
top\Test Scripts\C# Smoke Test\TWC-Smoke Tests\TWC-Smoke Tests\Smoke_Test_Driver
.cs:line 82

NaviQA

Posts : 6
Join date : 2012-07-16

Back to top Go down

Re: Can't Pass IWebDriver to other functions?

Post by popsha on Thu Jul 19, 2012 11:05 am

I could not figure out what goes wrong.
If possible share your code so that, let me check and revert.

Make sure you extend your main class in your required class.

popsha
Amateur
Amateur

Posts : 60
Join date : 2012-04-14

Back to top Go down

Re: Can't Pass IWebDriver to other functions?

Post by NaviQA on Thu Jul 19, 2012 7:38 pm

I figured it out a bit. I just have whatever methods/classes I'm using the webdriver in to always return the webdriver that way it just keeps getting passed along. Though I just opted for a easier (although probably not the best practice) of just coding each test in one class, and having just one method go straight through and coded everything straight out in that instead of breaking it up into different functions.

NaviQA

Posts : 6
Join date : 2012-07-16

Back to top Go down

Re: Can't Pass IWebDriver to other functions?

Post by Sponsored content Today at 7:26 am


Sponsored content


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