селеновый концентратор код отправляет свою команду в уже уничтоженный сеанс.
Мой код селена передает свою команду в уже уничтоженный сеанс.
Я установилсоздание экземпляра драйвера на уровне класса с использованием @beforeclass и уничтожение его @ afterclass.
У меня 2 тестовых случая.Например:
класс A - содержит тесты страницы входа, класс B - содержит тесты целевой страницы.
После выполнения тестов в классе A созданное удаляется:
Removing session b384cee7-56a5-45db-83ca-910b115cbe37 from our master session list
Теперь в тестах создается новый драйвер для Android (с сеансом d29a785f-23fd-4c81-a623-8b96ca2b384d и начинается выполнение тестов в классе B.
Но изблюз селен отправляет команду на b384cee7-56a5-45db-83ca-910b115cbe37 .
Я просто могу из этого разобраться. Может кто-нибудь помочь мне понять, почему это может бытьпроисходит.
2019-01-16 15:03:34:190 - [HTTP] <-- GET /wd/hub/session/d29a785f-23fd-4c81-a623-8b96ca2b384d/screenshot 200 394 ms - 272952
>2019-01-16 15:03:34:190 - [HTTP]
>2019-01-16 15:03:34:238 - [HTTP] --> POST /wd/hub/session/d29a785f-23fd-4c81-a623-8b96ca2b384d/timeouts
>2019-01-16 15:03:34:238 - [HTTP] {"implicit":0}
>2019-01-16 15:03:34:238 - [debug] [W3C (d29a785f)] Calling AppiumDriver.timeouts() with args: [null,null,null,null,0,"d29a785f-23fd-4c81-a623-8b96ca2b384d"]
>2019-01-16 15:03:34:240 - [debug] [BaseDriver] W3C timeout argument: {"implicit":0}}
>2019-01-16 15:03:34:240 - [debug] [BaseDriver] Set implicit wait to 0ms
>2019-01-16 15:03:34:240 - [debug] [W3C (d29a785f)] Responding to client with driver.timeouts() result: null
>2019-01-16 15:03:34:241 - [HTTP] <-- POST /wd/hub/session/d29a785f-23fd-4c81-a623-8b96ca2b384d/timeouts 200 3 ms - 14
>2019-01-16 15:03:34:241 - [HTTP]
>2019-01-16 15:03:34:248 - [HTTP] --> POST /wd/hub/session/b384cee7-56a5-45db-83ca-910b115cbe37/elements
>2019-01-16 15:03:34:249 - [HTTP] {"using":"xpath","value":"//android.widget.FrameLayout[@content-desc=\"list-template0-group3-hpanel0\"]/android.widget.FrameLayout"}
>2019-01-16 15:03:34:275 - [debug] [W3C (b384cee7)] Encountered internal error running command: NoSuchDriverError: A session is either terminated or not started
>2019-01-16 15:03:34:275 - [debug] [W3C (b384cee7)] at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:298:15)
>2019-01-16 15:03:34:276 - [debug] [W3C (b384cee7)] at app.(anonymous function) (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:492:15)
>2019-01-16 15:03:34:276 - [debug] [W3C (b384cee7)] at Layer.handle [as handle_request] (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
>2019-01-16 15:03:34:276 - [debug] [W3C (b384cee7)] at next (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/route.js:137:13)
Ожидаемое поведение :
Концентратор селена не должен был публиковаться в удаленном сеансе b384cee7-56a5-45db-83ca-910b115cbe37 поскольку этот сеанс был прерван после выполнения тестов в classA .
Версия
- appium - 1.10.1
- селеновый концентратор - 3.14.0
- TestNG - 6.14.3
Журнал ошибок
2019-01-16 15:03:34:190 - [HTTP] <-- GET /wd/hub/session/d29a785f-23fd-4c81-a623-8b96ca2b384d/screenshot 200 394 ms - 272952
2019-01-16 15:03:34:190 - [HTTP]
2019-01-16 15:03:34:238 - [HTTP] --> POST /wd/hub/session/d29a785f-23fd-4c81-a623-8b96ca2b384d/timeouts
2019-01-16 15:03:34:238 - [HTTP] {"implicit":0}
2019-01-16 15:03:34:238 - [debug] [W3C (d29a785f)] Calling AppiumDriver.timeouts() with args: [null,null,null,null,0,"d29a785f-23fd-4c81-a623-8b96ca2b384d"]
2019-01-16 15:03:34:240 - [debug] [BaseDriver] W3C timeout argument: {"implicit":0}}
2019-01-16 15:03:34:240 - [debug] [BaseDriver] Set implicit wait to 0ms
2019-01-16 15:03:34:240 - [debug] [W3C (d29a785f)] Responding to client with driver.timeouts() result: null
2019-01-16 15:03:34:241 - [HTTP] <-- POST /wd/hub/session/d29a785f-23fd-4c81-a623-8b96ca2b384d/timeouts 200 3 ms - 14
2019-01-16 15:03:34:241 - [HTTP]
2019-01-16 15:03:34:248 - [HTTP] --> POST /wd/hub/session/b384cee7-56a5-45db-83ca-910b115cbe37/elements
2019-01-16 15:03:34:249 - [HTTP] {"using":"xpath","value":"//android.widget.FrameLayout[@content-desc=\"list-template0-group3-hpanel0\"]/android.widget.FrameLayout"}
2019-01-16 15:03:34:275 - [debug] [W3C (b384cee7)] Encountered internal error running command: NoSuchDriverError: A session is either terminated or not started
2019-01-16 15:03:34:275 - [debug] [W3C (b384cee7)] at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:298:15)
2019-01-16 15:03:34:276 - [debug] [W3C (b384cee7)] at app.(anonymous function) (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:492:15)
2019-01-16 15:03:34:276 - [debug] [W3C (b384cee7)] at Layer.handle [as handle_request] (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
2019-01-16 15:03:34:276 - [debug] [W3C (b384cee7)] at next (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/route.js:137:13)
2019-01-16 15:03:34:276 - [debug] [W3C (b384cee7)] at Route.dispatch (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/route.js:112:3)
2019-01-16 15:03:34:276 - [debug] [W3C (b384cee7)] at Layer.handle [as handle_request] (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
2019-01-16 15:03:34:276 - [debug] [W3C (b384cee7)] at /usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:281:22
2019-01-16 15:03:34:277 - [debug] [W3C (b384cee7)] at param (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:354:14)
2019-01-16 15:03:34:277 - [debug] [W3C (b384cee7)] at param (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:365:14)
2019-01-16 15:03:34:277 - [debug] [W3C (b384cee7)] at Function.process_params (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:410:3)
2019-01-16 15:03:34:277 - [debug] [W3C (b384cee7)] at next (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:275:10)
2019-01-16 15:03:34:277 - [debug] [W3C (b384cee7)] at logger (/usr/local/lib/node_modules/appium/node_modules/morgan/index.js:144:5)
2019-01-16 15:03:34:278 - [debug] [W3C (b384cee7)] at Layer.handle [as handle_request] (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
2019-01-16 15:03:34:278 - [debug] [W3C (b384cee7)] at trim_prefix (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:317:13)
2019-01-16 15:03:34:278 - [debug] [W3C (b384cee7)] at /usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:284:7
2019-01-16 15:03:34:278 - [debug] [W3C (b384cee7)] at Function.process_params (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:335:12)
2019-01-16 15:03:34:278 - [debug] [W3C (b384cee7)] at next (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/index.js:275:10)
2019-01-16 15:03:34:278 - [debug] [W3C (b384cee7)] at /usr/local/lib/node_modules/appium/node_modules/body-parser/lib/read.js:130:5
2019-01-16 15:03:34:278 - [debug] [W3C (b384cee7)] at invokeCallback (/usr/local/lib/node_modules/appium/node_modules/raw-body/index.js:224:16)
2019-01-16 15:03:34:279 - [debug] [W3C (b384cee7)] at done (/usr/local/lib/node_modules/appium/node_modules/raw-body/index.js:213:7)
2019-01-16 15:03:34:279 - [debug] [W3C (b384cee7)] at IncomingMessage.onEnd (/usr/local/lib/node_modules/appium/node_modules/raw-body/index.js:273:7)
2019-01-16 15:03:34:279 - [debug] [W3C (b384cee7)] at emitNone (events.js:106:13)
2019-01-16 15:03:34:279 - [debug] [W3C (b384cee7)] at IncomingMessage.emit (events.js:208:7)
2019-01-16 15:03:34:279 - [debug] [W3C (b384cee7)] at endReadableNT (_stream_readable.js:1064:12)
2019-01-16 15:03:34:279 - [debug] [W3C (b384cee7)] at _combinedTickCallback (internal/process/next_tick.js:139:11)
2019-01-16 15:03:34:280 - [debug] [W3C (b384cee7)] at process._tickCallback (internal/process/next_tick.js:181:9)
2019-01-16 15:03:34:282 - [HTTP] <-- POST /wd/hub/session/b384cee7-56a5-45db-83ca-910b115cbe37/elements 404 32 ms - 2658
2019-01-16 15:03:34:282 - [HTTP]
2019-01-16 15:03:35:301 - [HTTP] --> GET /wd/hub/session/d29a785f-23fd-4c81-a623-8b96ca2b384d/window/rect
Заводской код драйвера
public class DriverFactory {
private static List<WebDriverThread> webDriverThreadPool = Collections.synchronizedList(new ArrayList<WebDriverThread>());
private static ThreadLocal<WebDriverThread> driverThread;
private static Logger logger = LogManager.getLogger(DriverFactory.class);
protected static Map<String, RemoteWebDriver> driverPool;
@BeforeSuite
public static void instantiateDriverObject() {
logger.info("Instantiating Driver Object");
driverThread = ThreadLocal.withInitial(() -> {
WebDriverThread webDriverThread = new WebDriverThread();
webDriverThreadPool.add(webDriverThread);
return webDriverThread;
});
}
public static RemoteWebDriver getDriver(String browserName) {
logger.info("Getting WebDriver");
driverThread.get().getDriver(browserName);
return getDriverPool().get(browserName);
}
public static RemoteWebDriver getDriver(String appName, String appPackage, String appActivity) {
driverThread.get().getDriver(appName, appPackage, appActivity);
return getDriverPool().get(appName);
}
public static RemoteWebDriver getDriver(String appName, String pCloudyApplicationName, int pCloudyDurationInMinutes, String pCloudyDeviceFullName) {
driverThread.get().getDriver(appName, pCloudyApplicationName, pCloudyDurationInMinutes, pCloudyDeviceFullName);
return getDriverPool().get(appName);
}
public static RemoteWebDriver getDriver(String appName, String uuid, String bundleId, String xcodeOrgId) {
driverThread.get().getDriver(appName, uuid, bundleId, xcodeOrgId);
return getDriverPool().get(appName);
}
public static Map<String, RemoteWebDriver> getDriverPool() {
if (driverPool == null) {
driverPool = new HashMap<>();
}
return driverPool;
}
@AfterMethod
public static void clearCookies() {
try {
if (!getDriverPool().entrySet().isEmpty()) {
for (Map.Entry<String, RemoteWebDriver> driver : getDriverPool().entrySet()) {
if (!((driver.getValue() instanceof AndroidDriver) || ((driver.getValue() instanceof IOSDriver))))
driver.getValue().manage().deleteAllCookies();
}
}
} catch (WebDriverException wde) {
logger.error("No need of clearing the cookies");
}
}
@AfterSuite
public static void closeDriverObjects() {
logger.info("Close the Driver ***************");
try {
logger.info("Updating the RemoteWebdriver ***************");
// PropertyHelper.updateHubUrlStatus(MainUtil.storeVariable.get("HUB_URL_ID"),"0");
for (WebDriverThread webDriverThread : webDriverThreadPool) {
if (webDriverThread != null) {
webDriverThread.quitDriver();
} else {
logger.info("Driver already closed");
}
}
} catch (Exception e) {
logger.error("Error in terminating the driver objects \n", e);
}
}
}
Код инициализации драйвера Android
RemoteWebDriver getDriver(String appName, String appPackage, String appActivity) {
DesiredCapabilities androidDcap = new DesiredCapabilities();
androidDcap.setCapability(MobileCapabilityType.AUTOMATION_NAME, androidConfigData.get("AUTOMATION_NAME"));
androidDcap.setCapability(MobileCapabilityType.PLATFORM_NAME, androidConfigData.get("PLATFORM_NAME"));
androidDcap.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, androidConfigData.get("AUTO_GRANT_PERMISSIONS"));
androidDcap.setCapability(MobileCapabilityType.NO_RESET, androidConfigData.get("NO_RESET"));
androidDcap.setCapability(MobileCapabilityType.FULL_RESET, androidConfigData.get("FULL_RESET"));
androidDcap.setCapability(AndroidMobileCapabilityType.NO_SIGN, androidConfigData.get("NO_SIGN"));
androidDcap.setCapability(AndroidMobileCapabilityType.APP_WAIT_DURATION, 60);
androidDcap.setCapability("browserName", "");
androidDcap.setCapability("newCommandTimeout", Integer.getInteger(androidConfigData.get("newCommandTimeout")));
androidDcap.setCapability("appPackage", appPackage);
androidDcap.setCapability("appActivity", appActivity);
androidDcap.setCapability(AndroidMobileCapabilityType.APP_WAIT_PACKAGE, appPackage);
androidDcap.setCapability(AndroidMobileCapabilityType.APP_WAIT_DURATION, 80000);
try {
if (System.getProperty("location").equalsIgnoreCase("local")) {
driver = new AndroidDriver<>(new URL(configData.get("LOCAL_HUB_URL")), androidDcap);
} else {
driver = new AndroidDriver<>(new URL(configData.get("REMOTE_HUB_URL")), androidDcap);
}
} catch (Exception e) {
logger.error("Driver instantiating failed", e);
}
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
DriverFactory.getDriverPool().put(appName, driver);
return driver;
}
Конфигурация узла Appium:
{
"capabilities": [
{
"maxInstances": 6,
"platformName": "android",
"platformVersion": "5.1.1"
}
],
"configuration": {
"cleanUpCycle": 2000,
"timeout": 0,
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"url": "http://127.0.0.1:4651/wd/hub",
"host": "127.0.0.1",
"port": 4504,
"maxSession": 1000,
"register": true,
"registerCycle": 500,
"hubPort": 4651,
"hubHost": "127.0.0.1"
}
}