B4J Library [b4j] jSelenium - A Test Automation for B4J

This is my very first attempt to create a wrap for a library, It is based on this project:
- https://www.selenium.dev/downloads/
jSelenium - version 1.0

Usage​

* Third party Jar:

AdditionalJar:
#AdditionalJar: client-combined-3.14.0.jar
#AdditionalJar: animal-sniffer-annotations-1.14.jar
#AdditionalJar: byte-buddy-1.8.15.jar
#AdditionalJar: checker-compat-qual-2.0.0.jar
#AdditionalJar: commons-codec-1.10.jar
#AdditionalJar: commons-exec-1.3.jar
#AdditionalJar: commons-logging-1.2.jar
#AdditionalJar: error_prone_annotations-2.1.3.jar
#AdditionalJar: guava-31.1-jre.jar
#AdditionalJar: httpclient-4.5.5.jar
#AdditionalJar: httpcore-4.4.9.jar
#AdditionalJar: j2objc-annotations-1.1.jar
#AdditionalJar: okhttp-3.10.0.jar
#AdditionalJar: jsr305-1.3.9.jar
#AdditionalJar: selenium-api-4.3.0.jar 
#AdditionalJar: selenium-chromium-driver-4.3.0.jar 
#AdditionalJar: selenium-java-3.14.0.jar 
#AdditionalJar: selenium-support-4.3.0.jar 
#AdditionalJar: selenium-remote-driver-4.3.0.jar
#AdditionalJar: okio-1.14.1.jar
#AdditionalJar: opentelemetry-sdk-1.16.0.jar
#AdditionalJar: opentelemetry-sdk-extension-autoconfigure-spi-1.16.0.jar

Using:
ClassName
id
CssSelector
Xpath
LinkText
Name
Partiallinktext
Tagname         

Example:
jChrome.SelecElement("//a[contains(text(),'B4J - Desktop, Server and Raspberry Pi')]", "xpath")

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    jChrome.Initialize("jChrome", "D:\B4J\b4jSelenium\jSelenium\Driver", "chromedriver104.exe")
    jChrome.Create
End Sub

Sub Button1_Click   
    'jChrome.HideAutomation(True)
    jChrome.loadURL("https://www.showmyip.com/")
    Sleep(1000)
    jChrome.ReadCookies(File.DirApp, "fb.cookies")
    Sleep(500)
    jChrome.Refresh
End Sub

EVENTS

Events:
Sub jChrome_PageFinished (error As String, success As Boolean)
    Log("PageFinished:" & success)
End Sub
Sub jChrome_AfterClickOn ()
    Log("AfterClickOn")
End Sub
Sub jChrome_BeforeClickOn()
    Log("BeforeClickOn")
End Sub

Sub jChrome_BeforeAlertAccept()
    Log("BeforeAlertAccept")
End Sub
    
Sub jChrome_AfterAlertAccept()
    Log("AfterAlertAccept")
End Sub

Sub jChrome_BeforeAlertDismiss()
    Log("BeforeAlertDismiss")
End Sub
Sub jChrome_AfterAlertDismiss()
    Log("AfterAlertDismiss")
End Sub
    
Sub jChrome_AfterNavigateTo(url As String)
    Log(url)
End Sub
Sub jChrome_BeforeNavigateTo(url As String)
    Log(url)
End Sub
Sub jChrome_AfterNavigateBack(url As String)
    Log(url)
End Sub
Sub jChrome_BeforeNavigateBack(url As String)
    Log(url)
End Sub
Sub jChrome_BeforeNavigateForward(url As String)
    Log(url)
End Sub
Sub jChrome_AfterNavigateForward(url As String)
    Log(url)
End Sub
Sub jChrome_AfterNavigateRefresh(url As String)
    Log(url)
End Sub
Sub jChrome_BeforeNavigateRefresh(url As String)
    Log(url)
End Sub
Sub jChrome_AfterFindBy()
    Log("AfterFindBy")
End Sub
Sub jChrome_BeforeFindBy()
    Log("BeforeFindBy")
End Sub

Sub jChrome_AfterChangeValueOf(keysToSend As String)
    Log("AfterChangeValueOf")
End Sub

Sub jChrome_BeforeChangeValueOf(keysToSend As String)
    Log("BeforeChangeValueOf")
End Sub
Sub jChrome_BeforeScript(script As String)
    Log("BeforeScript")
End Sub

Sub jChrome_AfterScript(script As String)
    Log("AfterScript")
End Sub

Sub jChrome_BeforeSwitchToWindow(windowName As String)
    Log(windowName)
End Sub

Sub jChrome_AfterSwitchToWindow(windowName As String)
    Log(windowName)
End Sub

Sub jChrome_OnException(throwable As String)
    Log(throwable)
End Sub

Sub jChrome_BeforeGetScreenshotAs()
    Log("BeforeGetScreenshotAs")
End Sub

Sub jChrome_AfterGetScreenshotAs()
    Log("AfterGetScreenshotAs")
End Sub

Sub jChrome_BeforeGetText(value As String)
    Log("BeforeGetText")
End Sub

Sub jChrome_AfterGetText(value As String)
    Log("AfterGetText")
End Sub

Download:
Buy me a coffee if you are happy with this library

Paypal: tantruongcc@yahoo.com.vn
 

mcqueccu

Well-Known Member
Licensed User
Thank you for the library. The 3rd party jars you added and the ones you specify in the example projects are of different version.

Edit: Seen the jar files now.

New issue: If the installed chrome driver is different from the chrome driver 104, it crashes. Is that the expected behaviour?

B4X:
Waiting for debugger to connect...
Program started.
Aug 07, 2022 7:50:25 PM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
Starting ChromeDriver 104.0.5112.29 (eff877e18f767c77fef0481a1cba402c8cbad404-refs/branch-heads/5112@{#422}) on port 19893
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1659901841.241][WARNING]: Deprecated chrome option is ignored: useAutomationExtension
[1659901841.241][WARNING]: Deprecated chrome option is ignored: useAutomationExtension
Error occurred on line: 49 (Main)
org.openqa.selenium.SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 104
Current browser version is 103.0.5060.134 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:05:20.749Z'
Driver info: driver.version: ChromeDriver
remote stacktrace: Backtrace:
    Ordinal0 [0x01138823+2197539]
    Ordinal0 [0x010D0911+1771793]
    Ordinal0 [0x00FE3FE8+802792]
    Ordinal0 [0x01005B43+940867]
  ....
.
.

    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)
 
Last edited:

tummosoft

Member
Licensed User
Longtime User
Thank you for the library. The 3rd party jars you added and the ones you specify in the example projects are of different version.

Edit: Seen the jar files now.

New issue: If the installed chrome driver is different from the chrome driver 104, it crashes. Is that the expected behaviour?

B4X:
Waiting for debugger to connect...
Program started.
Aug 07, 2022 7:50:25 PM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
Starting ChromeDriver 104.0.5112.29 (eff877e18f767c77fef0481a1cba402c8cbad404-refs/branch-heads/5112@{#422}) on port 19893
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1659901841.241][WARNING]: Deprecated chrome option is ignored: useAutomationExtension
[1659901841.241][WARNING]: Deprecated chrome option is ignored: useAutomationExtension
Error occurred on line: 49 (Main)
org.openqa.selenium.SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 104
Current browser version is 103.0.5060.134 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:05:20.749Z'
Driver info: driver.version: ChromeDriver
remote stacktrace: Backtrace:
    Ordinal0 [0x01138823+2197539]
    Ordinal0 [0x010D0911+1771793]
    Ordinal0 [0x00FE3FE8+802792]
    Ordinal0 [0x01005B43+940867]
  ....
.
.

    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)

Each version of ChromeDriver supports Chrome with matching major, minor, and build version numbers.

You can download other version and try:
https://chromedriver.chromium.org/downloads
 

miguelcleman

Member
Licensed User
Longtime User
Thank you for the library, but I get this error when try put text in a page :

java.lang.Exception: Sub jchrome_beforeclickon signature does not match expected signature

The examples show how put text but don't work.

Any help?
 

miguelcleman

Member
Licensed User
Longtime User
Hi, I cant run exe file created from build standalone package option B4J (never show browser like in IDE with source from post #1)

The jar file, in objects folder, too cant run.

Thank for Help!
 
Top