mirror of
https://github.com/appium/appium.git
synced 2026-10-28 20:31:51 +08:00
Fix timeout arguments conversion (#292)
This commit is contained in:
@@ -71,7 +71,8 @@ class ProtocolConverter {
|
||||
if (this.downstreamProtocol === MJSONWP && (!_.has(body, 'ms') || !_.has(body, 'type'))) {
|
||||
const typeToJSONWP = (x) => x === 'pageLoad' ? 'page load' : x;
|
||||
return _.toPairs(body)
|
||||
.filter((pair) => !isNaN(parseFloat(pair[1])))
|
||||
// Only transform the entry if ms value is a valid positive float number
|
||||
.filter((pair) => /^\d+(?:[.,]\d*?)?$/.test(`${pair[1]}`))
|
||||
.map((pair) => {
|
||||
return {
|
||||
type: typeToJSONWP(pair[0]),
|
||||
|
||||
@@ -23,6 +23,17 @@ describe('Protocol Converter', function () {
|
||||
timeoutObjects.length.should.equal(1);
|
||||
timeoutObjects[0].should.eql({type: 'script', ms: 100});
|
||||
});
|
||||
it('should ignore invalid entries while converting from W3C', function () {
|
||||
converter.downstreamProtocol = MJSONWP;
|
||||
let timeoutObjects = converter.getTimeoutRequestObjects({
|
||||
script: 100,
|
||||
sessionId: '5432a4f3-cd89-4781-8905-ea9d3150840c',
|
||||
bar: -1,
|
||||
baz: undefined,
|
||||
});
|
||||
timeoutObjects.length.should.equal(1);
|
||||
timeoutObjects[0].should.eql({type: 'script', ms: 100});
|
||||
});
|
||||
it('should take multiple W3C timeouts and produce multiple MJSONWP compatible objects', function () {
|
||||
converter.downstreamProtocol = MJSONWP;
|
||||
let [scriptTimeout, pageLoadTimeout, implicitTimeout] = converter.getTimeoutRequestObjects({script: 100, pageLoad: 200, implicit: 300});
|
||||
|
||||
Reference in New Issue
Block a user