I have implement two scenario outlines in one feature file at cucumber, and also wrote script that new browser initiate in #After Junit command when my test case fail.
#After
public void teardownpatientregis(Scenario s) throws IOException, InterruptedException
{
if(s.isFailed())
{
Screenshots.getscreenshot(s);
driver.quit();
initialize(failbrowser);
url(failurl);
Logintestpage.getusername(failuser);
Logintestpage.getpassword(failpass);
Logintestpage.loginalert();
Thread.sleep(2000);
Logintestpage.logout();
driver.quit();
}
}
But the new Webdriver does not initiate after close my browser. It shows SessionNotCreatedException errors. Please help me to resolve this issue
The new Webdriver does not initiate after closing the browser because you are NOT closing the browser, you are issuing a quit instead.
Replace at least the first driver.quit() with driver.close()if not both of them.
Related
I'm attempting to test the new 100.x.x.x changes using chrome://flags #force-major-version-to-100. After enabling it requires the browser to restart, I attempted to use driver.close() to do this but it doesn't save the change, so you're forced to use the button within chrome://flags to do so - once it reopens this way though, it has killed the instance. Is there a way to do this? I tried to setup ChromeOptions() for this, however I couldn't get it to enable experimental features.
The code I'm using is below.
#Test(enabled=true)
public void test() throws Throwable {
driver.get("chrome://flags/");
driver.findElement(By.xpath("//*[#id='search']")).sendKeys("force-major-version-to-100");
Thread.sleep(2000);
//driver.findElement(By.xpath("//*[#aria-labelledby='force-major-version-to-100_name']")).click();
Select dropdown = new Select(driver.findElement(By.xpath("//*[#aria-labelledby='force-major-version-to-100_name']")));
dropdown.selectByVisibleText("Enabled");
Thread.sleep(2000);
driver.findElement(By.xpath("//*[#id='experiment-restart-button']")).click();
Thread.sleep(3000);
driver.get("https://www.google.com");
i am working with selenium java with cucumber.In a single feature file i have 5 to 10 scenarios for a single URL.I do not want to open the browser 10 times and close 10 times.
In cook hooks i have written the code to not open the browser before every scenario using flags option .But unable to find any option where i could close the browser after all the scenarios of a feature file finished
browserinitialized=flase;
#Before
public void before(Scenario scenario) {
if(browserinitialized!=true)
{
InitializeDriver(scenario);
browserinitialized=true;
}}
#After
public void after(Scenario scenario) {
if (driver != null) {
captureReport(scenario, driver);
driver.manage().deleteAllCookies();
driver.close();
driver.quit();
}
I have executed the below code to perform load test
#Test(invocationCount = 5, threadPoolSize = 1)
public void GmailLogin() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "D:\\CIPL0564\\D
Drive\\Software\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://tst-oec-ebooking.azurewebsites.net/");
driver.manage().timeouts().implicitlyWait(6000, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[#id=\"Email\"]")).sendKeys("mad#dayrep.com");
driver.manage().timeouts().implicitlyWait(6000, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[#id=\"Password\"]")).sendKeys("Pass#123");
driver.findElement(By.xpath("//*[#id=\"login_submit\"]")).click();
Thread.sleep(1500);
driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);
driver.quit();
}
It executed 5 times with no errors but one after other.I need to execute this at a time by opening multiple windows.
I have tried by giving threadPoolSize = 5,but i got error as session not created.
TestNG runner would create just one test class instance for all test methods run. This logic also occurs when running in parallel. It seems like your WebDriver object is defined globally, so in each invocation when you call "driver = new ChromeDriver()" it overrides the other.
My advice for you is to use ThreadLocal object to define your WebDriver sessions. In that way, each WebDriver object in given thread acts as independent data set.
See this link http://seleniumautomationhelper.blogspot.com/2014/02/initializing-webdriver-object-as-thread.html for more detailed explanation about this subject.
I am trying to run a portion of code in Google Chrome and the rest in Firefox
public class flip
{
static WebDriver driver = new FirefoxDriver(); // starting firefox
public static void main(String[] args) throws IOException, InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:/chromedriver.exe");
WebDriver driver1 = new ChromeDriver();
driver1.get("website1");
driver1.findElement(By.id("id_username")).sendKeys("username");
driver1.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver1.findElement(By.id("id_password")).sendKeys("password");
System.out.print("logged in");
driver1.close();
driver.get("website-2"); // in firefox
}
}
I am getting following error (when program need to switch browsers).
Both browsers are opening but unable to drive.
Exception in thread "main" org.openqa.selenium.WebDriverException:
f.QueryInterface is not a function
Command duration or timeout: 60.03 seconds
Can any one help me where I made mistake ??
(firefox webdriver must be a static..)
put http:// on starting of your web address of your firefox driver. it is obligation in that selenium version.
I am new to Selenium Web driver and using this with Java.
I am able to launch an application but I am getting the SSL certificate error, could anyone please let me know how to overcome this issue.
I am actually learning it and need to implement at my work, if I could overcome this will be very helpful.
I am using the following code :
public class Test1 {
private static InternetExplorerDriver driver;
#Before
public void beforeclass ()
{
System.setProperty("webdriver.ie.driver", "C:\\My Folder\\selenium-2.33.0\\IEDriverServer.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setJavascriptEnabled(true);
driver = new InternetExplorerDriver(capabilities);
}
#Test
public void Test() throws Exception
{
driver.get("www.gmail.com");
driver.getTitle();
driver.getCurrentUrl();
System.out.println(driver.getCurrentUrl());
driver.findElement(By.name("username")).sendKeys("Admin1");
driver.findElement(By.name("password")).sendKeys("Password2");
}
#After
public void afterclass()
{
System.out.println("webdriver");
}
}
Thanks in advance.
I dont' think there is a way to properly set it. CapabilityType.ACCEPT_SSL_CERTS won't work for IE I suppose, Selenium is designed to ignore the invalid capability for the particular browser and won't throw an exception.
Here is a workaround you can click link "Continue to this website (not recommended)." to bypass it.
Try
// check if your driver is IEDriver and driver's Title contains "Certificate"
// then
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
driver.findElement(By.name("username")).sendKeys("Admin1");
driver.findElement(By.name("password")).sendKeys("Password2");
Facing the same issue i solved it adding target ssl certificates to IE trusted certificates on machine where test executes.
This solved in local dev machine and also on grid execution.(Certificates imported there)
This precentes certificate revogation warning to display on IE.
I did solve this issue by making changes in the settings.Try
Tools-> Internet options->Advanced-> Settings->under security uncheck " Warn if changing between secure and not secure mode"
and Restart your IE.