Every time I launch a script, instead of automating the login page, driver takes session from previous script. I am running the script on iPhone simulator. I am also resetting the device. Please refer the above code for more info,
ServerArguments serverArguments = new ServerArguments();
serverArguments.setArgument("--address", "127.0.0.1");
serverArguments.setArgument("--no-reset", false);
serverArguments.setArgument("--command-timeout", 2400);
serverArguments.setArgument("--local-timezone", true);
serverArguments.setArgument("--full-reset", true);
this.appiumServer = new AppiumServer(new File("/usr/local/bin/node"), new File("/usr/local/lib/node_modules/appium/build/lib/main.js"),serverArguments);
this.appiumServer.startServer();
I am using Genium framework for starting/stopping appium server.
I am setting the above capabilities in DesiredCapabilities class,
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("udid", udid);
capabilities.setCapability("browserName", "Safari");
if (!platformVersion.equals("")) {
capabilities.setCapability("platformVersion", platformVersion);
}
capabilities.setCapability("deviceName", deviceName);
capabilities.setCapability("autoWebview", true);
capabilities.setCapability("newCommandTimeout", 120);
Related
I'm testing a Windows hybrid application, I'm using the codes below to get contexts but I got an UnsupportedCommandException when I launch it.
Here's my code :
public void initialize() throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Windows");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Max");
capabilities.setCapability("app", "D:\\Users\\Max\\Desktop\\TI\\ti.exe");
driver = new AppiumDriver<>(new URL("http://localhost:4723/wd/hub"), capabilities);
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName);
}
driver.context((String) contextNames.toArray()[1]);
}
Here's the output on the Appium Server:
Appium server screen
It says that the command contexts is not recognized.
I'm using :
Appium Desktop v1.20.2
Appium Java client v7.5.1
WinAppDriver v1.2.1
The first of all, you need to get all contexts. More info in official docs
Here how I implemented it in tests.
In some Page Object files I keep Android contexts.
ANDROID_CONTEXTS = {
'webview': 'WEBVIEW_ru.myapp',
'native': 'NATIVE_APP'
}
In some tests I switch context from Native to Webview.
#allure.link(url='https://jira.project.tech/browse/TEST-1', name='TEST-1 - Fill payment form')
#allure.title('Fill payment form')
def test_card_standard_1_month(appdriver):
Paywall(appdriver).press_one_month_button()
PaymentsPage(appdriver).select_card_payment()
PaymentsPage(appdriver).press_payment_button()
appdriver.switch_to.context(ANDROID_CONTEXTS['webview'])
Payform(appdriver).fill_and_submit_payform()
appdriver.switch_to.context(ANDROID_CONTEXTS['native'])
assert SuccessPayment(appdriver).get_successful_payment_title_text() == 'Your subscription is successful!'
You can check all available contexts in your app. More info here -> http://appium.io/docs/en/commands/context/set-context/
I have created an automation project to test a flutter app using appium flutter driver.
But I cannot use flutter driver.
My automation project does not detect automationName as flutter.
Even if I try driver.context("FLUTTER"); I get NoSuchContextException error.
service = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File("/usr/local/bin/node"))
.withAppiumJS(
new File("/usr/local/lib/node_modules/appium/build/lib/main.js"))
.withIPAddress("127.0.0.1").usingPort(4723));
service.start();
DesiredCapabilities capabilities = new DesiredCapabilities();
File appDir = new File(System.getProperty("user.dir")+"/app");
File app = new File (appDir,"app-debug.apk");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability("automationName", "Flutter");
capabilities.setCapability("appPackage", "com.example.flutter_intellij_test");
capabilities.setCapability("appActivity","com.example.flutter_intellij_test.MainActivity");
driver = new AndroidDriver<MobileElement>(service.getUrl(), capabilities);
wait = new WebDriverWait(driver, 10);
find = new FlutterFinder(driver);
Make sure your Appium server version is above 1.6
There shouldn't be anything specific with Java client, just try to change your capabilities this way:
DesiredCapabilities capabilities = new DesiredCapabilities();
File appDir = new File(System.getProperty("user.dir")+"/app");
File app = new File (appDir,"app-debug.apk");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("automationName", "Flutter");
capabilities.setCapability("retryBackoffTime", "500");
capabilities.setCapability("deviceName", <value from `adb devices`>);
driver = new AndroidDriver<MobileElement>(service.getUrl(), capabilities);
Next time post Appium server log :)
In my feature automation, I need to disable JavaScript in browser and run the flow. How to disable JavaScript?
Tried DesiredCapabilities for firefox and Chrome.
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, false)
And
DesiredCapabilities dc = new DesiredCapabilities();
dc.setJavascriptEnabled(false);
For firefox, tried
1) Setting up profile for firefox
2) Adding add-on - noScript.xpi
3) profile.setPreference("javascript.enabled", false);
4) Through UI, tried changing the flag - "javascript.enabled" in "about:config" to false. Here, opened firefox and gave "about:config" getting a warning - "This might void your warranty!". There is a button - "I'll be careful, I promise!" with id - warningButton. This button should be clicked to proceed further. To click this button, used driver.findElement(By.id("warningButton")).click(); but it not work.
All the above options are not working. Any advice will be helpful.
I don't know Java, but maybe a solution for Python 3 will help you.
in Python, you can use Options() instead of FirefoxProfile() to deactivate JavaScript:
from selenium.webdriver.firefox.options import Options
options = Options()
options.preferences.update({"javascript.enabled": False})
driver = webdriver.Firefox(options=options)
driver.get('about:config')
Maybe Java this:
FirefoxOptions options = new FirefoxOptions();
options.preferences.update({"javascript.enabled": False});
WebDriver driver = new FirefoxDriver(options);
driver.get('about:config')
You change the preference value using profile with lots of options:
DesiredCapabilities capabilities = new DesiredCapabilities();
// setCapability(SUPPORTS_JAVASCRIPT, javascriptEnabled);
capabilities.setJavascriptEnabled(false);
FirefoxBinary binary = new FirefoxBinary( new File( binaryPath ) );
FirefoxProfile profile = new FirefoxProfile();
//profile.setPreference("preferenceName", "Value");
profile.setPreference("javascript.enabled", false);
RemoteWebDriver driver = new FirefoxDriver(binary, profile, capabilities);
To view the preferences, you can visit the URL about:config
#See
Chrome driver to disable JavaScript issue
chromium-command-line-switches
Truse me this was random trial but works perfectly for me
from selenium import webdriver
options= webdriver.ChromeOptions()
chrome_prefs = {}
options.experimental_options["prefs"] = chrome_prefs
chrome_prefs["profile.default_content_settings"] = {"javascript": 2}
chrome_prefs["profile.managed_default_content_settings"] = {"javascript": 2}
driver = webdriver.Chrome("your chromedriver path here",options=options)
driver.get('https://google.com/search?q=welcome to python world')
Example image here:-https://i.stack.imgur.com/DdKZQ.png
As per Selenium 3.6 Java Client Release, the easiest way to disable Javascript in the browser would be to set the setJavascriptEnabled argument through an instance of DesiredCapabilities to False and merge it through an instance of FirefoxOptions as follows:
package demo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Q46883024_setJavascriptEnabled
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
DesiredCapabilities dc = new DesiredCapabilities();
dc.setJavascriptEnabled(false);
FirefoxOptions op = new FirefoxOptions();
op.merge(dc);
WebDriver driver = new FirefoxDriver(op);
driver.get("https://google.com");
driver.quit();
}
}
While execution, the browser you are using may override the setJavascriptEnabled settings.
this works:
FirefoxOptions options = new FirefoxOptions();
options.addPreference("javascript.enabled", false);
This is how you can do it for Chrome in Java.
// import org.openqa.selenium.chrome.ChromeOptions;
ChromeOptions options = new ChromeOptions();
options.addArguments("user-agent=\"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)\"");
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_setting_values.javascript", 2);
options.setExperimentalOption("prefs", chromePrefs);
new ChromeDriver(options);
And it worked for me with ChromeDriver 2.41.578706. As a bonus I am also setting Googlebot as user-agent.
In case you need to do something with DesiredCapabilities you can also convert the options above to capabilities:
// import static org.openqa.selenium.chrome.ChromeOptions.CAPABILITY;
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CAPABILITY, options);
new ChromeDriver(capabilities);
I am new to appium. I am getting below error when i Run appium code in eclipse:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{app=D:\Workspace\Mobile\Apps\ATT\AT.apk, appPackage=com.atp.android, appActivity=Splash, appium-version=1.6.4, platformVersion=6.0, platformName=Android, deviceName=Test}], required capabilities = Capabilities [{}]
Code:
private static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException {
AppiumDriver driver;
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "/Apps/AST/");
File app = new File(appDir, "AT.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("appium-version", "1.6.4");
//capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "Test");
capabilities.setCapability("platformVersion", "6.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.atp.android");
capabilities.setCapability("appActivity", "Splash");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(10000);
driver.quit();
Selenium version is 3.4
Please help to resolve this issue. Thanks
You can try to comment the following two lines and see how does it work:
capabilities.setCapability("appPackage", "com.atp.android");
capabilities.setCapability("appActivity", "Splash");
since when you run test on a complicate app, it's hard to make sure the content of apppackage and app are set right. Appium will help you to find the correct content automatically instead.
Saucelabs:-
https://saucelabs.com/
Am creating the firefox driver on saucelabs using the following:-
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("version", "5");
capabilities.setCapability("platform", Platform.XP);
// Create the connection to Sauce Labs to run the tests
this.driver = new RemoteWebDriver(
new URL("http://YOUR_USERNAME:YOUR_ACCESS_KEY#ondemand.saucelabs.com:80/wd/hub"),
capabilities);
}
I want to use the mobile user agent using firefox driver. How can i do it.
Have you tried creating a new profile and setting the user agent string on the profile?
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "UA-STRING");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);