Hi,
In my Java selenium jupiter Junit5 project, I am using Appium server that initialized with capabilities before tests run for example:
in BeforeAll method:
first question:
I need to identify if appium server is already in use before each run and close it,
I read that if I use appium capabilities it automatically needs to close before each run test, but when I run entire class or project - it means amount of tests, between the tests - before each test run it does not happens, and the appium not close.
How and what do I need to do for this task?
second issue in the same topic:
If I need Appium to run in different port (not on 4723), I know that I need to specified DriverUrl with different port, I specified it, @DriverUrl
private String url = “http://127.0.0.1:5687/wd/hub”;
But the port still doesn’t change.
What the way to change the port in this using?
Most of the time when people want this, it’s because they want to run their tests in parallel, a tutorial like this will explain how to specify the port to run on (java examples):
@wreed
Thanks for the helpful answers.
So now I can know if Appium server is already in use.
but I also need an appropriate command for my case to close the Appium.
Do you have an answer for me?
Thanks a lots!
@wreed
I mean - that if Apium runs, that he should not start it again but continue on it session.
The problem is that when use capabilities, automatically Appium start every test run.
My need is control over opening and closing Appium, but still using capabilities. Then before each test I will check and if the port is already in use - I will not start Appium, if it is not in use - I will start it.
@wreed
Thank you for the quick answer.
I did not mean use the fullReset , noReset capabilities. - (I use them already in certain tests)
My intention is a wrapper of the Appium (that currently automatically opens before each test although Appium had open already in the first test… ) in an object that I can use to open and close the Appium as I need.
I saw something that might suit me:
the first option in this site.
Question: is it a good and acceptable way?
Or what is the best way for all platforms - IOS and Android, that most easily will help in my problem?
Ok, I took a look at the article. It’s good, the first option looks fine. I think a wrapper is an interesting idea. It certainly gives a certain amount of control that you don’t have otherwise.
I don’t think that it should matter for iOS vs Android. Starting and maintaining the server should be pretty agnostic.
public void startServer() {
//Set Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(“noReset”, “false”);
//Build the Appium service
builder = new AppiumServiceBuilder();
builder.withIPAddress("127.0.0.1");
builder.usingPort(4356);
builder.withCapabilities(caps);
builder.withArgument(GeneralServerFlag.SESSION_OVERRIDE);
builder.withArgument(GeneralServerFlag.LOG_LEVEL, "error");
//Start the server with the builder
service = AppiumDriverLocalService.buildService(builder);
service.start();
}
But I get an error when start the service:
…\AppData\Roaming\npm\node_modules\appium\build\lib\main.js: error: argument -dc/–default-capabilities: invalid parseDefaultCaps value: ‘{noReset:false}’
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\Efrat Cohen\AppData\Roaming\npm\node_modules\appium\build\lib\main.js, --port, 4356, --address, 127.0.0.1, --log-level, error, --session-override, --default-capabilities, {“noReset”:“false”}]
What can be the problem?
How do I need to set my capabilities when use AppiumServiceBuilder ?
This looks like a basic Java error. You are declaring the variable ‘cap’ as private just like the sample code but then you declare a non private, ‘caps’ and try to use that. The sample code looks like this:
private DesiredCapabilities cap;
cap = new DesiredCapabilities();
builder.withCapabilities(cap);
I would just advise you to follow the tutorial more closely.
Hi @wreed
Sorry for the error in the code, because I tried to fix it, I sent you with this error.
Of course I followed exactly according to the guide.
Even when I do this: