Saturday, December 17, 2011

Clear Browser Cache

We can press Control + F5 using webdriver to clear the browser cache.

            Actions actionObject = new Actions(driver);
            actionObject.keyDown(Keys.CONTROL).sendKeys(Keys.F5).keyUp(Keys.CONTROL).perform();

Disabling caching in ChromeDriver

For disabling caching in ChromeDriver we can use the chrome switches with  DesiredCapabilities

DesiredCapabilities dc = DesiredCapabilities.chrome();
                ArrayList<String> switches = new ArrayList<String>();
                switches.add("--proxy-server="+InetAddress.getLocalHost().getHostAddress()+ ":" + Integer.parseInt(port));
                switches.add("--proxy-bypass-list=local.addthis.com");
                switches.add("--disable-application-cache");
                dc.setCapability("chrome.switches", switches);

More details about chrome switches

Maven ant run plugin

Simulate all the tasks of ant script and also used to call external ant targets from a maven pom.


<groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <configuration>
      <tasks>
        <echo message="hello ant, from Maven!" />
        <echo>Maybe this will work?</echo>

        <ant antfile="${basedir}/build.xml">
          <target name="test" />
        </ant>

       <exec dir="${basedir}" executable="cmd"
         failonerror="true">
         <arg line="/K start" />
         <arg line="one.bat" />
       </exec>

      </tasks>
    </configuration>
   </plugin>
Sample Usage : mvn antrun:run