Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit ded6cc6

Browse files
committed
Merge branch 'develop' of github.com:Hi-Fi/robotframework-seleniumlibrary-java into removeExtraDependencies
2 parents 006f979 + fed6f0e commit ded6cc6

File tree

11 files changed

+50
-28
lines changed

11 files changed

+50
-28
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88
- PROFILE=build
99
- PROFILE=build,googlechromeheadless
1010
- PROFILE=build,firefoxheadless
11+
- PROFILE=build,htmlunitwithjs
1112

1213
stages:
1314
- test

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ your pom.xml:
4545
<dependency>
4646
<groupId>com.github.hi-fi</groupId>
4747
<artifactId>robotframework-seleniumlibrary</artifactId>
48-
<version>3.141.59.265</version>
48+
<version>3.141.59.2653</version>
4949
<scope>test</scope>
5050
</dependency>
5151

5252
If you cannot use the robotframework-maven-plugin you can use the
53-
[jar-with-dependencies](http://central.maven.org/maven2/com/github/hi-fi/robotframework-seleniumlibrary/3.141.59.265/robotframework-seleniumlibrary-3.141.59.265-jar-with-dependencies.jar),
54-
which contains all required libraries. Running of tests with this can be done with command `java -jar robotframework-seleniumlibrary-3.141.59.265-jar-with-dependencies.jar <test location>`.
53+
[jar-with-dependencies](http://central.maven.org/maven2/com/github/hi-fi/robotframework-seleniumlibrary/3.141.59.2653/robotframework-seleniumlibrary-3.141.59.2653-jar-with-dependencies.jar),
54+
which contains all required libraries. Running of tests with this can be done with command `java -jar robotframework-seleniumlibrary-3.141.59.2653-jar-with-dependencies.jar <test location>`.
5555

5656
* More information about this library can be found in the
57-
[Keyword Documentation](http://central.maven.org/maven2/com/github/hi-fi/robotframework-seleniumlibrary/3.141.59.265/robotframework-seleniumlibrary-3.141.59.265.html).
57+
[Keyword Documentation](http://central.maven.org/maven2/com/github/hi-fi/robotframework-seleniumlibrary/3.141.59.2653/robotframework-seleniumlibrary-3.141.59.2653.html).
5858
* For keyword completion in RIDE you can download this
59-
[Library Specs](http://central.maven.org/maven2/com/github/hi-fi/robotframework-seleniumlibrary/3.141.59.265/robotframework-seleniumlibrary-3.141.59.265.xml)
59+
[Library Specs](http://central.maven.org/maven2/com/github/hi-fi/robotframework-seleniumlibrary/3.141.59.2653/robotframework-seleniumlibrary-3.141.59.2653.xml)
6060
and place it in your PYTHONPATH.
6161

6262
Usage, Selenium 4 (WIP)

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@
141141
<artifactId>jbrowserdriver</artifactId>
142142
<version>1.1.0-RC1</version>
143143
</dependency>
144+
<dependency>
145+
<groupId>org.seleniumhq.selenium</groupId>
146+
<artifactId>htmlunit-driver</artifactId>
147+
<version>2.35.1</version>
148+
</dependency>
144149
<dependency>
145150
<groupId>org.mockito</groupId>
146151
<artifactId>mockito-core</artifactId>
@@ -373,6 +378,13 @@
373378
</plugins>
374379
</build>
375380
</profile>
381+
<profile>
382+
<id>htmlunitwithjs</id>
383+
<properties>
384+
<browser>htmlunitwithjs</browser>
385+
<downloadWebDriver>False</downloadWebDriver>
386+
</properties>
387+
</profile>
376388
<profile>
377389
<id>firefox</id>
378390
<properties>

src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagement.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.openqa.selenium.firefox.FirefoxDriver;
4040
import org.openqa.selenium.firefox.FirefoxOptions;
4141
import org.openqa.selenium.firefox.FirefoxProfile;
42+
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
4243
import org.openqa.selenium.ie.InternetExplorerDriver;
4344
import org.openqa.selenium.ie.InternetExplorerOptions;
4445
import org.openqa.selenium.remote.Augmenter;
@@ -165,7 +166,9 @@ public void closeBrowser() {
165166
"| Safari | safari |\r\n" +
166167
"| Android | android |\r\n" +
167168
"| Iphone | iphone |\r\n" +
168-
"| JBrowser | jbrowser |\r\n" +
169+
"| JBrowser | jbrowser |\r\n" +
170+
"| HTMLUnit | htmlunit |\r\n" +
171+
"| HTMLUnit with Javascript | htmlunitwithjs |\r\n" +
169172
"\r\n" +
170173
"To be able to actually use one of these browsers, you need to have a matching Selenium browser driver available. See the [https://github.com/Hi-Fi/robotframework-seleniumlibrary-java#browser-drivers|project documentation] for more details.\r\n" +
171174
"\r\n" +
@@ -672,6 +675,12 @@ protected WebDriver createLocalWebDriver(String browserName, Capabilities desire
672675
} catch (Exception e) {
673676
throw new SeleniumLibraryFatalException("Creating " + browserName + " instance failed.", e);
674677
}
678+
case "htmlunit":
679+
return new HtmlUnitDriver(desiredCapabilities);
680+
case "htmlunitwithjs":
681+
HtmlUnitDriver driver = new HtmlUnitDriver(desiredCapabilities);
682+
driver.setJavascriptEnabled(true);
683+
return driver;
675684
default:
676685
throw new SeleniumLibraryFatalException(browserName + " is not a supported browser.");
677686
}
@@ -761,6 +770,11 @@ protected Capabilities createCapabilities(String browserName, String desiredCapa
761770
case "jbrowser":
762771
desiredCapabilities = new DesiredCapabilities("jbrowser", "1", Platform.ANY);
763772
break;
773+
case "htmlunit":
774+
case "htmlunitwithjs":
775+
desiredCapabilities = DesiredCapabilities.htmlUnit();
776+
((DesiredCapabilities) desiredCapabilities).setBrowserName("htmlunit");
777+
break;
764778
default:
765779
throw new SeleniumLibraryFatalException(browserName + " is not a supported browser.");
766780
}

src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
import org.openqa.selenium.WebDriver;
1414
import org.openqa.selenium.WebElement;
1515
import org.openqa.selenium.interactions.Actions;
16-
import org.robotframework.javalib.annotation.ArgumentNames;
17-
import org.robotframework.javalib.annotation.Autowired;
18-
import org.robotframework.javalib.annotation.RobotKeyword;
19-
import org.robotframework.javalib.annotation.RobotKeywords;
16+
import org.robotframework.javalib.annotation.*;
2017

2118
import com.github.markusbernhardt.seleniumlibrary.RunOnFailureKeywordsAdapter;
2219
import com.github.markusbernhardt.seleniumlibrary.SeleniumLibraryNonFatalException;
@@ -423,17 +420,9 @@ public void elementTextShouldNotBe(String locator, String text, String...params)
423420
}
424421
}
425422

426-
@RobotKeyword("Returns the value of an element attribute.\r\n" +
427-
"\r\n" +
428-
"The ``attribute_locator`` consists of element locator followed by an @ sign and attribute name. Example: element_id@class\r\n" +
429-
"\r\n" +
430-
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.\r\n" +
431-
"\r\n" +
432-
"Passing attribute name as part of the locator was removed in SeleniumLibrary 3.2. The explicit attribute argument should be used instead.")
433-
@ArgumentNames({ "attributeLocator" })
434-
@Deprecated
435-
public String getElementAttribute(String attributeLocator) {
436-
String[] parts = parseAttributeLocator(attributeLocator);
423+
@RobotKeywordOverload
424+
public String getElementAttribute(String locator) {
425+
String[] parts = parseAttributeLocator(locator);
437426
return getElementAttribute(parts[0], parts[1]);
438427
}
439428

@@ -444,14 +433,15 @@ public String getElementAttribute(String attributeLocator) {
444433
"Example: ${id}= Get Element Attribute css:h1 id\r\n" +
445434
"\r\n" +
446435
"Passing attribute name as part of the locator was removed in SeleniumLibrary 3.2. The explicit attribute argument should be used instead.")
447-
@ArgumentNames({ "locator", "attribute" })
448-
public String getElementAttribute(String locator, String attribute) {
436+
@ArgumentNames({ "locator", "attribute=None" })
437+
public String getElementAttribute(String locator, String... attribute) {
438+
String attributeName = robot.getParamsValue(attribute, 0, "None");
449439
List<WebElement> elements = elementFind(locator, true, false);
450440

451441
if (elements.size() == 0) {
452442
throw new SeleniumLibraryNonFatalException(String.format("Element '%s' not found.", locator));
453443
}
454-
return elements.get(0).getAttribute(attribute);
444+
return elements.get(0).getAttribute(attributeName);
455445
}
456446

457447
@RobotKeyword("Clears the text from element identified by ``locator``.\r\n" +

src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/RunOnFailure.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public void runOnFailure() {
7777
if(runOnFailurePythonInterpreter.get().eval("EXECUTION_CONTEXTS.current").toString().equals("None")) {
7878
return;
7979
}
80+
runningOnFailureRoutine = true;
8081

8182
try {
8283
runOnFailurePythonInterpreter.get().exec(

src/test/java/com/github/markusbernhardt/seleniumlibrary/keywords/BrowserManagementTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public void testCreateDesiredCapabilitiesWithOnlyBrowserOptions() {
6262
assertTrue(profile.getStringPreference("network.proxy.http", "wrong") != "wrong");
6363
}
6464

65+
@Test
66+
public void testCreateDesiredCapabilitiesForHtmlUnit() {
67+
Capabilities dc = bm.createCapabilities("htmlunitwithjs", null, "");
68+
assertTrue(dc.getBrowserName().equals("htmlunit"));
69+
}
70+
6571
@Test
6672
public void parseChromeBrowserOptions() {
6773
ChromeOptions chromeOptions = new ChromeOptions();

src/test/robotframework/testsuites/UnitTests/AW3Schools.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
*** Settings ***
22
Suite Teardown Close All Browsers
33
Resource ../../settings/Settings.robot
4+
Default Tags htmlunitwith htmlunitwithjs
45

56
*** Variables ***
67
${URL Application} http://www.w3schools.com
78

89
*** Test Cases ***
910
Select
10-
[Tags] jbrowser
1111
Open Browser https://developer.mozilla.org/en/docs/Web/HTML/Element/select#Examples ${browser} mainbrowser
1212
Wait Until Page Contains Element xpath://select
1313
Select From List xpath://select Third Value

src/test/robotframework/testsuites/UnitTests/ExtJS.robot

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Suite Setup Open Page
33
Suite Teardown Close Browser
44
Resource ../../settings/Settings.robot
5-
Default Tags jbrowser
65

76
*** Variables ***
87
${URL Application} http://examples.sencha.com/extjs/6.5.0/examples/classic/ticket-app/index.html

src/test/robotframework/testsuites/UnitTests/GetInnerElementId.robot

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
*** Settings ***
22
Resource ../../settings/Settings.robot
3-
Default Tags jbrowser
43

54
*** Test Cases ***
65
Get Inner Element Id test

src/test/robotframework/testsuites/UnitTests/WhatAreCookies.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ Resource ../../settings/Settings.robot
55
Cookies
66
Open Browser http://www.whatarecookies.com/cookietest.asp ${browser} mainbrowser
77
${all_cookies}= Get Cookies
8-
${test}= Get Cookie Value __atuvc
8+
${test}= Get Cookie Value _ga
99
Close Browser

0 commit comments

Comments
 (0)