In Class Step1, I configured the ChromeDriver
And Navigate URL
Picture for clarification with the code Step1 Class
Then I created another class [step3 ] to get the page title
Picture for clarification with the code Step3 Class
I created an inheritance between them, but there is a problem
I don't know well what the problem is, I have attached a picture of the problem
If I request the title From Step3 Class gets a new instance And it opens a new page
Please help.. I searched for other sources and didn't get anything
Thank you all
Result
Step1 Class code
Imports System.IO
Imports System.Net
Imports OpenQA.Selenium.Chrome
Public Class Step1
Public driver As ChromeDriver
Public Shared options As ChromeOptions
Public Shared service As ChromeDriverService
Public Sub New()
options = New ChromeOptions
options.AddArgument("--lang=en-us")
options.AddArgument("--window-size=400,700")
options.AddAdditionalChromeOption("useAutomationExtension", False)
options.AddUserProfilePreference("credentials_enable_service", False)
service = ChromeDriverService.CreateDefaultService
service.HideCommandPromptWindow = True
driver = New ChromeDriver(service, options)
End Sub
Public Sub StartNavigate()
driver.Navigate().GoToUrl("https://www.google.com/")
End Sub
End Class
Step3 Class code
Public Class step3
Inherits Step1
Public Sub GetTitle()
Try
MsgBox(driver.Title)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
When you start a new instance of Step3 you also create a new Selenium-Driver and therefor a new browser-window.
If you only want one browser you have to make the driver shared
Public Shared driver As ChromeDriver
and then in Sub new:
Public Sub New()
If driver isnot nothing then return
options = New ChromeOptions
options.AddArgument("--lang=en-us")
options.AddArgument("--window-size=400,700")
options.AddAdditionalChromeOption("useAutomationExtension", False)
options.AddUserProfilePreference("credentials_enable_service", False)
service = ChromeDriverService.CreateDefaultService
service.HideCommandPromptWindow = True
driver = New ChromeDriver(service, options)
End Sub
All together:
Imports System.IO
Imports System.Net
Imports OpenQA.Selenium.Chrome
Public Class Step1
Public Shared driver As ChromeDriver
Public Shared options As ChromeOptions
Public Shared service As ChromeDriverService
Public Sub New()
If driver isnot nothing then return
options = New ChromeOptions
options.AddArgument("--lang=en-us")
options.AddArgument("--window-size=400,700")
options.AddAdditionalChromeOption("useAutomationExtension", False)
options.AddUserProfilePreference("credentials_enable_service", False)
service = ChromeDriverService.CreateDefaultService
service.HideCommandPromptWindow = True
driver = New ChromeDriver(service, options)
End Sub
Public Sub StartNavigate()
driver.Navigate().GoToUrl("https://www.google.com/")
End Sub
End Class
Related
what wrong of code that make this error pleze
error ;click is not member of openqa.selenium
Imports System.Text
Imports OpenQA.Selenium
Imports OpenQA.Selenium.Chrome
Module Module1
Sub Main()
Dim driver As IWebDriver
driver = New ChromeDriver
driver.Navigate().GoToUrl("https://m.facebook.com/")
Dim element As IWebDriver = driver.FindElement(By.Id("u_0_b"))
System.Threading.Thread.Sleep(10000)
element.Click()
End Sub
End Module
The type IWebDriver does not have a click method. Change the type for the element variable in the declaration to IWebElement:
Dim element As IWebElement = driver.FindElement(By.Id("u_0_b"))
I am new to .Net (any help will be greatly appreciated) and I am trying to implement this class to write to a rest api. All it does is pass in some data and does a postAsJsonAsync to the service.
It was written in C# and converted to VB.net to be added into a VB.net application solution.
It works once and then fails on the second call to it, when it initialises another instance of Uri.
Exception thrown: 'System.InvalidOperationException' in System.Net.Http.dllequest."}{"This instance has already started one or more requests. Properties can only be modified before sending the first request."}
Code here:
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Net.Http
Imports System.Net.Http.Headers
Namespace Logging
Public Class LogMessage
Public Property Application As String
Public Property Area As String
Public Property Activity As String
Public Property Description As String
Public Property User As String
End Class
Public Class ActionLogging
Public Shared Client As New HttpClient()
Public Shared Function AddToActionLog(Activity As String, Description As String, User As String)
Dim message = New LogMessage() With { _
.Activity = Activity, _
.Description = Description, _
.User = User, _
.Application = ConfigurationManager.AppSettings("Application"), _
.Area = ConfigurationManager.AppSettings("Area") _
}
If Run(message) IsNot Nothing
Run(message).Wait()
End If
End Function
Public Shared Function CreateMessage(message As LogMessage) As Uri
Dim task = Client.PostAsJsonAsync("Action", message)
task.Wait()
Dim response As HttpResponseMessage = task.Result
response.EnsureSuccessStatusCode()
Return response.Headers.Location
End Function
Public Shared Function Run(message As LogMessage) As Task
Client.BaseAddress = new Uri(ConfigurationManager.AppSettings("RestAPIServer"))
Client.DefaultRequestHeaders.Accept.Clear()
Client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))
CreateMessage(message)
End Function
End Class
End Namespace
Imports System.Configuration
Imports System.Threading.Tasks
Imports System.Net.Http
Imports System.Net.Http.Headers
Namespace Logging
Public Class LogMessage
Public Property Application As String
Public Property Area As String
Public Property Activity As String
Public Property Description As String
Public Property User As String
End Class
Public Class ActionLogging
Private ReadOnly Shared Client As New HttpClient() With {.BaseAddress = new Uri(ConfigurationManager.AppSettings("RestAPIServer"))}
public Sub New()
Client.DefaultRequestHeaders.Accept.Clear()
Client.DefaultRequestHeaders.Accept.Add(New MediaTypeWithQualityHeaderValue("application/json"))
End Sub
Public Shared Function AddToActionLog(activity As String, description As String, user As String)
Dim message = New LogMessage() With { _
.Activity = Activity, _
.Description = Description, _
.User = User, _
.Application = ConfigurationManager.AppSettings("Application"), _
.Area = ConfigurationManager.AppSettings("Area") _
}
SendMessage(message)
End Function
Private Shared Sub SendMessage(message As LogMessage)
Dim task = Client.PostAsJsonAsync("Action", message)
task.Wait()
Dim response As HttpResponseMessage = task.Result
response.EnsureSuccessStatusCode()
End Sub
End Class
End Namespace
I need to do some testing with SignalR so I have two console applications - first serving as SignalR hub (server) and second SignalR client. I need to transfer lists of custom objects, not some primitive data like strings or integers. I dont want to use WCF because of its complexity.
Hub:
Imports Microsoft.AspNet.SignalR
Imports Microsoft.AspNet.SignalR.Hubs
Imports DataContract
<HubName("Repository")>
Public Class RepositoryHub
Inherits Hub
Public Function SelectTasks() As IList(Of Task)
Dim tasks As New List(Of Task)
tasks.Add(New Task With {.Id = 1, .Code = "A", .Assignment = "Assignment A"})
tasks.Add(New Task With {.Id = 2, .Code = "B", .Assignment = "Assignment B"})
tasks.Add(New Task With {.Id = 3, .Code = "C", .Assignment = "Assignment C"})
Return tasks
End Function
Public Overrides Function OnConnected() As Threading.Tasks.Task
Console.WriteLine(Context.ConnectionId)
Return MyBase.OnConnected()
End Function
End Class
Public Class Task
Public Property Id As Integer
Public Property Code As String
Public Property Assignment As String
End Class
Server:
Imports Microsoft.Owin.Hosting
Module ServerModule
Sub Main()
Using WebApp.Start(Of OwinConfiguration)("http://localhost:8080")
Console.ReadLine()
End Using
End Sub
End Module
Public Class OwinConfiguration
Public Sub Configuration(app As IAppBuilder)
app.UseCors(CorsOptions.AllowAll)
app.MapSignalR()
End Sub
End Class
Client:
Imports Microsoft.AspNet.SignalR.Client
Imports DataContract
Module ClientModule
Sub Main()
Dim repositoryHub As IHubProxy
Dim connection As New HubConnection("http://localhost:8080")
repositoryHub = connection.CreateHubProxy("Repository")
repositoryHub.On(Of IList(Of Task))("SelectTasks", Sub(t)
Console.WriteLine(t.Count)
End Sub)
connection.Start().Wait()
repositoryHub.Invoke(Of IList(Of Task))("SelectTasks").Wait()
Console.ReadLine()
End Sub
End Module
Breakpoint is always reached in SelectTasks method, but never in anonymous Sub(t) method in client, where is processing of data received from server.
It was misunderstanding in SignalR usage. Client should be like this:
Imports Microsoft.AspNet.SignalR.Client
Imports DataContract
Module ClientModule
Sub Main()
Dim repositoryHub As IHubProxy
Dim connection As New HubConnection("http://localhost:8080")
repositoryHub = connection.CreateHubProxy("Repository")
connection.Start().Wait()
Dim tasks = repositoryHub.Invoke(Of IList(Of Task))("SelectTasks")
tasks.Wait()
Console.WriteLine(tasks.Result.Count)
Console.ReadLine()
End Sub
End Module
well hello everybody
i have one project with multiples web services so i created various singleton class thinking in performance. now i think create one singleton class and that have the instances of my webservices
example
public static WebServiceMaster
{
internal ServiceX WebX;
internal ServiceY WebY;
......
public static WEbServiceMaster GetInstance()
.....
}
what think about that?
is that bad?
Well, finally that is done. I know that is not perfect
Public NotInheritable Class ServiceProxySingleton
Private _services As IDictionary(Of ProxyServicesEnum, IServiceDispatcher) = New Dictionary(Of ProxyServicesEnum, IServiceDispatcher)
Private _dbRepository As IDACommon
Private Sub New()
_dbRepository = New DACommon()
LoadServices()
End Sub
Private Sub LoadServices()
_services.Add(ProxyServicesEnum.eActivity, New ActivityServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eAvailability, New AvailabilityServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eBrochure, New BrochureServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eInformation, New InformationServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eMeetingRoom, New MeetingRoomServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eMembership, New MembershipServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eName, New NameServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eReservation, New ReservationServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eResvAdvanced, New ResvAdvancedServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eSecurity, New SecurityServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.eStayHistory, New StayHistoryServiceImp(_dbRepository))
_services.Add(ProxyServicesEnum.ePostXml, New PostXmlServiceImp(_dbRepository, ConfigurationServiceSingleton.GetInstance.GetPostXmlConfig))
_services.Add(ProxyServicesEnum.eOxiHttp, New OxiServiceImp(_dbRepository))
End Sub
Public ReadOnly Property Service(ByVal serviceEnum As ProxyServicesEnum) As Object
Get
If _services.ContainsKey(serviceEnum) Then
Return _services.Item(serviceEnum)
End If
Return Nothing
End Get
End Property
Public ReadOnly Property GetMeta(ByVal serviceEnum As ProxyServicesEnum) As IDictionary(Of String, MethodIdentityAttribute)
Get
If _services.ContainsKey(serviceEnum) Then
Return _services.Item(serviceEnum).MetaInfo
End If
Return Nothing
End Get
End Property
Public Shared Function GetInstance() As ServiceProxySingleton
Return NestedPrWireService._instance
End Function
Class NestedPrWireService
Friend Shared ReadOnly _instance As ServiceProxySingleton = New ServiceProxySingleton()
Shared Sub New()
End Sub
End Class
End Class
comments and criticisms are welcome
Very good approach is to use Dependency Injection. For example Unity.
I am trying to test that a property has been set but when I write this as a unit test:
moqFeed.VerifySet(Function(m) m.RowAdded = "Row Added")
moq complains that "Expression is not a property setter invocation"
My complete code is
Imports Gallio.Framework
Imports MbUnit.Framework
Imports Moq
<TestFixture()> Public Class GUI_FeedPresenter_Test
Private moqFeed As Moq.Mock(Of IFeedView)
<SetUp()> Sub Setup()
moqFeed = New Mock(Of IFeedView)
End Sub
<Test()> Public Sub New_Presenter()
Dim pres = New FeedPresenter(moqFeed.Object)
moqFeed.VerifySet(Function(m) m.RowAdded = "Row Added")
End Sub
End Class
Public Interface IFeedView
Property RowAdded() As String
End Interface
Public Class FeedPresenter
Private _FeedView As IFeedView
Public Sub New(ByVal feedView As IFeedView)
_FeedView = feedView
_FeedView.RowAdded = "Row Added"
End Sub
End Class
I can't find any examples of moq in VB, I would be grateful for any examples.
See my question Using Moq's VerifySet in VB.NET for the solution to this.