Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* (C) Copyright 2022 VeriSoft (http://www.verisoft.co)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* 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 co.verisoft.fw.selenium.junit.extensions;
import co.verisoft.fw.extensions.jupiter.XrayPluginExtension;
import co.verisoft.fw.selenium.drivers.VerisoftDriver;
import co.verisoft.fw.selenium.drivers.VerisoftDriverManager;
import co.verisoft.fw.selenium.drivers.VerisoftMobileDriver;
import co.verisoft.fw.selenium.drivers.factory.AnnotationsReader;
import co.verisoft.fw.selenium.drivers.factory.DriverName;
import co.verisoft.fw.selenium.drivers.factory.SingleSession;
import co.verisoft.fw.store.StoreManager;
import co.verisoft.fw.store.StoreType;
import io.appium.java_client.AppiumDriver;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.*;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.HttpCommandExecutor;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.net.URL;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/**
* Extension to inject VerisoftDriver and VerisoftMobileDriver directly into the test instances
* This class is inspired by Boni Garcia code Selenium-Jupiter. Boni Garcia's code can be found
* here.
*
* @author Nir Gallner @ www.VeriSoft.co
* @since 0.0.. (March 2022)
*/
@ToString
@Slf4j
public class DriverInjectionExtension implements ParameterResolver, AfterEachCallback, AfterAllCallback {
AnnotationsReader annotationsReader;
public DriverInjectionExtension() {
annotationsReader = new AnnotationsReader();
}
@Override
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
// Extract the parameter and it's type
Parameter parameter = parameterContext.getParameter();
Class type = parameter.getType();
// Is the type assignable from WebDriver && test is NOT a test template?
return (WebDriver.class.isAssignableFrom(type) && !isTestTemplate(extensionContext));
}
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
ApplicationContext applicationContext;
try {
applicationContext = SpringExtension.getApplicationContext(extensionContext);
}
catch (Exception e)
{
applicationContext=null;
}
Parameter parameter = parameterContext.getParameter();
int index = parameterContext.getIndex();
Optional