-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #341 from telekom/feature/uielement-highlighter
Feature/uielement highlighter
- Loading branch information
Showing
7 changed files
with
197 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
.../main/java/eu/tsystems/mms/tic/testframework/pageobjects/DefaultUiElementHighlighter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Testerra | ||
* | ||
* (C) 2023, Martin Großmann, Deutsche Telekom MMS GmbH, Deutsche Telekom AG | ||
* | ||
* Deutsche Telekom AG and all other contributors / | ||
* copyright owners license this file to you under the Apache | ||
* License, Version 2.0 (the "License"); you may not use this | ||
* file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
package eu.tsystems.mms.tic.testframework.pageobjects; | ||
|
||
/** | ||
* Default implementation for UiElement highlighting | ||
* <p> | ||
* highlight.js added an outlined border to the WebElement | ||
* | ||
* @author mgn | ||
*/ | ||
public class DefaultUiElementHighlighter implements UiElementHighlighter { | ||
@Override | ||
public String getJSSnippet() { | ||
return "snippets/highlight.js"; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...-ui/src/main/java/eu/tsystems/mms/tic/testframework/pageobjects/UiElementHighlighter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Testerra | ||
* | ||
* (C) 2023, Martin Großmann, Deutsche Telekom MMS GmbH, Deutsche Telekom AG | ||
* | ||
* Deutsche Telekom AG and all other contributors / | ||
* copyright owners license this file to you under the Apache | ||
* License, Version 2.0 (the "License"); you may not use this | ||
* file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
*/ | ||
package eu.tsystems.mms.tic.testframework.pageobjects; | ||
|
||
import eu.tsystems.mms.tic.testframework.common.Testerra; | ||
import eu.tsystems.mms.tic.testframework.logging.Loggable; | ||
import eu.tsystems.mms.tic.testframework.utils.JSUtils; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import java.awt.Color; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Created on 2023-07-07 | ||
* | ||
* @author mgn | ||
*/ | ||
public interface UiElementHighlighter extends Loggable { | ||
|
||
String getJSSnippet(); | ||
|
||
default void highlight(WebDriver driver, WebElement webElement, Color color) { | ||
long timeout = Testerra.Properties.DEMO_MODE_TIMEOUT.asLong(); | ||
try { | ||
JSUtils.executeScriptWOCatch( | ||
driver, | ||
String.format( | ||
"%s\n" + | ||
"ttHighlight(arguments[0], '%s', %d)", | ||
JSUtils.readScriptResources(Stream.of(getJSSnippet())), | ||
toHex(color), | ||
timeout | ||
), | ||
webElement | ||
); | ||
} catch (Exception e) { | ||
log().error("Unable to highlight WebElement: {}", e.getMessage()); | ||
} | ||
} | ||
|
||
default String toHex(Color color) { | ||
return String.format("#%02x%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.