Search in sources :

Example 26 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class TestTestManagerReporter method testResultIsNotRecordedWrongTestId.

@Test(groups = { "it" })
public void testResultIsNotRecordedWrongTestId() throws Exception {
    try {
        System.setProperty(SeleniumTestsContext.TMS_TYPE, "squash");
        System.setProperty(SeleniumTestsContext.TMS_URL, "http://localhost:1234");
        System.setProperty(SeleniumTestsContext.TMS_PROJECT, "Project");
        System.setProperty(SeleniumTestsContext.TMS_USER, "squash");
        System.setProperty(SeleniumTestsContext.TMS_PASSWORD, "squash");
        doThrow(new ConfigurationException("Wrong Test ID")).when(api).addTestCaseInIteration(eq(iteration), anyInt());
        executeSubTest(1, new String[] { "com.seleniumtests.it.stubclasses.StubTestClassForTestManager" }, ParallelMode.METHODS, new String[] { "testAndSubActions" });
        // check no result has been recorded
        verify(api, never()).setExecutionResult(eq(iterationTestPlanItem), any());
    } finally {
        System.clearProperty(SeleniumTestsContext.TMS_TYPE);
        System.clearProperty(SeleniumTestsContext.TMS_PROJECT);
        System.clearProperty(SeleniumTestsContext.TMS_URL);
        System.clearProperty(SeleniumTestsContext.TMS_USER);
        System.clearProperty(SeleniumTestsContext.TMS_PASSWORD);
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 27 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class JiraConnector method transitionIssue.

/**
 * Transition issue
 * @param issueClient
 * @param issue
 * @param transitions
 * @param transitionName
 */
private void transitionIssue(IssueRestClient issueClient, Issue issue, Map<String, Transition> transitions, String transitionName) {
    for (int i = 0; i < 5; i++) {
        if (transitions.get(transitionName) == null) {
            // update available transitions
            WaitHelper.waitForMilliSeconds(500);
            transitions.clear();
            issueClient.getTransitions(issue).claim().forEach(transition -> transitions.put(transition.getName(), transition));
            continue;
        }
        issueClient.transition(issue, new TransitionInput(transitions.get(transitionName).getId(), new ArrayList<>()));
        return;
    }
    throw new ConfigurationException(String.format("'bugtracker.jira.closeTransition': value [%s] is invalid for this issue in its current state, allowed transitions are %s", transitionName, transitions.keySet()));
}
Also used : TransitionInput(com.atlassian.jira.rest.client.api.domain.input.TransitionInput) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) ArrayList(java.util.ArrayList)

Example 28 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class JiraConnector method main.

/**
 * Method for getting required fields and allowed values for creating an issue on a project
 *
 * @param args
 * 		server => url of jira server
 * 		user => user to connect to jira
 * 		password => password to connect to jira
 * 		project => projectkey
 * 		issueType => type of the issue that will be created
 * 		issueKey (optional) => give the transitions for a specific issue
 */
public static void main(String[] args) {
    if (args.length < 5) {
        System.out.println("Usage: JiraConnector <server> <projectKey> <user> <password> <issueType>");
        System.exit(1);
    }
    JiraConnector jiraConnector = new JiraConnector(args[0], args[1], args[2], args[3]);
    IssueType issueType = jiraConnector.issueTypes.get(args[4]);
    if (issueType == null) {
        throw new ConfigurationException(String.format("Issue type %s cannot be found among valid issue types %s", args[4], jiraConnector.issueTypes.keySet()));
    }
    System.out.println("Proprities:");
    for (String priority : jiraConnector.priorities.keySet()) {
        System.out.println(String.format(ITEM, priority));
    }
    System.out.println("\nComponents:");
    for (String component : jiraConnector.components.keySet()) {
        System.out.println(String.format(ITEM, component));
    }
    System.out.println(String.format("\nListing required fields and allowed values (if any) for issue '%s'", args[4]));
    Map<String, CimFieldInfo> fieldInfos = jiraConnector.getCustomFieldInfos(jiraConnector.project, issueType);
    for (Entry<String, List<String>> entry : jiraConnector.getRequiredFieldsAndValues(fieldInfos).entrySet()) {
        System.out.println(String.format("Field '%s':", entry.getKey()));
        for (String value : entry.getValue()) {
            System.out.println(String.format(ITEM, value));
        }
    }
    if (args.length >= 6) {
        IssueRestClient issueClient = jiraConnector.restClient.getIssueClient();
        Issue issue;
        try {
            issue = issueClient.getIssue(args[5]).claim();
        } catch (RestClientException e) {
            throw new ScenarioException(String.format("Jira issue %s does not exist, cannot close it", args[5]));
        }
        Map<String, Transition> transitions = new HashMap<>();
        issueClient.getTransitions(issue).claim().forEach(transition -> transitions.put(transition.getName(), transition));
        System.out.println(transitions);
    }
}
Also used : Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) HashMap(java.util.HashMap) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) Transition(com.atlassian.jira.rest.client.api.domain.Transition) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 29 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class Uft method prepareArguments.

/**
 * Prepare list of arguments
 *
 * @param load    if true, add '/load'
 * @param execute if true, add '/execute'
 * @return
 */
