I am trying to start the Appium server using Appium service builder but am getting the following error. I tried everything but still get the error.
AppiumTest
io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException: The local appium server has not been started. The given Node.js executable: C:\Program Files\nodejs\node.exe Arguments: [C:\Users\[username]\AppData\Roaming\npm\node_modules\appium\build\lib\main.js, --port, 4723, --address, 127.0.0.1]
at io.appium.java_client.service.local.AppiumDriverLocalService.start(AppiumDriverLocalService.java:191)
package MahiyarAutomation;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.testng.annotations.Test;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
public class AppiumBasics {
#Test
public void AppiumTest() throws MalformedURLException
{
AppiumDriverLocalService service = new AppiumServiceBuilder().withAppiumJS(new File("C:\\Users\\mahiyarwadia\\AppData\\Roaming\\npm\\node_modules\\appium\\build\\lib\\main.js"))
.withIPAddress("127.0.0.1").usingPort(4723).build();
service.start();
UiAutomator2Options options = new UiAutomator2Options();
options.setDeviceName ("MahiyarPhone");
options.setApp ("//Users//mahiyarwadia//eclipse-workspace//Appium//src//test//java//resources//ApiDemos-debug.apk");
}
}
Could you try the following?
AppiumServiceBuilder builder = new AppiumServiceBuilder()
.withAppiumJS(new File("C:\\Users\\mahiyarwadia\\AppData\\Roaming\\npm\\node_modules\\appium\\build\\lib\\main.js"))
.withIPAddress("127.0.0.1")
.usingPort(4723);
AppiumDriverLocalService service = AppiumDriverLocalService.buildService(builder);
service.start();
If it still does not work:
Are you able to start the server via the GUI or command line?
Is the Appium path correct?
Related
I've got some code that was intended to logon using selenium( selenium-4.7.2) so that I can keep up with job alerts on a popular job site. It's also a means of keeping my skills up while seeking work.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.chrome.service import Service
#from webdriver_manager.chrome import ChromeDriverManager
#driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Set up the webdriver
driver = webdriver.Chrome()
# Navigate to the login page
driver.get('https://www.linkedin.com/uas/login')
# Enter your login credentials
driver.find_element_by_id('username').send_keys('elksie#gmail.com')
driver.find_element_by_id('password').send_keys('g')
# Click the "Sign in" button
driver.find_element_by_css_selector('button[type="submit"]').click()
# Wait for the page to load
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'jobs-search-box')))
# Navigate to the job search page
driver.get('https://www.linkedin.com/jobs/search/?currentJobId=3424225432&keywords=data%20analyst&refresh=true')
# Wait for the page to load
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'job-card-container')))
# Extract the job data
job_cards = driver.find_elements_by_class_name('job-card-container')
for job_card in job_cards:
title = job_card.find_element_by_class_name('job-card-container__title').text
company = job_card.find_element_by_class_name('job-card-container__subtitle').text
location = job_card.find_element_by_class_name('job-card-container__bullet').text
print(title, company, location)
# Close the browser
driver.close()
The lines...
driver.find_element_by_id('username').send_keys('elksie#gmail.com')
driver.find_element_by_id('password').send_keys('g')
errors with:
AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'
find_element_by_id has been deprecated. Use driver.find_element(By.ID, 'username')
Import By using:
from selenium.webdriver.common.by import By
import time
import ScrollUtil
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['deviceName'] = 'Android'
desired_caps['appPackage'] = 'com.samsung.android.dialer'
desired_caps['appActivity'] = 'com.samsung.android.dialer.DialtactsActivity'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.implicitly_wait(10)
ScrollUtil.swipeUp(4,driver)
ScrollUtil.swipeDown(4,driver)
# driver.find_element_by_android_uiautomator(
# 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("Akash").instance(0))').click()
time.sleep(2)
driver.quit()
`
When I execute the above scripts I receive the below error messages and cannot be executed. I have already open the Appium Server
self.capabilities = response.get('value')
AttributeError: can't set attribute
Error message
Reinstall Appium-Python-Client using pip, instead of npm
And make sure selenium 3.XX version is installed
How do I configure Micronaut app using Vert.x and testcontainers? I'm trying:
application-test.yml
datasources:
default:
url: jdbc:tc:mysql:8:///db
driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver
vertx:
mysql:
client:
uri: jdbc:tc:mysql:8:///db
Tests with micronaut-data-jdbc work, but with micronaut-vertx-mysql-client not work:
Error:
Message: Cannot parse invalid connection URI: jdbc:tc:mysql:8:///db
I'm not very familiar with testecontainers, but it seems like it doesn't come up with a fixed port, so I don't know how to configure the connection URI.
Thanks!
It might be a problem that micronaut-vertx-mysql-client does not support the Testcontainers JDBC URL scheme (hard to say without further logs).
In this case, I would suggest to use Testcontainers with database container objects instead of the special JDBC URL.
I got a solution to the problem:
Micronaut + jdbc hikari + vertx mysql client + flyway mysql
package br.com.app;
import io.micronaut.context.ApplicationContext;
import io.micronaut.context.env.PropertySource;
import io.micronaut.core.util.CollectionUtils;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.client.HttpClient;
import io.micronaut.runtime.EmbeddedApplication;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
#Testcontainers
class AuthTest {
static Logger log = LoggerFactory.getLogger(AuthTest.class.getName());
#Container
static MySQLContainer mysql = new MySQLContainer("mysql:8");
private HttpClient client;
private static EmbeddedApplication application;
private static ApplicationContext context;
#BeforeAll
public static void initTests(){
log.info("Mysql is running {}, port {}", mysql.isRunning(), mysql.getFirstMappedPort());
var port = mysql.getFirstMappedPort();
var host = mysql.getHost();
var database = mysql.getDatabaseName();
var user = mysql.getUsername();
var password = mysql.getPassword();
var url = String.format("jdbc:mysql://%s:%s/%s", host, port, database);
application = ApplicationContext.run(EmbeddedApplication.class,
PropertySource.of(
"test",
CollectionUtils.mapOf(
"vertx.mysql.client.port", port,
"vertx.mysql.client.host", host,
"vertx.mysql.client.database", database,
"vertx.mysql.client.user", user,
"vertx.mysql.client.password", password,
"datasources.default.url", url,
"datasources.default.username", user,
"datasources.default.password", password,
"flyway.datasources.default.enabled", true
)
));
context = application.getApplicationContext();
}
#BeforeEach
void beforeEach(){
this.authService = context.getBean(AuthService.class);
this.client = context.getBean(HttpClient.class);
}
#Test
void testItWorks() {
Assertions.assertTrue(application.isRunning());
}
// api tests
}
Help links:
https://dev.to/major13ua/micronaut-integration-testing-using-testcontainers-2e30
https://github.com/major13ua/micronaut-tc/blob/main/src/test/java/com/example/testcontainer/controller/DemoControllerTest.java
I am trying to run a python script from java; in py script I am using pywinauto package and want to initiate notepad++.
When I am running this script it works fine, however when same is called from Java main method it throws TypeError: __enter__(): expected 1 args; got 0.
Below is python script:
import sys
sys.path.append("C:\\jython2.7.0\\bin")
sys.path.append("C:\\Python27")
sys.path.append("C:\\Python27\\Lib")
sys.path.append("C:\\jython2.7.0\\Lib")
def runpradeep():
print "trying to run it"
from pywinauto.application import Application
app = Application().start('C:\\Program Files (x86)\\Notepad++\\notepad++.exe')
app.kill()
runpradeep()
and below is java class:
package himalaya;
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.Properties;
public class OpenBoApplication {
public static void main(String[] args) throws ScriptException {
Properties props = new Properties();
props.put("python.home", "C:\\Python27");
props.put("python.console.encoding", "UTF-8");
props.put("python.security.respectJavaAccessibility", "false");
props.put("python.import.site", "false");
Properties preprops = System.getProperties();
PythonInterpreter.initialize(preprops, props, new String[0]);
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("D:path to py script\\renatoplease.py");
interpreter.exec("runpradeep()");
}
}
Below is error log:
Exception in thread "main" Traceback (most recent call last):
File "D:\pbhardwa\IdeaProjects\javapythongroovy\src\com\ingenico\runmiddleware\renatoplease.py", line 16, in
runpradeep()
File "D:\pbhardwa\IdeaProjects\javapythongroovy\src\com\ingenico\runmiddleware\renatoplease.py", line 11, in runpradeep
from pywinauto.application import Application
File "pyclasspath/pywinauto/application.py", line 72, in
File "C:\Python27\Lib\multiprocessing__init__.py", line 65, in
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "C:\Python27\Lib\multiprocessing\util.py", line 39, in
import threading # we want threading to install it's
File "C:\Python27\Lib\threading.py", line 1191, in
_shutdown = _MainThread()._exitfunc
File "C:\Python27\Lib\threading.py", line 1083, in init
self._Thread__started.set()
File "C:\Python27\Lib\threading.py", line 582, in set
"""
File "C:\Python27\Lib\threading.py", line 286, in enter
return self.lock.__enter()
TypeError: enter(): expected 1 args; got 0
I am using Intellij ultimate edition and Pycharm plugin is installed. I have also installed pywinauto(as mentioned enter link description here), pythonpath is also set. Also added jython dependencies to class path. Attaching complete project
Any help will surely help us.
I am trying to run Client code in Clinet-Server programming in java and I am getting error "Could not find or load main class."
javac DateClient.java
java DateClient (I have also tried "java -cp . DateClient" but still not working).
Program which I am trying to run is :
package edu.lmu.cs.networking;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import javax.swing.JOptionPane;
public class DateClient {
public static void main(String[] args) throws IOException {
String serverAddress = JOptionPane.showInputDialog(
"Enter IP Address of a machine that is\n" +
"running the date service on port 9090:");
Socket s = new Socket(serverAddress, 9090);
BufferedReader input =new BufferedReader(new InputStreamReader(s.getInputStream()));
String answer = input.readLine();
JOptionPane.showMessageDialog(null, answer);
System.exit(0);
}
}
Your class is in the package edu.lmu.cs.networking. Its name is thus edu.lmu.cs.networking.DateClient. And you thus need to execute it with
java -cp . edu.lmu.cs.networking.DateClient
(assuming . contains the edu directory, which contains the lmu directory, which contains the cs directory, which contains the networking directory, which contains the file DateClient.class).