-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow the htmlrunner to store variables
- Loading branch information
Showing
7 changed files
with
149 additions
and
30 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
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
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
84 changes: 84 additions & 0 deletions
84
java/server/src/org/openqa/selenium/server/htmlrunner/TestState.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,84 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses 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 org.openqa.selenium.server.htmlrunner; | ||
|
||
import static java.util.regex.Pattern.MULTILINE; | ||
|
||
import com.google.common.base.Preconditions; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
class TestState { | ||
private static Map<String, Object> storedValues = new HashMap<>(); | ||
|
||
public void store(String key, Object value) { | ||
storedValues.put(key, value); | ||
} | ||
|
||
private String getValue(String key) { | ||
return Preconditions.checkNotNull(key); | ||
} | ||
|
||
public String expand(String toExpand) { | ||
/* | ||
Selenium.prototype.replaceVariables = function(str) { | ||
var stringResult = str; | ||
// Find all of the matching variable references | ||
var match = stringResult.match(/\$\{\w+\}/g); | ||
if (!match) { | ||
return stringResult; | ||
} | ||
// For each match, lookup the variable value, and replace if found | ||
for (var i = 0; match && i < match.length; i++) { | ||
var variable = match[i]; // The replacement variable, with ${} | ||
var name = variable.substring(2, variable.length - 1); // The replacement variable without ${} | ||
var replacement = storedVars[name]; | ||
if (replacement && typeof(replacement) === 'string' && replacement.indexOf('$') != -1) { | ||
replacement = replacement.replace(/\$/g, '$$$$'); //double up on $'s because of the special meaning these have in 'replace' | ||
} | ||
if (replacement != undefined) { | ||
stringResult = stringResult.replace(variable, replacement); | ||
} | ||
} | ||
return stringResult; | ||
}; | ||
*/ | ||
Pattern toMatch = Pattern.compile("\\$\\{(\\w+)\\}", MULTILINE); | ||
Matcher matcher = toMatch.matcher(toExpand); | ||
StringBuilder toReturn = new StringBuilder(); | ||
|
||
int lastEnd = 0; | ||
while (matcher.find()) { | ||
// Copy from the last end into the stringbuffer | ||
toReturn.append(toExpand.substring(lastEnd, matcher.start())); | ||
// Now insert the value | ||
toReturn.append(getValue(matcher.group(1))); | ||
lastEnd = matcher.end(); | ||
} | ||
|
||
return toReturn.toString(); | ||
} | ||
} |
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