public List<String> prepareArguments(boolean load, boolean execute) {
    // copy uft.vbs to disk
    String vbsPath;
    try {
        File tempFile = Files.createTempDirectory("uft").resolve(SCRIPT_NAME).toFile();
        tempFile.deleteOnExit();
        FileUtils.copyInputStreamToFile(Thread.currentThread().getContextClassLoader().getResourceAsStream("uft/" + SCRIPT_NAME), tempFile);
        vbsPath = tempFile.getAbsolutePath();
    } catch (IOException e) {
        throw new ScenarioException("Error sending UFT script to grid node: " + e.getMessage());
    }
    if (SeleniumTestsContextManager.getThreadContext().getRunMode() == DriverMode.GRID) {
        SeleniumGridConnector gridConnector = SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector();
        if (gridConnector != null) {
            vbsPath = Paths.get(gridConnector.uploadFileToNode(vbsPath, true), SCRIPT_NAME).toString();
        } else {
            throw new ScenarioException("No grid connector present, executing UFT script needs a browser to be initialized");
        }
    }
    List<String> args = new ArrayList<>();
    args.add(vbsPath);
    args.add(scriptPath);
    if (execute) {
        args.add("/execute");
        parameters.forEach((key, value) -> args.add(String.format("\"%s=%s\"", key, value)));
    }
    if (load) {
        if (almServer != null && almUser != null && almPassword != null && almDomain != null && almProject != null) {
            args.add("/server:" + almServer);
            args.add("/user:" + almUser);
            args.add("/password:" + almPassword);
            args.add("/domain:" + almDomain);
            args.add("/project:" + almProject);
        } else if (almServer != null || almUser != null || almPassword != null || almDomain != null || almProject != null) {
            throw new ConfigurationException("All valuers pour ALM connection must be provided: server, user, password, domain and project");
        }
        args.add("/load");
        if (killUftOnStartup) {
            args.add("/clean");
        }
    }
    return args;
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) SeleniumGridConnector(com.seleniumtests.connectors.selenium.SeleniumGridConnector) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 30 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class SauceLabsCapabilitiesFactory method uploadFile.

/**
 * Upload application to saucelabs server
 * @param targetAppPath
 * @param serverURL
 * @return
 * @throws IOException
 * @throws AuthenticationException
 */
private void uploadFile(String application) {
    // extract user name and password from getWebDriverGrid
    Matcher matcher = REG_USER_PASSWORD.matcher(SeleniumTestsContextManager.getThreadContext().getWebDriverGrid().get(0));
    String user;
    String password;
    String datacenter;
    if (matcher.matches()) {
        user = matcher.group(1);
        password = matcher.group(2);
        datacenter = matcher.group(3);
    } else {
        throw new ConfigurationException("webDriverGrid variable does not have the right format for connecting to sauceLabs: \"https://<user>:<token>@ondemand.<datacenter>.saucelabs.com:443/wd/hub\"");
    }
    try (UnirestInstance unirest = Unirest.spawnInstance()) {
        String proxyHost = System.getProperty("https.proxyHost");
        String proxyPort = System.getProperty("https.proxyPort");
        if (proxyHost != null && proxyPort != null) {
            unirest.config().proxy(proxyHost, Integer.valueOf(proxyPort));
        }
        unirest.post(String.format(SAUCE_UPLOAD_URL, datacenter)).basicAuth(user, password).field("payload", new File(application)).field("name", new File(application).getName()).asString().ifFailure(response -> {
            throw new ConfigurationException(String.format("Application file upload failed: %s", response.getStatusText()));
        }).ifSuccess(response -> {
            logger.info("Application successfuly uploaded to Saucelabs");
        });
    } catch (UnirestException e) {
        throw new ConfigurationException("Application file upload failed: " + e.getMessage());
    }
}
Also used : MobileCapabilityType(io.appium.java_client.remote.MobileCapabilityType) IOException(java.io.IOException) Capabilities(org.openqa.selenium.Capabilities) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) MutableCapabilities(org.openqa.selenium.MutableCapabilities) Unirest(kong.unirest.Unirest) File(java.io.File) SeleniumTestsContextManager(com.seleniumtests.core.SeleniumTestsContextManager) Matcher(java.util.regex.Matcher) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) UnirestInstance(kong.unirest.UnirestInstance) Pattern(java.util.regex.Pattern) AuthenticationException(org.apache.http.auth.AuthenticationException) UnirestException(kong.unirest.UnirestException) DriverConfig(com.seleniumtests.driver.DriverConfig) UnirestInstance(kong.unirest.UnirestInstance) Matcher(java.util.regex.Matcher) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) UnirestException(kong.unirest.UnirestException) File(java.io.File)

Aggregations

ConfigurationException (com.seleniumtests.customexception.ConfigurationException)66 ArrayList (java.util.ArrayList)19 File (java.io.File)18 IOException (java.io.IOException)14 HashMap (java.util.HashMap)13 Test (org.testng.annotations.Test)13 Matcher (java.util.regex.Matcher)9 List (java.util.List)8 UnirestException (kong.unirest.UnirestException)8 GenericTest (com.seleniumtests.GenericTest)7 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ScenarioException (com.seleniumtests.customexception.ScenarioException)5 BrowserType (com.seleniumtests.driver.BrowserType)5 Map (java.util.Map)5 Pattern (java.util.regex.Pattern)5 Collectors (java.util.stream.Collectors)5 Win32Exception (com.sun.jna.platform.win32.Win32Exception)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Files (java.nio.file.Files)4