“错误:没有这样的会话”Webdriver-IO,Appium

时间:2016-12-04 20:35:31

标签: appium webdriver-io

我已经设置了Cucumber,Webdriver-IO和Appium。所有内容似乎都在互相交流,但是当我尝试导航到import com.squareup.moshi.FromJson; import com.squareup.moshi.JsonAdapter; import com.squareup.moshi.Moshi; import com.squareup.moshi.ToJson; import com.squareup.moshi.Types; import org.junit.Assert; import org.junit.Test; import java.io.IOException; import java.lang.reflect.Type; import java.util.List; import java.util.Map; import static org.junit.Assert.assertEquals; public class Foo { static abstract class Vehicle { public String id; public String name; } static class Car extends Vehicle { public Integer numDoors; } static class Boat extends Vehicle { public String propulsion; } static class VehicleAdapter { @FromJson Vehicle fromJson(Map<String, Object> raw) { String typename=raw.get("__typename").toString(); Vehicle result; if (typename.equals("Car")) { Car car=new Car(); car.numDoors=((Double)raw.get("numDoors")).intValue(); result=car; } else if (typename.equals("Boat")) { Boat boat=new Boat(); boat.propulsion=raw.get("propulsion").toString(); result=boat; } else { throw new IllegalStateException("Could not identify __typename: "+typename); } result.id=raw.get("id").toString(); result.name=raw.get("name").toString(); return(result); } @ToJson String toJson(Vehicle vehicle) { throw new UnsupportedOperationException("Um, why is this required?"); } } static final String JSON="[\n"+ " {\n"+ " \"__typename\": \"Car\",\n"+ " \"id\": \"123\",\n"+ " \"name\": \"Toyota Prius\",\n"+ " \"numDoors\": 4\n"+ " },\n"+ " {\n"+ " \"__typename\": \"Boat\",\n"+ " \"id\": \"4567\",\n"+ " \"name\": \"U.S.S. Constitution\",\n"+ " \"propulsion\": \"SAIL\"\n"+ " }\n"+ "]"; @Test public void deserializeGeneric() throws IOException { Moshi moshi=new Moshi.Builder().add(new VehicleAdapter()).build(); Type payloadType=Types.newParameterizedType(List.class, Vehicle.class); JsonAdapter<List<Vehicle>> jsonAdapter=moshi.adapter(payloadType); List<Vehicle> result=jsonAdapter.fromJson(JSON); assertEquals(2, result.size()); assertEquals(Car.class, result.get(0).getClass()); Car car=(Car)result.get(0); assertEquals("123", car.id); assertEquals("Toyota Prius", car.name); assertEquals((long)4, (long)car.numDoors); assertEquals(Boat.class, result.get(1).getClass()); Boat boat=(Boat)result.get(1); assertEquals("4567", boat.id); assertEquals("U.S.S. Constitution", boat.name); assertEquals("SAIL", boat.propulsion); } } 时,我得到Error: no such session

在Android设备上,它会打开Chrome浏览器,然后快速关闭它。

webdriverio.js

http://google.com

env.js

//webdriverio.js
let client = WebDriverIO.remote({
    desiredCapabilities: {
        platformName: 'Android',                        
      browserName: 'chrome',                          
      deviceName: 'test',
    },
    host: 'localhost',                                  
    port: 4723,                                     
    waitForTimeout: 120 * 1000,
});

global.client = client;

module.exports = function() {
  this.registerHandler('BeforeFeatures', function(event, done) {
    client.init().call(done);
  });

  this.registerHandler('AfterFeatures', function(event, done) {
    client.end().call(done);
  });
};

search_steps.js

// env.js
module.exports = function() {
  // added because default 50000 ms was long enough
  this.setDefaultTimeout(60 * 1000);
};

1 个答案:

答案 0 :(得分:0)

问题是chromedriver 2.21.371459,随我的Mac版Appium(1.3.5)一起提供。我下载了最新版本的chromedriver并覆盖了Appium附带的现有版本。有关Windows,请参阅此处Chrome opens for a second and the crashes的答案。对于mac,Appium附带的chromedriver exec的位置是。 /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-driver/node_modules/appium-chromedriver/chromedriver/mac